I've been trying to register an entity and the game keeps crashing. I looked through the console log and the error says that my entity doesn't have any attributes, but I think I've registered them. Please help. Btw I am making a passive mob similar to a chicken.
Mod class:
package mod.destructor_ben.wmim;
import mod.destructor_ben.wmim.entities.DuckEntity;
import mod.destructor_ben.wmim.init.ModBlocks;
import mod.destructor_ben.wmim.init.ModEntities;
import mod.destructor_ben.wmim.init.ModItems;
import net.minecraft.entity.ai.attributes.GlobalEntityTypeAttributes;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.DeferredWorkQueue;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@SuppressWarnings("deprecation")
@Mod(WMIM.MODID)
@Mod.EventBusSubscriber(modid = WMIM.MODID, bus = Bus.MOD)
public class WMIM
{
public static final String MODID = "wmim";
public static final Logger LOGGER = LogManager.getLogger();
public WMIM()
{
final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
ModItems.ITEMS.register(modEventBus);
LOGGER.info("Items registered");
ModBlocks.BLOCKS.register(modEventBus);
LOGGER.info("Blocks registered");
ModEntities.ENTITIES.register(modEventBus);
LOGGER.info("Entities registered");
}
private void setup(final FMLCommonSetupEvent event)
{
DeferredWorkQueue.runLater(() -> {
GlobalEntityTypeAttributes.put(ModEntities.DUCK.get(), DuckEntity.setCustomAttributes().create());
});
}
}
Entity class:
package mod.destructor_ben.wmim.entities;
import net.minecraft.block.BlockState;
import net.minecraft.entity.AgeableEntity;
import net.minecraft.entity.EntitySize;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.Pose;
import net.minecraft.entity.ai.attributes.AttributeModifierMap;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.entity.ai.goal.BreedGoal;
import net.minecraft.entity.ai.goal.FollowParentGoal;
import net.minecraft.entity.ai.goal.LookAtGoal;
import net.minecraft.entity.ai.goal.LookRandomlyGoal;
import net.minecraft.entity.ai.goal.PanicGoal;
import net.minecraft.entity.ai.goal.SwimGoal;
import net.minecraft.entity.ai.goal.TemptGoal;
import net.minecraft.entity.ai.goal.WaterAvoidingRandomWalkingGoal;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.pathfinding.PathNodeType;
import net.minecraft.util.DamageSource;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
public class DuckEntity extends AnimalEntity
{
private static final Ingredient TEMPTATION_ITEMS = Ingredient.fromItems(Items.WHEAT_SEEDS, Items.MELON_SEEDS, Items.PUMPKIN_SEEDS, Items.BEETROOT_SEEDS, Items.SALMON, Items.BREAD);
public float wingRotation;
public float destPos;
public float oFlapSpeed;
public float oFlap;
public float wingRotDelta = 1.0F;
public int timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
public DuckEntity(EntityType<? extends AnimalEntity> type, World worldIn)
{
super(type, worldIn);
this.setPathPriority(PathNodeType.WATER, 5.0F);
this.setPathPriority(PathNodeType.WATER_BORDER, 4.0F);
}
protected void registerGoals()
{
this.goalSelector.addGoal(0, new SwimGoal(this));
this.goalSelector.addGoal(1, new PanicGoal(this, 1.4D));
this.goalSelector.addGoal(2, new BreedGoal(this, 1.0D));
this.goalSelector.addGoal(3, new TemptGoal(this, 1.0D, false, TEMPTATION_ITEMS));
this.goalSelector.addGoal(4, new FollowParentGoal(this, 1.1D));
this.goalSelector.addGoal(5, new WaterAvoidingRandomWalkingGoal(this, 1.0D));
this.goalSelector.addGoal(6, new LookAtGoal(this, PlayerEntity.class, 6.0F));
this.goalSelector.addGoal(7, new LookRandomlyGoal(this));
}
protected float getStandingEyeHeight(Pose poseIn, EntitySize sizeIn)
{
return this.isChild() ? sizeIn.height * 0.85F : sizeIn.height * 0.92F;
}
public static AttributeModifierMap.MutableAttribute setCustomAttributes()
{
return MobEntity.func_233666_p_()
.createMutableAttribute(Attributes.MAX_HEALTH, 4.0D)
.createMutableAttribute(Attributes.MOVEMENT_SPEED, 0.25D);
}
public void livingTick()
{
super.livingTick();
this.oFlap = this.wingRotation;
this.oFlapSpeed = this.destPos;
this.destPos = (float)((double)this.destPos + (double)(this.onGround ? -1 : 4) * 0.3D);
this.destPos = MathHelper.clamp(this.destPos, 0.0F, 1.0F);
if (!this.onGround && this.wingRotDelta < 1.0F) {
this.wingRotDelta = 1.0F;
}
this.wingRotDelta = (float)((double)this.wingRotDelta * 0.9D);
Vector3d vector3d = this.getMotion();
if (!this.onGround && vector3d.y < 0.0D) {
this.setMotion(vector3d.mul(1.0D, 0.6D, 1.0D));
}
this.wingRotation += this.wingRotDelta * 2.0F;
//Change
if (!this.world.isRemote && this.isAlive() && !this.isChild() && --this.timeUntilNextEgg <= 0) {
this.playSound(SoundEvents.ENTITY_CHICKEN_EGG, 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
this.entityDropItem(Items.EGG);
this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
}
}
public boolean onLivingFall(float distance, float damageMultiplier) {
return false;
}
//change sounds
protected SoundEvent getAmbientSound() {
return SoundEvents.ENTITY_CHICKEN_AMBIENT;
}
protected SoundEvent getHurtSound(DamageSource damageSourceIn) {
return SoundEvents.ENTITY_CHICKEN_HURT;
}
protected SoundEvent getDeathSound() {
return SoundEvents.ENTITY_CHICKEN_DEATH;
}
protected void playStepSound(BlockPos pos, BlockState blockIn) {
this.playSound(SoundEvents.ENTITY_CHICKEN_STEP, 0.15F, 1.0F);
}
//change this
public net.minecraft.entity.passive.ChickenEntity func_241840_a(ServerWorld p_241840_1_, AgeableEntity p_241840_2_) {
return EntityType.CHICKEN.create(p_241840_1_);
}
public boolean isBreedingItem(ItemStack stack) {
return TEMPTATION_ITEMS.test(stack);
}
//protected int getExperiencePoints(PlayerEntity player){}
public void readAdditional(CompoundNBT compound) {
super.readAdditional(compound);
if (compound.contains("EggLayTime")) {
this.timeUntilNextEgg = compound.getInt("EggLayTime");
}
}
public void writeAdditional(CompoundNBT compound) {
super.writeAdditional(compound);
compound.putInt("EggLayTime", this.timeUntilNextEgg);
}
}