Jump to content

Registering EntityRenderer


bigMojitos

Recommended Posts

Hi I'm having trouble understanding what needs to go in the parameters of this method:

EntityRenderers.register(ModEntityTypes.REUS.get(), ReusRenderer::new);
						^

Both the options I  have in those parameters are wrong but I dont know where to get the right objects for the params any help would be appreciated thanks!

Link to comment
Share on other sites

Subscribe to EntityRenderersEvent.RegisterRenderers to register your entity renderers.

You code with the arrow is completely out of context. You don't even show the compiler error message.

I would guess it is a problem with the type parameters of your RegistryObject and the EntityRenderer not matching. But you don't show either definition.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

package me.wdh.inceptor.entity.custom;

import net.minecraft.world.entity.*;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.level.Level;
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 Mob implements IAnimatable {
    public ReusEntity(EntityType<? extends Mob> p_20966_, Level p_20967_) {
        super(p_20966_, p_20967_);
    }
    private AnimationFactory factory = new AnimationFactory(this);

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

    }


    private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event) {
        if (event.isMoving()) {
            event.getController().setAnimation(new AnimationBuilder().addAnimation("pose.model.new", true));
            return PlayState.CONTINUE;
        }

        event.getController().setAnimation(new AnimationBuilder().addAnimation("pose.model.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, 2.0f)
                .add(Attributes.MOVEMENT_SPEED, 0.3f).build();
    }

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

 

package me.wdh.inceptor.entity.client;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import me.wdh.inceptor.Inceptor;
import me.wdh.inceptor.entity.custom.ReusEntity;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.resources.ResourceLocation;
import software.bernie.geckolib3.model.AnimatedGeoModel;
import software.bernie.geckolib3.renderers.geo.GeoEntityRenderer;

public class ReusRenderer extends GeoEntityRenderer<ReusEntity> {
    public ReusRenderer(EntityRendererProvider.Context renderManager, AnimatedGeoModel<ReusEntity> modelProvider) {
        super(renderManager, modelProvider);
    }


    @Override
    public ResourceLocation getTextureLocation(ReusEntity instance) {
        return new ResourceLocation(Inceptor.MODID, "textures/reus.png");
    }

    public RenderType getRenderType(ReusEntity animatable, float partialTicks, PoseStack stack,
                                    MultiBufferSource renderTypeBuffer, VertexConsumer vertexBuilder, int packedLightIn,
                                    ResourceLocation textureLocation) {
        stack.scale(0.8F, 0.8F, 0.8F);
        return super.getRenderType(animatable, partialTicks, stack, renderTypeBuffer, vertexBuilder, packedLightIn, textureLocation);
    }
}
public class ModEntityTypes {

    public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, Inceptor.MODID);

    // Entity Types
    public static final RegistryObject<EntityType<ReusEntity>> REUS = ENTITY_TYPES.register("reus",
            () -> EntityType.Builder.of(ReusEntity::new, MobCategory.CREATURE)
                    .sized(1.0f, 1.0f) // Hitbox Size
                    .build(new ResourceLocation(Inceptor.MODID, "reus").toString()));
}
    @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
    public static class ClientBus {


        @SubscribeEvent
        public static void playerRender(RenderPlayerEvent.Pre ev){
            print("Event has fired"); //not firing
        }

        @SubscribeEvent
        public static void livingRender(EntityRenderersEvent.RegisterRenderers event){
            event.registerEntityRenderer(REUS.get(),ReusRenderer::new);
        }

        @SubscribeEvent
        public static void keyTest(InputEvent.Key key){
            if(key.getKey() == InputConstants.KEY_C) print("Test Working");
        }

    }

The error im getting at living render event is this --> https://imgur.com/a/3CtbJOM

Link to comment
Share on other sites

Your image tells you what is wrong. Your method reference is wrong.

You need to be able to understand what the compiler is telling you, this is a java question not a forge question.

 

You are passing ReusRenderer::new as a parameter that wants an EntityRendererProvider.

Your constructor has 2 parameters but an EntityRendererProvider has only 1 parameter. 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

26 minutes ago, warjort said:

Your image tells you what is wrong. Your method reference is wrong.

You need to be able to understand what the compiler is telling you, this is a java question not a forge question.

 

You are passing ReusRenderer::new as a parameter that wants an EntityRendererProvider.

Your constructor has 2 parameters but an EntityRendererProvider has only 1 parameter. 

So do I need to create a new EntityRendererProvider? Sorry most of the tutorial I'm looking at are in 1.18 so I dont know if everything is correct. And what about for the first parameter with ModEntityTypes.Reus.get() but it says its incorrect?

Link to comment
Share on other sites

Quote

So do I need to create a new EntityRendererProvider? 

You already have an EntityRendererProvider. It is your EntityRenderer constructor. You just defined it wrong.

 

Here's an example of a mod using geckolib. This is what its entity renderer constructor looks like:

https://github.com/baileyholl/Ars-Nouveau/blob/eca471912263bce08f9f8f57ef132e45f18f7ff1/src/main/java/com/hollingsworth/arsnouveau/client/renderer/entity/AmethystGolemRenderer.java#L21

But if you are just going to copy/paste other people's code you will never learn how to mod.

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

9 hours ago, warjort said:

You already have an EntityRendererProvider. It is your EntityRenderer constructor. You just defined it wrong.

 

Here's an example of a mod using geckolib. This is what its entity renderer constructor looks like:

https://github.com/baileyholl/Ars-Nouveau/blob/eca471912263bce08f9f8f57ef132e45f18f7ff1/src/main/java/com/hollingsworth/arsnouveau/client/renderer/entity/AmethystGolemRenderer.java#L21

But if you are just going to copy/paste other people's code you will never learn how to mod.

Ok so I got it working and it seems to register fine but I cant spawn my entity. I heard that its supposed to appear with /summon command but I cant find it. Here is my new ClientBus with the working EntityRenderersEvent: 

    @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
    public static class ClientBus {


        @SubscribeEvent
        public static void playerRender(RenderPlayerEvent.Pre ev){
            print("Event has fired"); //not firing
        }

        @SubscribeEvent
        public static void registerRenderers(EntityRenderersEvent.RegisterRenderers event){
            event.registerEntityRenderer(REUS.get(), ReusRenderer::new);

        }
        @SubscribeEvent
        public void entityAttributeCreationEvent(EntityAttributeCreationEvent event) {
            LOGGER.info("Entity Attribute Event");
            event.put(REUS.get(), ReusEntity.setAttributes());
        }

        @SubscribeEvent
        public static void keyTest(InputEvent.Key key){
            if(key.getKey() == InputConstants.KEY_C) print("Test Working");
        }

    }

And here is my register:

@Mod.EventBusSubscriber(modid =Inceptor.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModEntityTypes {

    public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, Inceptor.MODID);

    // Entity Types
    public static final RegistryObject<EntityType<ReusEntity>> REUS = ENTITY_TYPES.register("reus",
            () -> EntityType.Builder.of(ReusEntity::new, MobCategory.CREATURE)
                    .sized(1.0f, 1.0f) // Hitbox Size
                    .build(new ResourceLocation(Inceptor.MODID, "reus").toString()));




    public static void register(IEventBus eventBus) {
        ENTITY_TYPES.register(eventBus);
    }


}

Is there a better way to check if its registered rather than spawning it?

Edited by bigMojitos
Link to comment
Share on other sites

You need cheat mode enabled to use the /summon command.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

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



×
×
  • Create New...

Important Information

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