Jump to content

[1.16.5] Entity spawning but not rendering


ChasseEtPêche

Recommended Posts

 

Hello, I'm trying to make a kart, i'm able to spawn the entity, i can see its hitbox with f3+b but the entity is not rendering and the console isn't printing any error when it spawns. Can someone help me?

My code:

Spoiler

package fr.chasseetpeche92.mckart;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import fr.chasseetpeche92.mckart.client.entity.KartExampleEntityRenderer;
import fr.chasseetpeche92.mckart.common.entity.KartExampleEntity;
import fr.chasseetpeche92.mckart.core.init.BlockInit;
import fr.chasseetpeche92.mckart.core.init.EntityTypesInit;
import fr.chasseetpeche92.mckart.core.init.ItemInit;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

@Mod(McKart.MOD_ID)
public class McKart {
	public static final String MOD_ID = "mckart";
	public static final Logger LOGGER = LogManager.getLogger();
	
	public McKart() {
		IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
		
		bus.addListener(this::clientSetup);
		
		ItemInit.ITEMS.register(bus);
		BlockInit.BLOCKS.register(bus);
		EntityTypesInit.ENTITY_TYPES.register(bus);
		MinecraftForge.EVENT_BUS.register(this);		
	}
	
	private void clientSetup(final FMLClientSetupEvent event) {
		RenderingRegistry.registerEntityRenderingHandler(EntityTypesInit.KART_EXAMPLE.get(), KartExampleEntityRenderer<KartExampleEntity>::new);
	}
}

 

Spoiler

package fr.chasseetpeche92.mckart.common.entity;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.IPacket;
import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkHooks;

public class KartExampleEntity extends Entity{
	
	public KartExampleEntity(EntityType<? extends KartExampleEntity> entity, World world) {
		super(entity, world);
	}
	
	@Override
	protected void defineSynchedData() {
	}

	@Override
	protected void readAdditionalSaveData(CompoundNBT p_70037_1_) {
	}

	@Override
	protected void addAdditionalSaveData(CompoundNBT p_213281_1_) {
	}

	@Override
	public IPacket<?> getAddEntityPacket() {
		return NetworkHooks.getEntitySpawningPacket(this);
	}
}

 

Spoiler

package fr.chasseetpeche92.mckart.client.entity.model;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;

import fr.chasseetpeche92.mckart.common.entity.KartExampleEntity;
import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.client.renderer.model.ModelRenderer;

// Made with Blockbench 3.9.3
// Exported for Minecraft version 1.15 - 1.16 with Mojang mappings
// Paste this class into your mod and generate all required imports


public class KartExampleEntityModel<T extends KartExampleEntity> extends EntityModel<T> {
	private final ModelRenderer bb_main;

	public KartExampleEntityModel() {
		texWidth = 16;
		texHeight = 16;

		bb_main = new ModelRenderer(this);
		bb_main.setPos(0.0F, 24.0F, 0.0F);
		bb_main.texOffs(0, 0).addBox(-1.0F, -1.0F, 0.0F, 1.0F, 1.0F, 1.0F, 8.0F, false);
	}

	@Override
	public void setupAnim(T p_225597_1_, float p_225597_2_, float p_225597_3_, float p_225597_4_, float p_225597_5_,
			float p_225597_6_) {
	}

	@Override
	public void renderToBuffer(MatrixStack matrixStack, IVertexBuilder buffer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha){
		bb_main.render(matrixStack, buffer, packedLight, packedOverlay);
	}

	public void setRotationAngle(ModelRenderer modelRenderer, float x, float y, float z) {
		modelRenderer.xRot = x;
		modelRenderer.yRot = y;
		modelRenderer.zRot = z;
	}
}

 

Spoiler

package fr.chasseetpeche92.mckart.client.entity;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;

import fr.chasseetpeche92.mckart.McKart;
import fr.chasseetpeche92.mckart.client.entity.model.KartExampleEntityModel;
import fr.chasseetpeche92.mckart.common.entity.KartExampleEntity;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.util.ResourceLocation;

public class KartExampleEntityRenderer<T extends KartExampleEntity> extends EntityRenderer<KartExampleEntity> {
	
	protected static final ResourceLocation TEXTURE = new ResourceLocation(McKart.MOD_ID, "textures/entity/kart_example.png");
	
	private final KartExampleEntityModel<KartExampleEntity> model = new KartExampleEntityModel<KartExampleEntity>();

	public KartExampleEntityRenderer(EntityRendererManager rendererManagerIn) {
	    super(rendererManagerIn);
	}

	public void render(T entityIn, float entityYaw, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int packedLightIn) {
	    IVertexBuilder ivertexbuilder = net.minecraft.client.renderer.ItemRenderer.getFoilBuffer(bufferIn, this.model.renderType(this.getTextureLocation(entityIn)), false, false);
	    model.renderToBuffer(matrixStackIn, ivertexbuilder, packedLightIn, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F,1.0F, 1.0F);
	    super.render(entityIn, entityYaw, partialTicks, matrixStackIn, bufferIn, packedLightIn);
	}
    
	@Override
	public ResourceLocation getTextureLocation(KartExampleEntity p_110775_1_) {
		return TEXTURE;
	}

}

 

Spoiler

package fr.chasseetpeche92.mckart.core.init;

import fr.chasseetpeche92.mckart.McKart;
import fr.chasseetpeche92.mckart.common.entity.KartExampleEntity;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public class EntityTypesInit {
	public static final DeferredRegister <EntityType<?>> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITIES, McKart.MOD_ID);
	
	public static final RegistryObject<EntityType<KartExampleEntity>> KART_EXAMPLE = ENTITY_TYPES.register("kart_example", () -> EntityType.Builder.<KartExampleEntity>of(KartExampleEntity::new, EntityClassification.MISC)
			.sized(2.0f,2.0f)
			.build(new ResourceLocation(McKart.MOD_ID, "kart_example").toString()));
}

 

 

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.



×
×
  • Create New...

Important Information

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