Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Resolved][1.16.5] How I can render a line from one tile entity to another

Featured Replies

Posted

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?

2021-08-06_02.47.52.jpg

Edited by tigres810

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

  • Author

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

 

2021-08-07_02.11.06.png

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

  • tigres810 changed the title to [Resolved][1.16.5] How I can render a line from one tile entity to another

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.