Jump to content

Porting from TileEntityRenderer 1.16 to BlockEntityRenderer 1.19


Recommended Posts

Posted

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);
	}
}

 

Posted

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.

Posted

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

Posted (edited)

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.

Posted (edited)

No problem for performance. I'll do it later. I just want an example running...

What i still dont understand is how and where to set a custom texture before rendering a model.

Edited by Zacomat
typing error

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.