Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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) {

    }

}

 

  • Author

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

  • Author

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

 

 

  • Author

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.

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.

 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.