Jump to content

[1.15.1] Rendering block 'manually' (clientside)


Koudja

Recommended Posts

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

image.png.72f8558374337a58c85c7db3d887b8b3.png

 

After rendering "fake" block (player's hand disappear)

image.png.c000e71258ce10d73d6ce777b9da5491.png

  • Thanks 1
Link to comment
Share on other sites

4 minutes ago, Koudja said:

matrixStack.func_227861_a_(0, 0, 0); // reset translation

matrixStack.func_227865_b_(); // pop

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 by Draco18s

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.

Link to comment
Share on other sites

Have you looked at BlockRendererDispatcher#renderBlock?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Because you're waiting for RenderWorldLastEvent. As indicated by its name, it's last.

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.

Link to comment
Share on other sites

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 by Koudja
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

You probably want to use the hex representation of your color number. Also why not pass in a BlockPos instead of a Vec3d?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.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)

Link to comment
Share on other sites

On 1/15/2020 at 12:22 AM, Koudja said:

Fun fact, my snippet does not seem to work for FluidBlock

Hint: BlockRendererDispatcher#renderFluid (func_228794_a_). Look at ChunkRenderDispatcher.ChunkRender.RebuildTask#rebuild (func_228940_a_) for more context (previously RenderChunk#rebuildChunkChunkRender#rebuildChunk).

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.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)

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

    • Selamat datang di OLXTOTO, situs slot gacor terpanas yang sedang booming di industri perjudian online. Jika Anda mencari pengalaman bermain yang luar biasa, maka OLXTOTO adalah tempat yang tepat untuk Anda. Dapatkan sensasi tidak biasa dengan variasi slot online terlengkap dan peluang memenangkan jackpot slot maxwin yang sering. Di sini, Anda akan merasakan keseruan yang luar biasa dalam bermain judi slot. DAFTAR OLXTOTO DISINI LOGIN OLXTOTO DISINI AKUN PRO OLXTOTO DISINI   Slot Gacor untuk Sensasi Bermain Maksimal Olahraga cepat dan seru dengan slot gacor di OLXTOTO. Rasakan sensasi bermain maksimal dengan mesin slot yang memberikan kemenangan beruntun. Temukan keberuntungan Anda di antara berbagai pilihan slot gacor yang tersedia dan rasakan kegembiraan bermain judi slot yang tak terlupakan. Situs Slot Terpercaya dengan Pilihan Terlengkap OLXTOTO adalah situs slot terpercaya yang menawarkan pilihan terlengkap dalam perjudian online. Nikmati berbagai genre dan tema slot online yang menarik, dari slot klasik hingga slot video yang inovatif. Dipercaya oleh jutaan pemain, OLXTOTO memberikan pengalaman bermain yang aman dan terjamin.   Jackpot Slot Maxwin Sering Untuk Peluang Besar Di OLXTOTO, kami tidak hanya memberikan hadiah slot biasa, tapi juga memberikan kesempatan kepada pemain untuk memenangkan jackpot slot maxwin yang sering. Dengan demikian, Anda dapat meraih keberuntungan besar dan memenangkan ribuan rupiah sebagai hadiah jackpot slot maxwin kami. Jackpot slot maxwin merupakan peluang besar bagi para pemain judi slot untuk meraih keuntungan yang lebih besar. Dalam permainan kami, Anda tidak harus terpaku pada kemenangan biasa saja. Kami hadir dengan jackpot slot maxwin yang sering, sehingga Anda memiliki peluang yang lebih besar untuk meraih kemenangan besar dengan hadiah yang menggiurkan. Dalam permainan judi slot, pengalaman bermain bukan hanya tentang keseruan dan hiburan semata. Kami memahami bahwa para pemain juga menginginkan kesempatan untuk meraih keberuntungan besar. Oleh karena itu, OLXTOTO hadir dengan jackpot slot maxwin yang sering untuk memberikan peluang besar kepada para pemain kami. Peluang Besar Menang Jackpot Slot Maxwin Peluang menang jackpot slot maxwin di OLXTOTO sangatlah besar. Anda tidak perlu khawatir tentang batasan atau pembatasan dalam meraih jackpot tersebut. Kami ingin memberikan kesempatan kepada semua pemain kami untuk merasakan sensasi menang dalam jumlah yang luar biasa. Jackpot slot maxwin kami dibuka untuk semua pemain judi slot di OLXTOTO. Anda memiliki peluang yang sama dengan pemain lainnya untuk memenangkan hadiah jackpot yang besar. Kami percaya bahwa semua orang memiliki kesempatan untuk meraih keberuntungan besar, dan itulah mengapa kami menyediakan jackpot slot maxwin yang sering untuk memenuhi harapan dan keinginan Anda.  
    • LOGIN DAN DAFTAR DISINI SEKARANG !!!! Blacktogel adalah situs judi slot online yang menjadi pilihan banyak penggemar judi slot gacor di Indonesia. Dengan platform yang sangat user-friendly dan berbagai macam permainan slot yang tersedia, Blacktogel menjadi tempat yang tepat untuk penggemar judi slot online. Dalam artikel ini, kami akan membahas tentang Blacktogel dan keunggulan situs slot gacor online yang disediakan.  
    • Situs bandar slot online Gacor dengan bonus terbesar saat ini sedang menjadi sorotan para pemain judi online. Dengan persaingan yang semakin ketat dalam industri perjudian online, pemain mencari situs yang tidak hanya menawarkan permainan slot yang gacor (sering memberikan kemenangan), tetapi juga bonus terbesar yang bisa meningkatkan peluang menang. Daftar disini : https://gesit.io/googlegopek
    • Situs bandar slot online Gacor dengan bonus terbesar saat ini sedang menjadi sorotan para pemain judi online. Dengan persaingan yang semakin ketat dalam industri perjudian online, pemain mencari situs yang tidak hanya menawarkan permainan slot yang gacor (sering memberikan kemenangan), tetapi juga bonus terbesar yang bisa meningkatkan peluang menang. Daftar disini : https://gesit.io/googlegopek
    • Situs bandar slot online Gacor dengan bonus terbesar saat ini sedang menjadi sorotan para pemain judi online. Dengan persaingan yang semakin ketat dalam industri perjudian online, pemain mencari situs yang tidak hanya menawarkan permainan slot yang gacor (sering memberikan kemenangan), tetapi juga bonus terbesar yang bisa meningkatkan peluang menang. Daftar disini : https://gesit.io/googlegopek
  • Topics

×
×
  • Create New...

Important Information

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