ISenseHostility Posted May 8, 2021 Share Posted May 8, 2021 (edited) I am having a problem with entity attributes. I feel like have set them correctly, but when I launch the game I get multiple errors stating that I, in fact, have not. I'm not sure where the problem lies, so I was hoping someone could help me. Here is the log: https://privatebin.net/?0938f12eb189ae59#H5EKLWjp8BL2iZ6tAgVFmAyheUSmJDVhBgMcbHS12G79 Here is the entity class: Spoiler package com.isensehostility.entity_testing.entities; import net.minecraft.entity.AgeableEntity; import net.minecraft.entity.EntityType; import net.minecraft.entity.MobEntity; import net.minecraft.entity.ai.attributes.AttributeModifierMap; import net.minecraft.entity.ai.attributes.Attributes; import net.minecraft.entity.ai.goal.*; import net.minecraft.entity.passive.AnimalEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; import javax.annotation.Nullable; public class TestEntity extends AnimalEntity { public TestEntity(EntityType<? extends AnimalEntity> type, World worldIn) { super(type, worldIn); } @Nullable @Override public AgeableEntity func_241840_a(ServerWorld p_241840_1_, AgeableEntity p_241840_2_) { return null; } @Override protected void registerGoals() { super.registerGoals(); this.goalSelector.addGoal(0, new SwimGoal(this)); this.goalSelector.addGoal(3, new WaterAvoidingRandomFlyingGoal(this, 1.0D)); this.goalSelector.addGoal(4, new WaterAvoidingRandomWalkingGoal(this, 1.0D)); this.goalSelector.addGoal(5, new LookAtGoal(this, PlayerEntity.class, 6.0F)); this.goalSelector.addGoal(6, new LookRandomlyGoal(this)); } public static AttributeModifierMap.MutableAttribute setAttributes() { return MobEntity.func_233666_p_() .createMutableAttribute(Attributes.MAX_HEALTH, 1.0D) .createMutableAttribute(Attributes.MOVEMENT_SPEED, 0.25D); } } Here is the registry class: Spoiler package com.isensehostility.entity_testing.registries; import com.isensehostility.entity_testing.EntityTesting; import com.isensehostility.entity_testing.entities.TestEntity; import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntityType; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; public class EntityRegistry { private static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITIES, EntityTesting.MODID); public static void init() { ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus()); } public static final RegistryObject<EntityType<TestEntity>> TEST_ENTITY = ENTITIES.register("test_entity", () -> EntityType.Builder.create(TestEntity::new, EntityClassification.CREATURE).size(1.0F,1.0F).build(new ResourceLocation(EntityTesting.MODID, "test_entity").toString())); } Here is the main class: Spoiler package com.isensehostility.entity_testing; import com.isensehostility.entity_testing.entities.TestEntity; import com.isensehostility.entity_testing.registries.EntityRegistry; import net.minecraft.entity.ai.attributes.GlobalEntityTypeAttributes; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.DeferredWorkQueue; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; @Mod("entity_testing") public class EntityTesting { public static final String MODID = "entity_testing"; public EntityTesting() { EntityRegistry.init(); MinecraftForge.EVENT_BUS.register(this); } @SubscribeEvent public static void setup(final FMLCommonSetupEvent event) { DeferredWorkQueue.runLater(()-> GlobalEntityTypeAttributes.put(EntityRegistry.TEST_ENTITY.get(), TestEntity.setAttributes().create())); } } If more info is needed tell me and I will add it. Edited May 8, 2021 by ISenseHostility removed quotes because it looked weird Quote Link to comment Share on other sites More sharing options...
ChampionAsh5357 Posted May 8, 2021 Share Posted May 8, 2021 Well, first the event handler is not attached to the mod event bus so EntityTesting#setup is never called. Second, entity attributes are now registered via EntityAttributeCreationEvent. That event is still called on the mod event bus. 1 Quote Link to comment Share on other sites More sharing options...
ISenseHostility Posted May 10, 2021 Author Share Posted May 10, 2021 I forgot to say, this fixed the attribute problem. Quote Link to comment Share on other sites More sharing options...
poppakap Posted August 11, 2021 Share Posted August 11, 2021 What if the Entity does not extend from LivingEntity? I have the same issue but with a Projectile. The EntityAttributeCreationEvent only wants LivingEntity: public void put(EntityType<? extends LivingEntity> entity, AttributeSupplier map) Quote Link to comment Share on other sites More sharing options...
poppakap Posted August 11, 2021 Share Posted August 11, 2021 It's ok, I think I've found this particular problem - it does complain if your Projectile is registered as EntityType.Builder<>.of() with anything other than MobCategory.MISC For some crazy reason, I registered it with MobCategory.AMBIENT. This is where having cool examples would really come in handy 😄 Thank you diesieben07 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.