Jump to content

[1.16.4] RenderRegistry#registerEntityRenderingHandler not working


Mahdi1224

Recommended Posts

Hello, I tried making an entity last night. I spent around 2 hours trying to figure out why I was getting an incompatible types error. And I couldn't figure it out.

I tried copying some code snippets off the forums that I found, but even that didn't work, and I'm left here confused.

 

I want to mention I read a fair bit of the docs (I skipped the parts that I don't need yet, like tile entities and what not). I also started learning forge yesterday, so please bare with me. Thanks in advance.

 

My Entities Class

package com.turtles.entities;

import com.turtles.Turtles;
import com.turtles.entities.render.CobblestoneTurtleRenderer;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public class TEntities {

    public static final DeferredRegister<EntityType<?>> ENTETIES = DeferredRegister.create(ForgeRegistries.ENTITIES, Turtles.MODID);

    public static final RegistryObject<EntityType<CobblestoneTurtleEntity>> COBBLESTONE_TURTLE = ENTETIES.register(
            "cobblestone_turtle", () -> EntityType.Builder.create(CobblestoneTurtleEntity::new, EntityClassification.CREATURE).size(
                    1.2F, 0.4F).build(new ResourceLocation(Turtles.MODID, "cobblestone_turtle").toString()));

    public static void register(){
        ENTETIES.register(FMLJavaModLoadingContext.get().getModEventBus());
    }

    public static void registerRender(){
        RenderingRegistry.registerEntityRenderingHandler(COBBLESTONE_TURTLE.get(), CobblestoneTurtleRenderer::new);
    }

}

 

Renderer class

package com.turtles.entities.render;

import com.turtles.Turtles;
import com.turtles.entities.CobblestoneTurtleEntity;
import com.turtles.entities.model.TTurtleModel;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.util.ResourceLocation;

public class CobblestoneTurtleRenderer extends MobRenderer<CobblestoneTurtleEntity, TTurtleModel<CobblestoneTurtleEntity>> {

    private static final ResourceLocation TEXTURE = new ResourceLocation(Turtles.MODID, "textures/entities/cobblestone_turtle.png");

    public CobblestoneTurtleRenderer(EntityRendererManager renderManagerIn, float shadowSizeIn) {
        super(renderManagerIn, new TTurtleModel<>(0.0f), shadowSizeIn);
    }

    @Override
    public ResourceLocation getEntityTexture(CobblestoneTurtleEntity entity) {
        return TEXTURE;
    }

}

 

Model class WIP (Copied the turtle model and I haven't updated it)

package com.turtles.entities.model;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import com.turtles.entities.TTurtleEntity;
import net.minecraft.client.renderer.entity.model.QuadrupedModel;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.util.math.MathHelper;

public class TTurtleModel <T extends TTurtleEntity> extends QuadrupedModel<T> {

    private final ModelRenderer pregnant;

    public TTurtleModel(float p_i48834_1_) {
        super(12, p_i48834_1_, true, 120.0F, 0.0F, 9.0F, 6.0F, 120);
        this.textureWidth = 128;
        this.textureHeight = 64;
        this.headModel = new ModelRenderer(this, 3, 0);
        this.headModel.addBox(-3.0F, -1.0F, -3.0F, 6.0F, 5.0F, 6.0F, 0.0F);
        this.headModel.setRotationPoint(0.0F, 19.0F, -10.0F);
        this.body = new ModelRenderer(this);
        this.body.setTextureOffset(7, 37).addBox(-9.5F, 3.0F, -10.0F, 19.0F, 20.0F, 6.0F, 0.0F);
        this.body.setTextureOffset(31, 1).addBox(-5.5F, 3.0F, -13.0F, 11.0F, 18.0F, 3.0F, 0.0F);
        this.body.setRotationPoint(0.0F, 11.0F, -10.0F);
        this.pregnant = new ModelRenderer(this);
        this.pregnant.setTextureOffset(70, 33).addBox(-4.5F, 3.0F, -14.0F, 9.0F, 18.0F, 1.0F, 0.0F);
        this.pregnant.setRotationPoint(0.0F, 11.0F, -10.0F);
        int i = 1;
        this.legBackRight = new ModelRenderer(this, 1, 23);
        this.legBackRight.addBox(-2.0F, 0.0F, 0.0F, 4.0F, 1.0F, 10.0F, 0.0F);
        this.legBackRight.setRotationPoint(-3.5F, 22.0F, 11.0F);
        this.legBackLeft = new ModelRenderer(this, 1, 12);
        this.legBackLeft.addBox(-2.0F, 0.0F, 0.0F, 4.0F, 1.0F, 10.0F, 0.0F);
        this.legBackLeft.setRotationPoint(3.5F, 22.0F, 11.0F);
        this.legFrontRight = new ModelRenderer(this, 27, 30);
        this.legFrontRight.addBox(-13.0F, 0.0F, -2.0F, 13.0F, 1.0F, 5.0F, 0.0F);
        this.legFrontRight.setRotationPoint(-5.0F, 21.0F, -4.0F);
        this.legFrontLeft = new ModelRenderer(this, 27, 24);
        this.legFrontLeft.addBox(0.0F, 0.0F, -2.0F, 13.0F, 1.0F, 5.0F, 0.0F);
        this.legFrontLeft.setRotationPoint(5.0F, 21.0F, -4.0F);
    }

    protected Iterable<ModelRenderer> getBodyParts() {
        return Iterables.concat(super.getBodyParts(), ImmutableList.of(this.pregnant));
    }

    /**
     * Sets this entity's model rotation angles
     */
    public void setRotationAngles(T entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
        super.setRotationAngles(entityIn, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch);
        this.legBackRight.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F * 0.6F) * 0.5F * limbSwingAmount;
        this.legBackLeft.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F * 0.6F + (float)Math.PI) * 0.5F * limbSwingAmount;
        this.legFrontRight.rotateAngleZ = MathHelper.cos(limbSwing * 0.6662F * 0.6F + (float)Math.PI) * 0.5F * limbSwingAmount;
        this.legFrontLeft.rotateAngleZ = MathHelper.cos(limbSwing * 0.6662F * 0.6F) * 0.5F * limbSwingAmount;
        this.legFrontRight.rotateAngleX = 0.0F;
        this.legFrontLeft.rotateAngleX = 0.0F;
        this.legFrontRight.rotateAngleY = 0.0F;
        this.legFrontLeft.rotateAngleY = 0.0F;
        this.legBackRight.rotateAngleY = 0.0F;
        this.legBackLeft.rotateAngleY = 0.0F;
        this.pregnant.rotateAngleX = ((float)Math.PI / 2F);

        this.pregnant.showModel = !this.isChild;
    }

    public void render(MatrixStack matrixStackIn, IVertexBuilder bufferIn, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) {
        boolean flag = this.pregnant.showModel;
        if (flag) {
            matrixStackIn.push();
            matrixStackIn.translate(0.0D, (double)-0.08F, 0.0D);
        }

        super.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn, red, green, blue, alpha);
        if (flag) {
            matrixStackIn.pop();
        }

    }

}

 

Base Entity Class

package com.turtles.entities;

import net.minecraft.entity.AgeableEntity;
import net.minecraft.entity.CreatureEntity;
import net.minecraft.entity.EntityType;
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.nbt.CompoundNBT;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;

import javax.annotation.Nullable;

public class TTurtleEntity extends AnimalEntity {

    protected TTurtleEntity(EntityType<? extends AnimalEntity> type, World worldIn) {
        super(type, worldIn);
    }

    @Override
    protected void registerGoals() {
        super.registerGoals();
        this.goalSelector.addGoal(0, new SwimGoal(this));
        this.goalSelector.addGoal(1, new PanicGoal(this, 1.25d));
        this.goalSelector.addGoal(2, new LookAtGoal(this, PlayerEntity.class, 6.0f));
        this.goalSelector.addGoal(3, new WaterAvoidingRandomWalkingGoal(this, 1.0d));
        this.goalSelector.addGoal(4, new LookRandomlyGoal(this));
    }

    @Nullable
    @Override
    public AgeableEntity func_241840_a(ServerWorld p_241840_1_, AgeableEntity p_241840_2_) {
        return null;
    }
}

 

Cobblestone Turtle Class

package com.turtles.entities;

import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.world.World;

public class CobblestoneTurtleEntity extends TTurtleEntity {

    protected CobblestoneTurtleEntity(EntityType<? extends AnimalEntity> type, World worldIn) {
        super(type, worldIn);
    }


}

 

Main class

package com.turtles;

import com.turtles.blocks.TBlocks;
import com.turtles.entities.TEntities;
import com.turtles.entities.render.CobblestoneTurtleRenderer;
import com.turtles.items.TItems;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.stream.Collectors;

@net.minecraftforge.fml.common.Mod(Turtles.MODID)
public class Turtles {

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

    public static final String MODID = "turtles";

    public Turtles() {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        MinecraftForge.EVENT_BUS.register(this);
        TBlocks.register();
        TItems.register();
        TEntities.register();

        TEntities.registerRender();
    }

    private void setup(final FMLCommonSetupEvent event) {
        LOGGER.info("Pre initializing");
    }

    private void doClientStuff(final FMLClientSetupEvent event) {

    }

    private void enqueueIMC(final InterModEnqueueEvent event) {
        InterModComms.sendTo("turtles", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";});
    }

    private void processIMC(final InterModProcessEvent event) {
        LOGGER.info("Got IMC {}", event.getIMCStream().
                map(m->m.getMessageSupplier().get()).
                collect(Collectors.toList()));
    }

    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {

    }

}

 

Link to comment
Share on other sites

Oh my bad, I thought I did. I get a syntax error here. From what I've seen this is the right way to do it. So Im not sure what Im doing wrong.

https://gyazo.com/2a2589a4cbb86970e27eefb90eac515a

    public static void registerRender(){
        RenderingRegistry.registerEntityRenderingHandler(COBBLESTONE_TURTLE.get(), CobblestoneTurtleRenderer::new);
    }
Edited by Mahdi1224
Link to comment
Share on other sites

I do know Java to a certain extent. I wouldn't call my self an expert but Im not a beginner. I realize it doesn't accept the variable Im assigning it. I just don't know why. Im pretty certain I have written everything correctly, especially since I've confirmed this by looking at other people's examples. I tried changing some stuff up to match the required variable but It still wouldn't work. Also if the solution is an easy one that Im missing, I apologize. I have a habit of missing small details sometimes

 

 

Link to comment
Share on other sites

44 minutes ago, Mahdi1224 said:

You know what. Ima just figure it out myself, you seem to not wanna help me anyways, instead telling me to do it myself. Thanks for the help.

the constructor of your Renderer contains two elemetnts a EntityRendererManager and a float

the IRenderFactory needs only the EntityRendererManager

In addition, the Factory cannot do anything with the float and gives you the error

that's exactly what @diesieben07 meant by

57 minutes ago, diesieben07 said:

Look at the two and understand how method references work.

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello. I'm using IntelliJ IDEA and making a mod for Forge 1.20.1 and I'm trying to make a GUI. I found that the Minecraft-related codes are all obfuscated and when setting up the workspace, Gradle did not execute Deobfuscation tasks like createMcpToSrg. Is this normal or a bug? Can anyone help me with this?
    • Hello! I'm trying to get a list of all entries registered in the infusion upgrade registry. Code can be found in github: https://github.com/ChamoisEST/MiningMadness/tree/1.20.1 Registry in common/registries/MMRegistries.java Event that calls the registry is in MiningMadness.java List of registered entries should be called in common/capabilities/infusion/InfusionCapabilityImplementation.java:getActiveInfusions() in the for loop. Is there any way to accomplish that? Thanks in advance!  
    • So, I am trying to create and add tags to my custom damage type, but looks like I made something wrong, since it crashing with error that "cannot register" damage type. Im trying to register it, and in datagen add tags, but it everytime crashing due to not register "grimtales:entropy". Full code there - https://github.com/undertakerJ/Grim-Tales-Forge ModDamageTypes class public class ModDamageTypes { public static final DeferredRegister<DamageType> DAMAGE_TYPES = DeferredRegister.create(Registries.DAMAGE_TYPE, GrimTales.MOD_ID); public static final ResourceKey<DamageType> ENTROPY_KEY = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(GrimTales.MOD_ID, "entropy")); public static final RegistryObject<DamageType> ENTROPY = DAMAGE_TYPES.register( "entropy", () -> new DamageType("entropy_effect", DamageScaling.ALWAYS, 1f, DamageEffects.HURT)); // // public static final DamageSource ENTROPY_SOURCE = new DamageSource(Holder.direct(ENTROPY.get())); public static void register(IEventBus eventBus) { DAMAGE_TYPES.register(eventBus); } } Datagen for damageTags public class ModDamageTagsProvider extends DamageTypeTagsProvider { public ModDamageTagsProvider( PackOutput p_270719_, CompletableFuture<HolderLookup.Provider> p_270256_, @Nullable ExistingFileHelper existingFileHelper) { super(p_270719_, p_270256_, GrimTales.MOD_ID, existingFileHelper); } @Override protected void addTags(HolderLookup.Provider pProvider) { this.tag(DamageTypeTags.BYPASSES_INVULNERABILITY).add(ModDamageTypes.ENTROPY_KEY); } } Datagen class it self   @Mod.EventBusSubscriber(modid = GrimTales.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class DataGenerators { @SubscribeEvent public static void gatherData(GatherDataEvent event){ DataGenerator generator = event.getGenerator(); PackOutput packOutput = generator.getPackOutput(); ExistingFileHelper helper = event.getExistingFileHelper(); CompletableFuture<HolderLookup.Provider> lookupProvider = event.getLookupProvider(); generator.addProvider(event.includeServer(), new ModDamageTagsProvider(packOutput, lookupProvider, helper)); } } And register class in main class public GrimTales() { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); ModDamageTypes.register(modEventBus); modEventBus.addListener(this::commonSetup); MinecraftForge.EVENT_BUS.register(this); modEventBus.addListener(this::addCreative); }  
    • Looking for a semi-vanilla Minecraft server? Maybe one with keep inventory and land claims? I have one for you! Let me introduce you to Safe Survival! Come on and join us at mc.safesurvival.net. It is bedrock supported too!
    • Hi. I'm trying to play RLCraft with Optifine but my game keeps crashing on startup with Exit Code 1. The modpack was working fine yesterday, not sure what changed to make it not wanna work anymore. I was hoping someone here could help me figure out what's going wrong. If I remove Optifine, nothing changes, I still get the same errors. Thanks in advance. Crash Report (I only included the errors+fatal, I’m not sure if more is needed, please let me know): https://pastebin.ai/66ivknz0f4  
  • Topics

×
×
  • Create New...

Important Information

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