tigres810 Posted August 6, 2021 Posted August 6, 2021 (edited) Okay so I looked everywhere and I cannot find anything on how to render a line from one tile entity to another I have the position of the other tileentity store in the tileentity I want to achieve the image below Any help? Edited August 7, 2021 by tigres810 Quote
Luis_ST Posted August 6, 2021 Posted August 6, 2021 6 hours ago, tigres810 said: Okay so I looked everywhere and I cannot find anything on how to render a line from one tile entity to another I have the position of the other tileentity store in the tileentity I want to achieve the image below Any help? take a look at the StructureBlockRenderer, but you normally render a line with LevelRenderer#renderLine Quote
tigres810 Posted August 7, 2021 Author Posted August 7, 2021 Now the line cuts off and is black it should be red here is the code package com.tigres810.testmod.client.renders; import java.awt.Color; import org.lwjgl.opengl.GL11; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import com.tigres810.testmod.common.tileentitys.TileEnergyDispenserBlock; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.ItemCameraTransforms; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.vector.Matrix4f; import net.minecraft.util.math.vector.Vector3d; public class RenderEnergyDispenserBlock extends TileEntityRenderer<TileEnergyDispenserBlock> { public RenderEnergyDispenserBlock(TileEntityRendererDispatcher rendererDispatcherIn) { super(rendererDispatcherIn); } @SuppressWarnings("resource") @Override public void render(TileEnergyDispenserBlock tileEntityIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferbuilder = tessellator.getBuilder(); Vector3d projectedView = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition(); matrixStackIn.pushPose(); matrixStackIn.translate(-projectedView.x, -projectedView.y, -projectedView.z); RenderSystem.lineWidth(2); Matrix4f matrix = matrixStackIn.last().pose(); Color color = new Color(255, 0, 0, 255); bufferbuilder.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR); if(tileEntityIn.getConnectedTo() != null && !tileEntityIn.getConnectedTo().equals(BlockPos.ZERO)) { drawLine(matrix, bufferbuilder, new Vector3d(tileEntityIn.getBlockPos().getX() + 1f, tileEntityIn.getBlockPos().getY() + 0.7f, tileEntityIn.getBlockPos().getZ() + 1f), new Vector3d(tileEntityIn.getConnectedTo().getX() + 1f, tileEntityIn.getConnectedTo().getY() + 0.7f, tileEntityIn.getConnectedTo().getZ() + 1f), color); } tessellator.end(); GlStateManager._lineWidth(1); matrixStackIn.popPose(); matrixStackIn.pushPose(); matrixStackIn.translate(0.5f, 0.35f, 0.5f); matrixStackIn.scale(0.2f, 0.2f, 0.2f); net.minecraft.client.renderer.ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer(); ItemStack stack = new ItemStack(Items.RED_STAINED_GLASS); IBakedModel ibakedmodel = itemRenderer.getModel(stack, tileEntityIn.getLevel(), null); itemRenderer.render(stack, ItemCameraTransforms.TransformType.FIXED, true, matrixStackIn, bufferIn, combinedLightIn, combinedOverlayIn, ibakedmodel); matrixStackIn.popPose(); } private static void drawLine(Matrix4f matrix, BufferBuilder buffer, Vector3d p1, Vector3d p2, Color color) { buffer.vertex(matrix, (float)p1.x, (float)p1.y, (float)p1.z) .color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()) .endVertex(); buffer.vertex(matrix, (float)p2.x, (float)p2.y, (float)p2.z) .color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()) .endVertex(); } } Quote
Luis_ST Posted August 7, 2021 Posted August 7, 2021 10 hours ago, tigres810 said: Now the line cuts off and is black it should be red here is the code does color method uses integers or floats as parameters? On 8/6/2021 at 9:18 AM, Luis_ST said: you normally render a line with LevelRenderer#renderLine why do you create your own method, you should use vanilla method for this Quote
tigres810 Posted August 7, 2021 Author Posted August 7, 2021 (edited) I fixed it ill mark this post as resolved Edited August 7, 2021 by tigres810 Quote
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.