Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.5] Bind texture to model rendered in tile entity renderer


That_Martin_Guy
 Share

Recommended Posts

I have a custom model as a part of a tile entity renderer. I want to give this model a texture. I am struggling a bit with figuring out all the steps required to do this.

 

I currently have the following code in my tile entity renderer

public class ClockworksTileEntityRenderer extends TileEntityRenderer<TheClockworksTileEntity>
{
    public static final ResourceLocation ATLAS_REGION = ResourceHelper.createNew("textures/atlas/test.png");
    public static final ResourceLocation TEXTURE = ResourceHelper.createNew("block/test.png");
    private RenderMaterial renderMaterial;

    public ClockworksTileEntityRenderer(TileEntityRendererDispatcher p_i226006_1_)
    {
        super(p_i226006_1_);

        //Instantiate model

        renderMaterial = new RenderMaterial(ATLAS_REGION, TEXTURE);
    }

    @Override
    public void render(TheClockworksTileEntity tileEntity, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer buffer, int combinedLight, int combinedOverlay)
    {
        System.out.println(ATLAS_REGION);
        IVertexBuilder builder = renderMaterial.buffer(buffer, RenderType::entityCutout);
      
        model.renderToBuffer(matrixStack, builder, combinedLight, combinedOverlay, 0, 0, 0, 0);
    }
}

When I created this code I crashed with the following message.

 

I asked on discord if I was missing something and got told I should use the TextureStitchEvent to stitch the texture to the atlas. That code looks like this:

    @SubscribeEvent
    public static void preTextureStitch(TextureStitchEvent.Pre event)
    {
        if(event.getMap().location().equals(ClockworksTileEntityRenderer.ATLAS_REGION))
            event.addSprite(ClockworksTileEntityRenderer.TEXTURE);
    }

While the event itself runs, the code inside the if statement does not.

 

Not sure how to proceed.

Link to comment
Share on other sites

4 hours ago, Luis_ST said:

show the method ResourceHelper#createNew and which is line 41 in this code?

That's just a shorthand for creating a new resource location with the mod id prefixed.

1 hour ago, diesieben07 said:

Don't try to make your own atlas.

Okay then... that doesn't tell me what to do instead though.

Link to comment
Share on other sites

Right now it doesn't crash, but the model is still untextured in game (as in, it's completely black).

 

public class ClockworksTileEntityRenderer extends TileEntityRenderer<TheClockworksTileEntity>
{
    public static final ResourceLocation TEXTURE = ResourceHelper.createNew("block/test.png");
    private RenderMaterial renderMaterial;

    public ClockworksTileEntityRenderer(TileEntityRendererDispatcher p_i226006_1_)
    {
        super(p_i226006_1_);

        //Instantiate model

        renderMaterial = new RenderMaterial(PlayerContainer.BLOCK_ATLAS, TEXTURE);
    }

    @Override
    public void render(TheClockworksTileEntity tileEntity, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer buffer, int combinedLight, int combinedOverlay)
    {
        IVertexBuilder builder = renderMaterial.buffer(buffer, RenderType::entityCutout);
      
        model.renderToBuffer(matrixStack, builder, combinedLight, combinedOverlay, 0, 0, 0, 0);
    }
}

 

Link to comment
Share on other sites

Those values are not used in the model.

	@Override
	public void renderToBuffer(MatrixStack matrixStack, IVertexBuilder buffer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha){
		modelGroup.render(matrixStack, buffer, packedLight, packedOverlay);
	}
Link to comment
Share on other sites

	private final ModelRenderer model;

	public ClockworksKnobModel() {
		super(RenderType::entityCutoutNoCull);
		texWidth = 48;
		texHeight = 48;

		model = new ModelRenderer(this);
		model.setPos(8.0F, 8, 0);
		model.texOffs(0, 1).addBox(-1.0F, -1.0F, -1.0F, 2.0F, 2.0F, 1.0F, 0.0F, false);
		model.texOffs(1, 2).addBox(-0.5F, -4.0F, -2.0F, 1.0F, 5.0F, 2.0F, 0.0F, false);
	}

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

The rendering code is part of vanilla.

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

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • you need to register the Block itself and the BlockItem for it
    • Its a render error try and lower your render distance. 
    • ---- Minecraft Crash Report ---- // This doesn't make any sense! Time: 07/12/2021 15:29 Description: Unexpected error java.lang.RuntimeException: GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT     at net.minecraft.client.shader.Framebuffer.func_147611_b(Framebuffer.java:230) ~[?:?] {re:computing_frames,xf:OptiFine:default,re:classloading,xf:OptiFine:default}     at net.minecraft.client.shader.Framebuffer.func_216492_b(Framebuffer.java:200) ~[?:?] {re:computing_frames,xf:OptiFine:default,re:classloading,xf:OptiFine:default}     at net.minecraft.client.shader.Framebuffer.func_227586_d_(Framebuffer.java:74) ~[?:?] {re:computing_frames,xf:OptiFine:default,re:classloading,xf:OptiFine:default}     at net.minecraft.client.shader.Framebuffer.func_216491_a(Framebuffer.java:52) ~[?:?] {re:computing_frames,xf:OptiFine:default,re:classloading,xf:OptiFine:default}     at net.minecraft.client.shader.Framebuffer.enableStencil(Framebuffer.java:435) ~[?:?] {re:computing_frames,xf:OptiFine:default,re:classloading,xf:OptiFine:default}     at com.simibubi.create.foundation.gui.UIRenderHelper.createFramebuffer(UIRenderHelper.java:48) ~[create:mc1.16.5_v0.3.2g] {re:mixin,re:classloading}     at com.simibubi.create.foundation.gui.UIRenderHelper.lambda$init$0(UIRenderHelper.java:40) ~[create:mc1.16.5_v0.3.2g] {re:mixin,re:classloading}     at com.mojang.blaze3d.systems.RenderSystem.replayQueue(SourceFile:116) ~[?:?] {re:classloading}     at com.mojang.blaze3d.systems.RenderSystem.flipFrame(SourceFile:103) ~[?:?] {re:classloading}     at net.minecraft.client.MainWindow.func_227802_e_(MainWindow.java:398) ~[?:?] {re:classloading,xf:OptiFine:default}     at net.minecraft.client.Minecraft.func_195542_b(Minecraft.java:997) ~[?:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:flywheel.mixins.json:ShaderCloseMixin,pl:mixin:APP:create.mixins.json:WindowResizeMixin,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:607) ~[?:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:flywheel.mixins.json:ShaderCloseMixin,pl:mixin:APP:create.mixins.json:WindowResizeMixin,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:184) ~[ForgeOptiFine%201.16.5.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[?:?] {}     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}     at java.lang.reflect.Method.invoke(Method.java:567) ~[?:?] {}     at net.minecraftforge.fml.loading.FMLClientLaunchProvider.lambda$launchService$0(FMLClientLaunchProvider.java:51) ~[forge-1.16.5-36.2.19.jar:36.2] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.0.9.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.0.9.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.0.9.jar:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.0.9.jar:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.0.9.jar:?] {} A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- System Details -- Details:     Minecraft Version: 1.16.5     Minecraft Version ID: 1.16.5     Operating System: Windows 7 (amd64) version 6.1     Java Version: 16.0.1, Oracle Corporation     Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode, sharing), Oracle Corporation     Memory: 1444724224 bytes (1377 MB) / 1793064960 bytes (1710 MB) up to 1795162112 bytes (1712 MB)     CPUs: 2     JVM Flags: 6 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xss1M -XX:+IgnoreUnrecognizedVMOptions -Xmn128M -Xmx1712M -XX:+UseConcMarkSweepGC     ModLauncher: 8.0.9+86+master.3cf110c     ModLauncher launch target: fmlclient     ModLauncher naming: srg     ModLauncher services:          /mixin-0.8.4.jar mixin PLUGINSERVICE          /eventbus-4.0.0.jar eventbus PLUGINSERVICE          /forge-1.16.5-36.2.19.jar object_holder_definalize PLUGINSERVICE          /forge-1.16.5-36.2.19.jar runtime_enum_extender PLUGINSERVICE          /forge-1.16.5-36.2.19.jar capability_inject_definalize PLUGINSERVICE          /accesstransformers-3.0.1.jar accesstransformer PLUGINSERVICE          /forge-1.16.5-36.2.19.jar runtimedistcleaner PLUGINSERVICE          /mixin-0.8.4.jar mixin TRANSFORMATIONSERVICE          /OptiFine-OptiFine-1.16.5_HD_U_G8_pre2.jar OptiFine TRANSFORMATIONSERVICE          /forge-1.16.5-36.2.19.jar fml TRANSFORMATIONSERVICE      FML: 36.2     Forge: net.minecraftforge:36.2.19     FML Language Providers:          javafml@36.2         minecraft@1     Mod List:          forge-1.16.5-36.2.19-client.jar                   |Minecraft                     |minecraft                     |1.16.5              |ENQUEUE_IM|Manifest: NOSIGNATURE         forge-1.16.5-36.2.19-universal.jar                |Forge                         |forge                         |36.2.19             |ENQUEUE_IM|Manifest: 22:af:21:d8:19:82:7f:93:94:fe:2b:ac:b7:e4:41:57:68:39:87:b1:a7:5c:c6:44:f9:25:74:21:14:f5:0d:90         flywheel-1.16-0.2.5.jar                           |Flywheel                      |flywheel                      |1.16-0.2.5          |ENQUEUE_IM|Manifest: NOSIGNATURE         create-mc1.16.5_v0.3.2g.jar                       |Create                        |create                        |v0.3.2g             |ENQUEUE_IM|Manifest: NOSIGNATURE         jei-1.16.5-7.7.1.137.jar                          |Just Enough Items             |jei                           |7.7.1.137           |ENQUEUE_IM|Manifest: NOSIGNATURE     Crash Report UUID: 6470925c-fddd-4f6c-a833-a8f649ad7dff     Launched Version: ForgeOptiFine 1.16.5     Backend library: LWJGL version 3.2.2 build 10     Backend API: GeForce 7025 / nForce 630a/integrated/SSE2 GL version 2.1.2, NVIDIA Corporation     GL Caps: Using framebuffer using ARB_framebuffer_object extension     Using VBOs: Yes     Is Modded: Definitely; Client brand changed to 'forge'     Type: Client (map_client.txt)     Graphics mode: fast     Resource Packs: vanilla, file/Termis - Resource     Current Language: English (US)     CPU: 2x AMD Athlon(tm) II X2 250 Processor     OptiFine Version: OptiFine_1.16.5_HD_U_G8_pre2     OptiFine Build: 20210305-002749     Render Distance Chunks: 2     Mipmaps: 4     Anisotropic Filtering: 1     Antialiasing: 0     Multitexture: false     Shaders: null     OpenGlVersion: 2.1.2     OpenGlRenderer: GeForce 7025 / nForce 630a/integrated/SSE2     OpenGlVendor: NVIDIA Corporation     CpuCount: 2
    • I have been trying to open a Minecraft modded server but the run.bat keeps giving me an error, I use this code but it gives me this error any help?
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.