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


还是一样报错,无论是用FMLCommonSetupEvent还是EntityAttributeCreationEvent


  1. package com.example.examplemod;

  2. import mod.azure.azurelib.animatable.GeoEntity;
  3. import mod.azure.azurelib.core.animatable.instance.AnimatableInstanceCache;
  4. import mod.azure.azurelib.core.animation.AnimatableManager;
  5. import mod.azure.azurelib.core.animation.AnimationController;
  6. import mod.azure.azurelib.core.animation.RawAnimation;
  7. import mod.azure.azurelib.util.AzureLibUtil;
  8. import net.minecraft.entity.*;
  9. import net.minecraft.entity.ai.attributes.AttributeModifierManager;
  10. import net.minecraft.entity.ai.attributes.Attributes;
  11. import net.minecraft.entity.ai.goal.LookAtGoal;
  12. import net.minecraft.entity.passive.AnimalEntity;
  13. import net.minecraft.entity.player.PlayerEntity;
  14. import net.minecraft.nbt.CompoundNBT;
  15. import net.minecraft.network.IPacket;
  16. import net.minecraft.network.datasync.DataParameter;
  17. import net.minecraft.network.datasync.DataSerializers;
  18. import net.minecraft.network.datasync.EntityDataManager;
  19. import net.minecraft.world.World;
  20. import net.minecraft.world.server.ServerWorld;
  21. import net.minecraftforge.fml.network.NetworkHooks;

  22. import javax.annotation.Nullable;

  23. public class TestEntity extends CreatureEntity implements GeoEntity {
  24.     private final AnimatableInstanceCache cache = AzureLibUtil.createInstanceCache(this);

  25.     public TestEntity(EntityType<? extends CreatureEntity> p_i48580_1_, World p_i48580_2_) {
  26.         super(p_i48580_1_, p_i48580_2_);
  27.         this.getAttributes().getInstance(Attributes.MAX_HEALTH);
  28.     }

  29.     @Override
  30.     public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
  31.         controllers.add(new AnimationController<>(this, "controllerName", 0, event ->
  32.         {
  33.             return event.setAndContinue(
  34.                     // If moving, play the walking animation
  35.                     event.isMoving() ? RawAnimation.begin().thenLoop("walking"):
  36.                             // If not moving, play the idle animation
  37.                             RawAnimation.begin().thenLoop("idle"));
  38.         }));
  39.     }

  40.     @Override
  41.     public AnimatableInstanceCache getAnimatableInstanceCache() {
  42.         return cache;
  43.     }

  44.     @Override
  45.     protected void defineSynchedData() {
  46.     }

  47.     @Override
  48.     public void readAdditionalSaveData(CompoundNBT p_70037_1_) {

  49.     }

  50.     @Override
  51.     public void addAdditionalSaveData(CompoundNBT p_213281_1_) {

  52.     }

  53.     @Override
  54.     public IPacket<?> getAddEntityPacket() {
  55.         return NetworkHooks.getEntitySpawningPacket(this);
  56.     }

  57. }
复制代码



wozhizhan
属性添加错误,你可以换一种方法给生物添加属性
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();
                }
        }

数据system
wozhizhan 发表于 2024-1-5 19:26
属性添加错误,你可以换一种方法给生物添加属性
private static class EntityAttributesRegisterHandler {
...

开始就是用EntityAttributeCreationEvent添加属性,但现在无论是EntityAttributeCreationEvent.put还是GlobalEntityTypeAttributes.put都一样

第一页 上一页 下一页 最后一页