Jump to content

Recommended Posts

Posted (edited)

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);
    }
}
Edited by The_Biggest_Noob

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have a custom 3d model which works perfectly. BUT I want it to be held diffrently on the players hand when the item is being used. My JSON file under assets/examplemod/items looks like this: { "model": { "type": "minecraft:condition", "on_false": { "type": "minecraft:model", "model": "examplemod:item/example_item" }, "on_true": { "type": "minecraft:model", "model": "examplemod:item/example_item_using" }, "property": "minecraft:using_item" } }   This works fine until the item is used. The correct model will be displayed but with a full black texture instead of the actuall texture. Any idea why? (I want to use the exact same texture for both items, because their model is the same just diffrent displays on firstperson_righthand and firstperson_lefthand). The models JSON's are fully blockbench files inlcuding the elements, display, textures with texture_size.   Also is this the correct way to do it? Because it feels so dumb to change the exact same model just for a diffrent right- and lefthand view.   (fyi: ItemUseAnimation is BLOCK for this item)
    • I just backed up my world then tried to create new mod with currently equipped mod but with new world still made same error. Sooo I think it's not world error. also It's working fine on singleplayer. + but it made some another weird error with new world
    • Maybe the file is too large - you can upload the log file via Mediafire
    • Create a new instance and start with Embeddium + Oculus Then add new mods one by one or in groups The "IncompatibleClassChangeError: class net.coderbot.iris.gui.option.ShadowDistanceOption" often appears in connection with an incompatible mod
    • I hosted forge modded server using feather client I was able to join without any issues yesterday, but today after I tested my shader on my single world then tried to join the world but it made error meassage. (I also changed server.properties's render settings, but I reverted it as same as yesterday) So I removed my shader and removed optifine on server and on my mod file then it made this error: Internal Exception: io.netty.handler.codec.DecoderException: net.minecraft.ResourceLocationException: Non [a-z0-9/-1 character in path of location: inecraft:ask_server\u0012\u0001\uFFFD\n\u0007targets\u001D\u0001\u0014minecraft:ask_server\u0012\u0002\uFFFD\n\uFFFD\n\u0002id!\u0014minecraft:ask_server\u0002 \u0001\uFFFD\n\u0006target\u0006\u0001\u0002\u0001\uFFFD\n\ttarget My server/client is 1.20.1 forge. And I got 34 mods total, it was working pretty fine yesterday (I did not add/remove any mods before it started happening) I hope it's not about my worlds, it's been quite long since using this world I'm not native english speaker so there may be grammar issue! Thank you for reading!
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.