Koudja Posted January 9, 2020 Posted January 9, 2020 Hello ! I am currently working on a Forge mod that must display a fake block on client side ("fake" because only for visual). From picking up various render methods in previous versions, and somehow dive into 1.15 new rendering system, I've managed to display something succesfully on screen. I've got an unexpected side-effect: player's hand is disappearing (or probably just rendering far away ?). I've been struggling to understand why and would like to know if anybody could help me on that point. Some snippets MinecraftForge.EVENT_BUS.addListener(renderFake); // somewhere at client's init (FMLClientSetupEvent, Dist.CLIENT) private void renderFake(RenderWorldLastEvent event) { ActiveRenderInfo renderInfo = Minecraft.getInstance().gameRenderer.getActiveRenderInfo(); BlockPos pos = new Blockpos(0, 64, 0); // Just somewhere in the world matrixStack.func_227860_a_(); // push matrixStack.func_227861_a_(-renderInfo.getProjectedView().getX(), -renderInfo.getProjectedView().getY(), -renderInfo.getProjectedView().getZ()); // translate back to camera Matrix4f matrix4f = matrixStack.func_227866_c_().func_227870_a_(); // get final transformation matrix, handy to get yaw+pitch transformation RenderSystem.multMatrix(matrix4f); Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("textures/block/stone.png")); Tessellator.getInstance().getBuffer().begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); drawBlock(Tessellator.getInstance().getBuffer(), pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, 0, 1, 0, 1, 0.5,0.5,0.5); Tessellator.getInstance().draw(); matrixStack.func_227861_a_(0, 0, 0); // reset translation matrixStack.func_227865_b_(); // pop } private static void drawBlock(final BufferBuilder bufferbuilder, final double x, final double y, final double z, final float minU, final float maxU, final float minV, final float maxV, final double x_size, final double y_size, final double z_size) { // UP bufferbuilder.func_225582_a_(-x_size + x, y_size + y, -z_size + z).func_225583_a_(maxU, maxV).endVertex(); bufferbuilder.func_225582_a_(-x_size + x, y_size + y, z_size + z).func_225583_a_(maxU, minV).endVertex(); bufferbuilder.func_225582_a_(x_size + x, y_size + y, z_size + z).func_225583_a_(minU, minV).endVertex(); bufferbuilder.func_225582_a_(x_size + x, y_size + y, -z_size + z).func_225583_a_(minU, maxV).endVertex(); // DOWN bufferbuilder.func_225582_a_(-x_size + x, -y_size + y, z_size + z).func_225583_a_(minU, minV).endVertex(); bufferbuilder.func_225582_a_(-x_size + x, -y_size + y, -z_size + z).func_225583_a_(minU, maxV).endVertex(); bufferbuilder.func_225582_a_(x_size + x, -y_size + y, -z_size + z).func_225583_a_(maxU, maxV).endVertex(); bufferbuilder.func_225582_a_(x_size + x, -y_size + y, z_size + z).func_225583_a_(maxU, minV).endVertex(); // LEFT bufferbuilder.func_225582_a_(x_size + x, -y_size + y, z_size + z).func_225583_a_(maxU, minV).endVertex(); bufferbuilder.func_225582_a_(x_size + x, -y_size + y, -z_size + z).func_225583_a_(maxU, maxV).endVertex(); bufferbuilder.func_225582_a_(x_size + x, y_size + y, -z_size + z).func_225583_a_(minU, maxV).endVertex(); bufferbuilder.func_225582_a_(x_size + x, y_size + y, z_size + z).func_225583_a_(minU, minV).endVertex(); // RIGHT bufferbuilder.func_225582_a_(-x_size + x, -y_size + y, -z_size + z).func_225583_a_(minU, maxV).endVertex(); bufferbuilder.func_225582_a_(-x_size + x, -y_size + y, z_size + z).func_225583_a_(minU, minV).endVertex(); bufferbuilder.func_225582_a_(-x_size + x, y_size + y, z_size + z).func_225583_a_(maxU, minV).endVertex(); bufferbuilder.func_225582_a_(-x_size + x, y_size + y, -z_size + z).func_225583_a_(maxU, maxV).endVertex(); // BACK bufferbuilder.func_225582_a_(-x_size + x, -y_size + y, -z_size + z).func_225583_a_(minU, maxV).endVertex(); bufferbuilder.func_225582_a_(-x_size + x, y_size + y, -z_size + z).func_225583_a_(minU, minV).endVertex(); bufferbuilder.func_225582_a_(x_size + x, y_size + y, -z_size + z).func_225583_a_(maxU, minV).endVertex(); bufferbuilder.func_225582_a_(x_size + x, -y_size + y, -z_size + z).func_225583_a_(maxU, maxV).endVertex(); // FRONT bufferbuilder.func_225582_a_(x_size + x, -y_size + y, z_size + z).func_225583_a_(maxU, minV).endVertex(); bufferbuilder.func_225582_a_(x_size + x, y_size + y, z_size + z).func_225583_a_(maxU, maxV).endVertex(); bufferbuilder.func_225582_a_(-x_size + x, y_size + y, z_size + z).func_225583_a_(minU, maxV).endVertex(); bufferbuilder.func_225582_a_(-x_size + x, -y_size + y, z_size + z).func_225583_a_(minU, minV).endVertex(); } Before rendering "fake" block After rendering "fake" block (player's hand disappear) 1 Quote
Draco18s Posted January 9, 2020 Posted January 9, 2020 (edited) On 1/9/2020 at 3:36 PM, Koudja said: matrixStack.func_227861_a_(0, 0, 0); // reset translation matrixStack.func_227865_b_(); // pop Expand pop already resets translation. That's the whole point of the pop (push/pop "the matrix" which refers to the transformation matrix, which covers translation, scale, and rotation as well as projection (roughly, the field of view)). Edited January 9, 2020 by Draco18s Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
Cadiboo Posted January 9, 2020 Posted January 9, 2020 Have you looked at BlockRendererDispatcher#renderBlock? Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
Koudja Posted January 9, 2020 Author Posted January 9, 2020 Yes, I have been trying to use it but could'nt figure out how rendering system knows where BlockPos is. I have been looking backward in stack looking for it (believing it was set before) without success I would prefer using this method rather than my own custom in fact. Quote
Cadiboo Posted January 9, 2020 Posted January 9, 2020 The block pos is used for gathering extra data + randomising the model. Passing in BlockPos.ORIGIN (or ZERO, it might have been renamed) is likely to not cause any noticeable bugs. In 1.14.4 there was a method that just took in a BlockState and rendered it, I think it was called renderBlockBrightness and you might want to replicate its logic. Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
Koudja Posted January 9, 2020 Author Posted January 9, 2020 I managed to make use of renderBlock as mentionned: public static void renderBlock2(MatrixStack matrixStack, Vec3d pos, BlockState state) { BlockRendererDispatcher renderer = Minecraft.getInstance().getBlockRendererDispatcher(); ClientWorld world = Minecraft.getInstance().world; IModelData model = renderer.getModelForState(state).getModelData(world, new BlockPos(pos), state, ModelDataManager.getModelData(world, new BlockPos(pos))); ActiveRenderInfo renderInfo = Minecraft.getInstance().gameRenderer.getActiveRenderInfo(); matrixStack.func_227860_a_(); // push matrixStack.func_227861_a_(-renderInfo.getProjectedView().getX() + pos.x, -renderInfo.getProjectedView().getY() + pos.y, -renderInfo.getProjectedView().getZ() + pos.z); // translate back to camera Minecraft.getInstance().getBlockRendererDispatcher().renderBlock(state, matrixStack, Minecraft.getInstance().func_228019_au_().func_228487_b_(), 15728880, OverlayTexture.field_229196_a_, model); matrixStack.func_227865_b_(); // pop } The only issue left is that rendered block is always on top of everything else with this method. Quote
Draco18s Posted January 9, 2020 Posted January 9, 2020 Because you're waiting for RenderWorldLastEvent. As indicated by its name, it's last. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
Koudja Posted January 9, 2020 Author Posted January 9, 2020 Method in first snippet produced a block that was always behind world. Shall I use a different BufferBuilder to reproduce same behavior ? Quote
Koudja Posted January 13, 2020 Author Posted January 13, 2020 (edited) I found out why it was on top of everything else. There is 2 different RenderTypeBuffer.Impl available in client, one is for displaying stuff as part of GUI (in top of world rendering), the other is for world rendering. Thanks to everyone working with me on this ! Here is a working snippet for anyone struggling with same issue as me (needless to say, it's physical client-side code only) public void render(RenderWorldLastEvent event) { Vec3d location; // some location in world BlockState state; // some BlockState (does not have to be part of world) renderBlock(event.getMatrixStack(), location, state); } public static void renderBlock(MatrixStack matrixStack, Vec3d pos, BlockState state) { BlockRendererDispatcher renderer = Minecraft.getInstance().getBlockRendererDispatcher(); ClientWorld world = Minecraft.getInstance().world; IModelData model = renderer.getModelForState(state).getModelData(world, new BlockPos(pos), state, ModelDataManager.getModelData(world, new BlockPos(pos))); ActiveRenderInfo renderInfo = Minecraft.getInstance().gameRenderer.getActiveRenderInfo(); matrixStack.func_227860_a_(); // push matrixStack.func_227861_a_(-renderInfo.getProjectedView().getX() + pos.x, -renderInfo.getProjectedView().getY() + pos.y, -renderInfo.getProjectedView().getZ() + pos.z); // translate back to camera // Overlay texture = custom RGBA on top of texture, 0 -> red //func_228487_b_ -> display over everything else //func_228489_c_ -> display as part of chunk rendering Minecraft.getInstance().getBlockRendererDispatcher().renderBlock(state, matrixStack, Minecraft.getInstance().func_228019_au_().func_228489_c_(), 15728880, OverlayTexture.field_229196_a_, model); matrixStack.func_227865_b_(); // pop } Edited January 13, 2020 by Koudja 1 1 Quote
Cadiboo Posted January 14, 2020 Posted January 14, 2020 You probably want to use the hex representation of your color number. Also why not pass in a BlockPos instead of a Vec3d? Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
Koudja Posted January 14, 2020 Author Posted January 14, 2020 I am using this code to render a moving block, whose location is not discrete. Fun fact, my snippet does not seem to work for FluidBlock; I shall look on that part later on. Quote
Cadiboo Posted January 15, 2020 Posted January 15, 2020 On 1/14/2020 at 1:22 PM, Koudja said: Fun fact, my snippet does not seem to work for FluidBlock Expand Hint: BlockRendererDispatcher#renderFluid (func_228794_a_). Look at ChunkRenderDispatcher.ChunkRender.RebuildTask#rebuild (func_228940_a_) for more context (previously RenderChunk#rebuildChunk / ChunkRender#rebuildChunk). Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
Recommended Posts
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.