Jump to content

Porting from TileEntityRenderer 1.16 to BlockEntityRenderer 1.19


Zacomat

Recommended Posts

Hello everyone!

I want to port my old TileEntityRenderer from version 1.16 to 1.19.
It seems like a lot of things have changed in the rendering system and I can't find any documentation about it.

The block is drawn automatically since FishingnetBlock#getRenderType returns BlockRenderType.MODEL.
This drawing includes only the faces of the cube.
In my tile entity renderer I want to draw two additional rectangles as specified in the FishingnetModel class below.
These rectangles are oriented at an angle specified in my tile entity.
The textures of the rectangles depend on a parameter of my tile entity.

Can anyone help me do this update?
Where can I find documentation on the 1.19 rendering system?

Thank you all.

This is the code of the FishingnetTileEntityRenderer class:


package com.polipo.fishing_net.client.renderer.tileentity;

import com.mojang.blaze3d.matrix.MatrixStack;

import com.mojang.blaze3d.vertex.IVertexBuilder;
import com.polipo.fishing_net.FishingnetMod;
import com.polipo.fishing_net.client.renderer.model.FishingnetModel;
import com.polipo.fishing_net.tileentity.FishingnetTileEntity;

import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.util.ResourceLocation;

public class FishingnetTileEntityRenderer extends TileEntityRenderer<FishingnetTileEntity> {

	FishingnetModel model = new FishingnetModel();
	ResourceLocation[] textures = { new ResourceLocation(FishingnetMod.MODID + ":textures/block/net0.png"), new ResourceLocation(FishingnetMod.MODID + ":textures/block/net1.png"), new ResourceLocation(FishingnetMod.MODID + ":textures/block/net2.png"), new ResourceLocation(FishingnetMod.MODID + ":textures/block/net3.png"), new ResourceLocation(FishingnetMod.MODID + ":textures/block/net4.png"), new ResourceLocation(FishingnetMod.MODID + ":textures/block/net5.png"), };

	public FishingnetTileEntityRenderer(TileEntityRendererDispatcher rendererDispatcherIn) {
		super(rendererDispatcherIn);
	}

	@Override
	public void render(FishingnetTileEntity tileEntityNet, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) {

		int textureIndex = tileEntityNet.getItemsCount();
		if (textureIndex > textures.length - 1) {
			textureIndex = textures.length - 1;
		}
		if (textureIndex < 0) {
			textureIndex = 0;
		}
		renderDispatcher.textureManager.bindTexture(textures[textureIndex]);

		model.rotateY(tileEntityNet.facing);

		IVertexBuilder ivertexbuilder = bufferIn.getBuffer(model.getRenderType(textures[textureIndex]));

		model.render(matrixStackIn, ivertexbuilder, combinedLightIn, combinedOverlayIn, 1, 1, 1, 1);
	}

}

and this is the code of the FishingnetModel class:


package com.polipo.fishing_net.client.renderer.model;

import com.mojang.blaze3d.matrix.MatrixStack;

import com.mojang.blaze3d.vertex.IVertexBuilder;

import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.model.Model;
import net.minecraft.client.renderer.model.ModelRenderer;

public class FishingnetModel extends Model {

	ModelRenderer shape1;
	ModelRenderer shape2;

	public FishingnetModel() {
		super(RenderType::getEntityCutoutNoCull);

		textureWidth = 64;
		textureHeight = 64;

		shape1 = new ModelRenderer(this);
		shape1.setTextureSize(64, 64);
		shape1.setTextureOffset(0, 32);
		shape1.setRotationPoint(8, 0, 8);
		shape1.mirror = false;
		shape1.rotateAngleX = 0;
		shape1.rotateAngleY = 0.785f;
		shape1.rotateAngleZ = 0;
		shape1.addBox(-11, 0, 0, 22, 16, 0);

		shape2 = new ModelRenderer(this);
		shape2.setTextureSize(64, 64);
		shape2.setTextureOffset(0, 48);
		shape2.setRotationPoint(8, 0, 8);
		shape2.mirror = false;
		shape2.rotateAngleX = 0;
		shape2.rotateAngleY = 2.356f;
		shape2.rotateAngleZ = 0;
		shape2.addBox(-11, 0, 0, 22, 16, 0);
	}

	public void rotateY(int facing) {
		shape1.rotateAngleY = 0.0245f * facing;
		shape2.rotateAngleY = 1.570f + 0.0245f * facing;
	}

	@Override
	public void render(MatrixStack matrixStackIn, IVertexBuilder bufferIn, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) {
		shape1.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn, red, green, blue, alpha);
		shape2.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn, red, green, blue, alpha);
	}
}

 

Link to comment
Share on other sites

This link has a guide for 1.16 -> 1.17 including a tool for semi-automating it and a reference to a bot on the forge discord for getting new names from old names.

https://gist.github.com/50ap5ud5/beebcf056cbdd3c922cc8993689428f4

The 1.19 changes (including another tool) are linked here: https://forums.minecraftforge.net/topic/114502-forge-411-minecraft-119

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

Thx!

Very interesting! 

So let's say i want to render an enchanting table book in my render function i added this:

	public void render(NetBlockEntity be, float partial, PoseStack pose, MultiBufferSource buffer, int light, int overlay) {

		BookModel model = new BookModel(context.bakeLayer(ModelLayers.BOOK));
		pose.pushPose();
		pose.translate(0.5D, 1.0625D, 0.5D);
		pose.mulPose(Vector3f.YP.rotationDegrees(0));
		pose.mulPose(Vector3f.ZP.rotationDegrees(67.5F));
		pose.translate(0.0D, -0.125D, 0.0D);
		model.setupAnim(0.0F, 0.1F, 0.9f, 1.2F);
		RenderSystem.setShaderTexture(0, new ResourceLocation("textures/entity/enchanting_table_book"));
		RenderSystem.setShaderColor(1f, 1f, 0f, 0.5f);
		VertexConsumer vertexconsumer = sprite().wrap(buffer.getBuffer(RenderType.entityCutout(BLOCK_ATLAS)));
		model.render(pose, vertexconsumer, light, overlay, 1.0F, 1.0F, 1.0F, 1.0F);
		pose.popPose();
	}

 but the texture is from my block. The texture specified in RenderSystem.setShaderTexture(0, new ResourceLocation("textures/entity/enchanting_table_book"))

is not used... Nor colors worked: RenderSystem.setShaderColor(1f, 1f, 0f, 0.5f);

Link to comment
Share on other sites

Not really my area of expertise, but...

Look at what EnchantmentTableRenderer EnchantTableRenderer does and adapt it to your needs.

NOTE: how it sets up the model in the constructor not on every render call.

 

The last four parameters of model.render() are rgba.

I don't know what it actually does with Block models? Like I said not an expert.🙂  

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

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

    • Error: java.lang.NullPointerException: Cannot invoke "me.codexadrian.tempad.TempadClientConfig.renderBlur()" because the return value of "me.codexadrian.tempad.TempadClient.getClientConfig()" is null I keep having this error while trying to launch a modpack through the forge modloader, any suggestions? https://docs.google.com/document/d/1CRKUoSiu2e_mDvDTVYpIA5wqD3w-BsCycxBu1_vQ4OA/edit?usp=sharing Crash Report ^^^^
    • I'm trying to start a server with the latest installer, but running the run.bat file doesn't generate new files. It shows the following in the cmd prompt.
    • One of my players is suddenly unable to join a locally hosted MC Eternal server. We have been playing on this server for about 2-3 weeks now. I have tried erasing his player files and his reputation file, and now it just coughs up this and kicks him out: [User Authenticator #5/INFO] [minecraft/NetHandlerLoginServer]: UUID of player EthosTheGod is 7692d8db-02c3-424f-a4ab-0e4e259b106b [20:25:36] [User Authenticator #4/INFO] [minecraft/NetHandlerLoginServer]: UUID of player EthosTheGod is 7692d8db-02c3-424f-a4ab-0e4e259b106b [20:29:35] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Did the system time change, or is the server overloaded? Running 575849ms behind, skipping 11516 tick(s) [20:29:35] [Server thread/INFO] [minecraft/NetHandlerLoginServer]: com.mojang.authlib.GameProfile@4a6c63f1[id=7692d8db-02c3-424f-a4ab-0e4e259b106b,name=EthosTheGod,properties={textures=[com.mojang.authlib.properties.Property@241ea89e]},legacy=false] (/IP.ADDRESS) lost connection: Disconnected [20:29:35] [Server thread/INFO] [minecraft/NetHandlerLoginServer]: com.mojang.authlib.GameProfile@6ab6c661[id=7692d8db-02c3-424f-a4ab-0e4e259b106b,name=EthosTheGod,properties={textures=[com.mojang.authlib.properties.Property@7f19aae3]},legacy=false] (/IP.ADDRESS) lost connection: Disconnected It just says "connection timed out" on his end. Any ideas?
    • I'm trying to migrate my mod from 1.20 to 1.21. Some packages in the forge api were changed so my mod did have some classes not working. I've changed everything i needed but still is getting me the following error error: cannot access Registry DeferredRegister.create(ForgeRegistries.BLOCKS, FarmMod.MOD_ID); ^ class file for net.minecraft.core.Registry not found The piece of code that is wrong is   public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, FarmMod.MOD_ID); And here are my imports   import com.lucas.farmmod.FarmMod; import com.lucas.farmmod.block.custom.BaseIrrigatorBlock; import com.lucas.farmmod.item.ModItems; import com.lucas.farmmod.item.custom.BaseIrrigatorBlockItem; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegistryObject; The class DeferredRegister is throwing the error in the print below     I've tried running rebuilding my project in every way possible, tried refreshing my dependencies but nothing works. What can i do?
    • It sounds like there might be a synchronization issue with your PartEntity. Ensure that the part entity’s position is updated in your entity's tick method to continuously match the main entity’s location.
  • Topics

×
×
  • Create New...

Important Information

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