Jump to content

Recommended Posts

Posted

Hi, I have a custom entity with Attributes which aren't applying. Before when I didn't have an EntityAttributeCreationEvent handler my entity wouldn't event load but, I added one and It now spawns and renders/animates. However, none of the Entity Attribute modifiers are actually applying to my entity. No matte how much I change the Attack Speed or Movement variable it always stays the same.

Heres my Entity Class

package willh.org.medieval.entity.reus;

import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.ai.goal.*;
import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.animal.Cow;
import net.minecraft.world.entity.monster.Monster;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import software.bernie.geckolib3.core.IAnimatable;
import software.bernie.geckolib3.core.PlayState;
import software.bernie.geckolib3.core.builder.AnimationBuilder;
import software.bernie.geckolib3.core.controller.AnimationController;
import software.bernie.geckolib3.core.event.predicate.AnimationEvent;
import software.bernie.geckolib3.core.manager.AnimationData;
import software.bernie.geckolib3.core.manager.AnimationFactory;

public class ReusEntity extends Monster implements IAnimatable {
    boolean attacking;

    public ReusEntity(EntityType<? extends Monster> p_20966_, Level p_20967_) {
        super(p_20966_, p_20967_);
        attacking =false;
    }
    private AnimationFactory factory = new AnimationFactory(this);

    @Override
    public void registerControllers(AnimationData data) {
        data.addAnimationController(new AnimationController(this, "controller",
                0, this::predicate));

    }
    public static void print(String r){
        if(Minecraft.getInstance().player != null) {
            Player p = Minecraft.getInstance().player;
            p.sendSystemMessage(Component.nullToEmpty(r));
        }

    }

    @Override
    public boolean doHurtTarget(Entity p_21372_) {
        this.level.broadcastEntityEvent(this, (byte)10);
        return super.doHurtTarget(p_21372_);
    }
    @Override
    public void handleEntityEvent(byte p_21375_) {
        attacking = p_21375_ == 10;
        super.handleEntityEvent(p_21375_);
    }

    protected void registerGoals() {

        this.goalSelector.addGoal(0, new MeleeAttackGoal(this, 1.1d, false) {});
        this.goalSelector.addGoal(1, new FloatGoal(this));
        this.goalSelector.addGoal(2, new PanicGoal(this, 1.25D));
        this.goalSelector.addGoal(3, new NearestAttackableTargetGoal(this, Cow.class,true));
        this.goalSelector.addGoal(4, new LookAtPlayerGoal(this, Player.class, 8.0F));
        this.goalSelector.addGoal(5, new RandomLookAroundGoal(this));
        this.targetSelector.addGoal(6, (new HurtByTargetGoal(this)).setAlertOthers());
    }

    private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event) {

        if (event.isMoving()) {
            event.getController().setAnimation(new AnimationBuilder().addAnimation("walkEquipped.model.new", true));
            return PlayState.CONTINUE;
        }
        event.getController().setAnimation(new AnimationBuilder().addAnimation("idle_equipped.new", true));
        return PlayState.CONTINUE;
    }

    public static AttributeSupplier setAttributes() {
        return Mob.createMobAttributes()
                .add(Attributes.MAX_HEALTH, 20.0D)
                .add(Attributes.ATTACK_DAMAGE, 3.0f)
                .add(Attributes.ATTACK_SPEED, 0.9)
                .add(Attributes.MOVEMENT_SPEED, 0.3f).build();
    }

    @Override
    public AnimationFactory getFactory() {
        return this.factory;
    }
}

And heres my main mod class where I register my EntityAttributeCreationEvent handler:

@Mod(Medieval.MOD_ID)
public class Medieval
{
    public static final String MOD_ID = "medi";

    private static final Logger LOGGER = LogUtils.getLogger();

    public static ResourceLocation modLoc(String name) {
        return new ResourceLocation(MOD_ID, name);
    }

    public Medieval() {
        IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
        // Add to the constructor
        ItemInit.register(modEventBus);
        EntityInit.ENTITIES.register(modEventBus);
        modEventBus.addListener(this::commonSetup);
        modEventBus.addListener(this::clientSetup);
        GeckoLib.initialize();

        modEventBus.addListener(this::commonSetup);
        MinecraftForge.EVENT_BUS.register(this);
    }
    private void commonSetup(final FMLCommonSetupEvent event)
    {
    }
    private void clientSetup(FMLClientSetupEvent event){
        EntityRenderers.register(EntityInit.REUS.get(), ReusRenderer::new);

    }

    @Mod.EventBusSubscriber(modid = MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
    public static class ClientModEvents
    {
        @SubscribeEvent
        public static void onClientSetup(FMLClientSetupEvent event)
        {
            LOGGER.info("HELLO FROM CLIENT SETUP");
            LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName());
        }

        @SubscribeEvent
        public static void registerEntityAttributes(EntityAttributeCreationEvent event){
            event.put(EntityInit.REUS.get(), ReusEntity.setAttributes());

        }
    }
}

Any help would be appreciated thanks!

Posted

You should move your Events into the correct class. Your ClientModEvents class will be also load (and called) on server, this will crash the Server, since the Minecraft class is client only.
Why did you put the EntityAttributeCreationEvent EventHandler in a class called "ClientModEvents", the Event should be called on both sides.

You also register the FMLCommonSetupEvent twice.
You should take a look at this FCW page to see how Events works and how you register them correctly.

A few things i would recommend you to do:

  1. Do not put Events into your main Mod class
  2. Separate Events which are fired on different buses and different sides into their own class

After fixing your Events, check if the EntityAttributeCreationEvent is called using the debugger.

Last but not least, EntityRenderers should be registered in EntityRenderersEvent.RegisterRenderers

  • Like 1
Posted (edited)

So I did what you told me and put my entity registering method in the EntityRenderersEvent.RegisterRenderers handler and then I moved that Handler, along with the EntityAttributeCreationEvent handler, too a separate client side class. It lead to the error "Entity has no attributes". Since my project is not the big I uploaded that version of it to Github so if you're okay with looking at it heres the link : github.com/bigMojitos/MilMedi . So ater that didn't work I reverted back to registering in the Main Mod class and running debug on the EntityAttributeCreationEvent, heres what I got: https://imgur.com/a/CehO5A3 . It seems like its working but I'm not seeing the affects in game, my mob is still moves and attacks at the same speed no matter how much I adjust those two attributes. What should I do?

Edited by bigMojitos
Posted

EntityAttributeCreationEvent and EntityRenderersEvent.RegisterRenderers are Mod Bus Events, you need to move these Events into a class which is subscribe to the Mod.EventBusSubscriber.Bus#MOD.

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 am using forge 1.20.1 (version 47.3.0). My pc has an RTX 4080 super and an i9 14900 KF, I am on the latest Nvidia graphics driver, latest windows 10 software, I have java 23, forge 1.12.2 works and so does all vanilla versions but for some reason no version of forge 1.20.1 works and instead the game just crashes with the error code "-1." I have no mods in my mods fodler, I have deleted my options.txt and forge.cfg files in case my settings were causing a crash and have tried removing my forge version from the installations folder and reinstalling but no matter what I still crash with the same code and my log doesn't tell me anything: 18:34:53.924 game 2025-02-06 18:34:53,914 main WARN Advanced terminal features are not available in this environment 18:34:54.023 game [18:34:54] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, mrmirchi, --version, 1.20.1-forge-47.3.0, --gameDir, C:\Users\aryam\AppData\Roaming\.minecraft, --assetsDir, C:\Users\aryam\AppData\Roaming\.minecraft\assets, --assetIndex, 5, --uuid, 2db00ea8d678420a8956109a85d90e9d, --accessToken, ????????, --clientId, ZWI3NThkNzMtNmNlZS00MGI5LTgyZTgtYmZkNzcwMTM5MGMx, --xuid, 2535436222989555, --userType, msa, --versionType, release, --quickPlayPath, C:\Users\aryam\AppData\Roaming\.minecraft\quickPlay\java\1738838092785.json, --launchTarget, forgeclient, --fml.forgeVersion, 47.3.0, --fml.mcVersion, 1.20.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20230612.114412] 18:34:54.027 game [18:34:54] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 10.0.9+10.0.9+main.dcd20f30 starting: java version 17.0.8 by Microsoft; OS Windows 10 arch amd64 version 10.0 18:34:54.132 game [18:34:54] [main/INFO] [ne.mi.fm.lo.ImmediateWindowHandler/]: Loading ImmediateWindowProvider fmlearlywindow 18:34:54.191 game [18:34:54] [main/INFO] [EARLYDISPLAY/]: Trying GL version 4.6 18:34:54.303 game [18:34:54] [main/INFO] [EARLYDISPLAY/]: Requested GL version 4.6 got version 4.6 18:34:54.367 monitor Process Monitor Process crashed with exit code -1     screenshot of log: https://drive.google.com/file/d/1WdkH88H865XErvmIqAKjlg7yrmj8EYy7/view?usp=sharing
    • I am currently working on a big mod, but I'm having trouble with my tabs, I want to find a way to add tabs inside tabs, like how in mrcrayfishes furniture mod, his furniture tab has multiple other sub tabs to them, so i know it is possible but i just don't know how it is possible, any help would be appreciated, thanks
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
    • Make a test with adding this mod: https://www.curseforge.com/minecraft/mc-mods/betterrandomsourceconcurrencycrash If you have further issues, create an own thread
    • hi same thing happened to me this is my paste bin please help!  crash report - https://pastes.io/crash-rep
  • Topics

×
×
  • Create New...

Important Information

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