无敌三脚猫 发表于 2024-1-5 16:45
这个教程用的是mcp反混淆表,比如他写的createSpawnPacket就相当于你写的getAddEntityPacket,当然还有一 ...
还是一样报错,无论是用FMLCommonSetupEvent还是EntityAttributeCreationEvent

- package com.example.examplemod;
- import mod.azure.azurelib.animatable.GeoEntity;
- import mod.azure.azurelib.core.animatable.instance.AnimatableInstanceCache;
- import mod.azure.azurelib.core.animation.AnimatableManager;
- import mod.azure.azurelib.core.animation.AnimationController;
- import mod.azure.azurelib.core.animation.RawAnimation;
- import mod.azure.azurelib.util.AzureLibUtil;
- import net.minecraft.entity.*;
- import net.minecraft.entity.ai.attributes.AttributeModifierManager;
- import net.minecraft.entity.ai.attributes.Attributes;
- import net.minecraft.entity.ai.goal.LookAtGoal;
- import net.minecraft.entity.passive.AnimalEntity;
- import net.minecraft.entity.player.PlayerEntity;
- import net.minecraft.nbt.CompoundNBT;
- import net.minecraft.network.IPacket;
- import net.minecraft.network.datasync.DataParameter;
- import net.minecraft.network.datasync.DataSerializers;
- import net.minecraft.network.datasync.EntityDataManager;
- import net.minecraft.world.World;
- import net.minecraft.world.server.ServerWorld;
- import net.minecraftforge.fml.network.NetworkHooks;
- import javax.annotation.Nullable;
- public class TestEntity extends CreatureEntity implements GeoEntity {
- private final AnimatableInstanceCache cache = AzureLibUtil.createInstanceCache(this);
- public TestEntity(EntityType<? extends CreatureEntity> p_i48580_1_, World p_i48580_2_) {
- super(p_i48580_1_, p_i48580_2_);
- this.getAttributes().getInstance(Attributes.MAX_HEALTH);
- }
- @Override
- public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
- controllers.add(new AnimationController<>(this, "controllerName", 0, event ->
- {
- return event.setAndContinue(
- // If moving, play the walking animation
- event.isMoving() ? RawAnimation.begin().thenLoop("walking"):
- // If not moving, play the idle animation
- RawAnimation.begin().thenLoop("idle"));
- }));
- }
- @Override
- public AnimatableInstanceCache getAnimatableInstanceCache() {
- return cache;
- }
- @Override
- protected void defineSynchedData() {
- }
- @Override
- public void readAdditionalSaveData(CompoundNBT p_70037_1_) {
- }
- @Override
- public void addAdditionalSaveData(CompoundNBT p_213281_1_) {
- }
- @Override
- public IPacket<?> getAddEntityPacket() {
- return NetworkHooks.getEntitySpawningPacket(this);
- }
- }
属性添加错误,你可以换一种方法给生物添加属性
private static class EntityAttributesRegisterHandler {
@SubscribeEvent
public void onEntityAttributeCreation(EntityAttributeCreationEvent event) {
AttributeModifierMap.MutableAttribute ammma = MobEntity.func_233666_p_();
ammma = ammma.createMutableAttribute(Attributes.MOVEMENT_SPEED, 0);
ammma = ammma.createMutableAttribute(Attributes.MAX_HEALTH, 1024);
ammma = ammma.createMutableAttribute(Attributes.ARMOR, 0);
ammma = ammma.createMutableAttribute(Attributes.ATTACK_DAMAGE, 0);
ammma = ammma.createMutableAttribute(Attributes.FLYING_SPEED, 0);
event.put(entity, ammma.create());
}
}
注册
FMLJavaModLoadingContext.get().getModEventBus().register(new EntityAttributesRegisterHandler());
这是我的生物
public static class CustomEntity extends MonsterEntity {
public CustomEntity(FMLPlayMessages.SpawnEntity packet, World world) {
this(entity, world);
}
public CustomEntity(EntityType<CustomEntity> type, World world) {
super(type, world);
experienceValue = 0;
setNoAI(false);
enablePersistence();
setCustomNameVisible(true);
setInvisible(false);
}
@Override
public IPacket<?> createSpawnPacket() {
return NetworkHooks.getEntitySpawningPacket(this);
}
@Override
protected void registerGoals() {
super.registerGoals();
this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 1.2, false));
this.goalSelector.addGoal(2, new RandomWalkingGoal(this, 1));
this.targetSelector.addGoal(3, new HurtByTargetGoal(this));
this.goalSelector.addGoal(4, new LookRandomlyGoal(this));
this.goalSelector.addGoal(5, new SwimGoal(this));
}
@Override
public void baseTick() {
super.baseTick();
}
@Nullable
@Override
public ILivingEntityData onInitialSpawn(IServerWorld worldIn, DifficultyInstance difficultyIn, SpawnReason reason, @Nullable ILivingEntityData spawnDataIn, @Nullable CompoundNBT dataTag) {
return super.onInitialSpawn(worldIn, difficultyIn, reason, spawnDataIn, dataTag);
}
public void livingTick() {
super.livingTick();
}
}
private static class EntityAttributesRegisterHandler {
@SubscribeEvent
public void onEntityAttributeCreation(EntityAttributeCreationEvent event) {
AttributeModifierMap.MutableAttribute ammma = MobEntity.func_233666_p_();
ammma = ammma.createMutableAttribute(Attributes.MOVEMENT_SPEED, 0);
ammma = ammma.createMutableAttribute(Attributes.MAX_HEALTH, 1024);
ammma = ammma.createMutableAttribute(Attributes.ARMOR, 0);
ammma = ammma.createMutableAttribute(Attributes.ATTACK_DAMAGE, 0);
ammma = ammma.createMutableAttribute(Attributes.FLYING_SPEED, 0);
event.put(entity, ammma.create());
}
}
注册
FMLJavaModLoadingContext.get().getModEventBus().register(new EntityAttributesRegisterHandler());
这是我的生物
public static class CustomEntity extends MonsterEntity {
public CustomEntity(FMLPlayMessages.SpawnEntity packet, World world) {
this(entity, world);
}
public CustomEntity(EntityType<CustomEntity> type, World world) {
super(type, world);
experienceValue = 0;
setNoAI(false);
enablePersistence();
setCustomNameVisible(true);
setInvisible(false);
}
@Override
public IPacket<?> createSpawnPacket() {
return NetworkHooks.getEntitySpawningPacket(this);
}
@Override
protected void registerGoals() {
super.registerGoals();
this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 1.2, false));
this.goalSelector.addGoal(2, new RandomWalkingGoal(this, 1));
this.targetSelector.addGoal(3, new HurtByTargetGoal(this));
this.goalSelector.addGoal(4, new LookRandomlyGoal(this));
this.goalSelector.addGoal(5, new SwimGoal(this));
}
@Override
public void baseTick() {
super.baseTick();
}
@Nullable
@Override
public ILivingEntityData onInitialSpawn(IServerWorld worldIn, DifficultyInstance difficultyIn, SpawnReason reason, @Nullable ILivingEntityData spawnDataIn, @Nullable CompoundNBT dataTag) {
return super.onInitialSpawn(worldIn, difficultyIn, reason, spawnDataIn, dataTag);
}
public void livingTick() {
super.livingTick();
}
}
wozhizhan 发表于 2024-1-5 19:26
属性添加错误,你可以换一种方法给生物添加属性
private static class EntityAttributesRegisterHandler {
...
开始就是用EntityAttributeCreationEvent添加属性,但现在无论是EntityAttributeCreationEvent.put还是GlobalEntityTypeAttributes.put都一样