package net.geforcemods.securitycraft.renderers;

import org.lwjgl.opengl.GL11;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;

import net.geforcemods.securitycraft.tileentity.TrophySystemTileEntity;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public class TrophySystemTileEntityRenderer extends TileEntityRenderer<TrophySystemTileEntity> {

	public TrophySystemTileEntityRenderer(TileEntityRendererDispatcher terd)
	{
		super(terd);
	}

	//TODO: does not work yet, line is being drawn at incorrect position
	@Override
	public void func_225616_a_(TrophySystemTileEntity te, float partialTicks, MatrixStack matrix, IRenderTypeBuffer buffer, int p_225616_5_, int p_225616_6_) {
		// The code below draws a line between the trophy system and the projectile that
		// it's targeting.

		if(te.entityBeingTargeted == null) return;

		BlockPos pos = te.getPos();
		BufferBuilder bb = Tessellator.getInstance().getBuffer();

		RenderSystem.disableTexture();
		RenderSystem.disableBlend();
		RenderSystem.lineWidth(2.0F);
		bb.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION_COLOR);
		//pos, color
		bb.func_225582_a_(pos.getX() + 0.5D, pos.getY() + 0.75D, pos.getZ() + 0.5D).func_225586_a_(255, 0, 0, 255).endVertex();
		bb.func_225582_a_(te.entityBeingTargeted.func_226277_ct_() - te.getPos().getX() - 0.5D, te.entityBeingTargeted.func_226278_cu_() - te.getPos().getY() - 0.75D, te.entityBeingTargeted.func_226281_cx_() - te.getPos().getZ() - 0.5D).func_225586_a_(255, 0, 0, 255).endVertex();
		Tessellator.getInstance().draw();
		RenderSystem.enableBlend();
		RenderSystem.enableTexture();
	}

}

@@ -47,39 +47,8 @@
 s;%0A%0A
-import org.lwjgl.opengl.GL11;%0A%0A
 impo
@@ -119,28 +119,29 @@
 e3d.
-systems.RenderSystem
+vertex.IVertexBuilder
 ;%0A%0Ai
@@ -215,60 +215,8 @@
 ty;%0A
-import net.minecraft.client.renderer.BufferBuilder;%0A
 impo
@@ -304,27 +304,73 @@
 enderer.
-Tessellator
+Matrix4f;%0Aimport net.minecraft.client.renderer.RenderType
 ;%0Aimport
@@ -513,74 +513,8 @@
 er;%0A
-import net.minecraft.client.renderer.vertex.DefaultVertexFormats;%0A
 impo
@@ -866,78 +866,8 @@
 %09%7D%0A%0A
-%09//TODO: does not work yet, line is being drawn at incorrect position%0A
 %09@Ov
@@ -1187,262 +1187,170 @@
 %0A%0A%09%09
-BlockPos pos = te.getPos();%0A%09%09BufferBuilder bb = Tessellator.getInstance().getBuffer();%0A%0A%09%09RenderSystem.disableTexture();%0A%09%09RenderSystem.disableBlend();%0A%09%09RenderSystem.lineWidth(2.0F);%0A%09%09bb.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION_COLOR
+IVertexBuilder builder = buffer.getBuffer(RenderType.func_228659_m_());%0A%09%09Matrix4f m4f = matrix.func_227866_c_().func_227870_a_();%0A%09%09BlockPos pos = te.getPos(
 );%0A
+%0A
 %09%09//
@@ -1359,33 +1359,38 @@
 s, color%0A%09%09b
-b
+uilder
 .func_22
 5582_a_(pos.
@@ -1381,72 +1381,38 @@
 c_22
-5582_a_(pos.getX() +
+7888_a_(m4f,
  0.5
-D, pos.getY() +
+F,
  0.75
-D, pos.getZ() +
+F,
  0.5
-D
+F
 ).fu
@@ -1460,17 +1460,22 @@
 %0A%09%09b
-b
+uilder
 .func_22
 5582
@@ -1474,15 +1474,28 @@
 c_22
-5582_a_
+7888_a_(m4f, (float)
 (te.
@@ -1538,35 +1538,29 @@
 ) - 
-te.getPos().getX() - 0.5D, 
+pos.getX()), (float)(
 te.e
@@ -1602,36 +1602,29 @@
 ) - 
-te.getPos().getY() - 0.75D, 
+pos.getY()), (float)(
 te.e
@@ -1666,33 +1666,19 @@
 ) - 
-te.getPos().getZ() - 0.5D
+pos.getZ())
 ).fu
@@ -1723,106 +1723,8 @@
 ();%0A
-%09%09Tessellator.getInstance().draw();%0A%09%09RenderSystem.enableBlend();%0A%09%09RenderSystem.enableTexture();%0A
 %09%7D%0A%0A

fix trophy system not rendering