From 6cd86ee3c5bf73abd8fc64a513f2eced899264dc Mon Sep 17 00:00:00 2001 From: Brian Ricketts Date: Fri, 28 Dec 2012 03:23:55 -0600 Subject: [PATCH] Starting to work on printing the filtered items above the rejector --- .../client/render/RenderHelper.java | 50 +++++++++++++++++++ .../client/render/RenderSorter.java | 13 ++++- .../common/machine/TileEntityRejector.java | 11 ++-- 3 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 src/minecraft/assemblyline/client/render/RenderHelper.java diff --git a/src/minecraft/assemblyline/client/render/RenderHelper.java b/src/minecraft/assemblyline/client/render/RenderHelper.java new file mode 100644 index 000000000..af3260604 --- /dev/null +++ b/src/minecraft/assemblyline/client/render/RenderHelper.java @@ -0,0 +1,50 @@ +package assemblyline.client.render; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.entity.RenderManager; + +import org.lwjgl.opengl.GL11; + +public class RenderHelper +{ + public static void renderFloatingText(String text, float x, float y, float z) + { + RenderManager renderManager = RenderManager.instance; + FontRenderer fontRenderer = renderManager.getFontRenderer(); + float scale = 0.027f; + GL11.glPushMatrix(); + GL11.glTranslatef((float) x + 0.0F, (float) y + 2.3F, (float) z); + GL11.glNormal3f(0.0F, 1.0F, 0.0F); + GL11.glRotatef(-renderManager.playerViewY, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(renderManager.playerViewX, 1.0F, 0.0F, 0.0F); + GL11.glScalef(-scale, -scale, scale); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDepthMask(false); + GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + Tessellator tessellator = Tessellator.instance; + int yOffset = 0; + + GL11.glDisable(GL11.GL_TEXTURE_2D); + tessellator.startDrawingQuads(); + int stringMiddle = fontRenderer.getStringWidth(text) / 2; + tessellator.setColorRGBA_F(0.0F, 0.0F, 0.0F, 0.25F); + tessellator.addVertex((double) (-stringMiddle - 1), (double) (-1 + yOffset), 0.0D); + tessellator.addVertex((double) (-stringMiddle - 1), (double) (8 + yOffset), 0.0D); + tessellator.addVertex((double) (stringMiddle + 1), (double) (8 + yOffset), 0.0D); + tessellator.addVertex((double) (stringMiddle + 1), (double) (-1 + yOffset), 0.0D); + tessellator.draw(); + GL11.glEnable(GL11.GL_TEXTURE_2D); + fontRenderer.drawString(text, -fontRenderer.getStringWidth(text) / 2, yOffset, 553648127); + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glDepthMask(true); + fontRenderer.drawString(text, -fontRenderer.getStringWidth(text) / 2, yOffset, -1); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_BLEND); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glPopMatrix(); + } +} diff --git a/src/minecraft/assemblyline/client/render/RenderSorter.java b/src/minecraft/assemblyline/client/render/RenderSorter.java index c61bf3bdf..056a15d83 100644 --- a/src/minecraft/assemblyline/client/render/RenderSorter.java +++ b/src/minecraft/assemblyline/client/render/RenderSorter.java @@ -1,6 +1,7 @@ package assemblyline.client.render; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import org.lwjgl.opengl.GL11; @@ -8,6 +9,7 @@ import org.lwjgl.opengl.GL11; import assemblyline.client.model.ModelSorter; import assemblyline.common.AssemblyLine; import assemblyline.common.machine.TileEntityRejector; +import assemblyline.common.machine.filter.ItemFilter; public class RenderSorter extends TileEntitySpecialRenderer { @@ -46,7 +48,16 @@ public class RenderSorter extends TileEntitySpecialRenderer model.renderMain(0.0625F); model.renderPiston(0.0625F, pos); GL11.glPopMatrix(); - + + ItemStack filter = tileEntity.getFilter(); + if (filter != null) + { + ItemStack filterItem = ItemFilter.getFilters(filter).get(0); + if (filterItem != null) + { + RenderHelper.renderFloatingText(filterItem.getDisplayName(), (float) x + 0.5f, (float) y, (float) z + 0.5f); + } + } } @Override diff --git a/src/minecraft/assemblyline/common/machine/TileEntityRejector.java b/src/minecraft/assemblyline/common/machine/TileEntityRejector.java index 1fde1b9eb..e9d3d8fb3 100644 --- a/src/minecraft/assemblyline/common/machine/TileEntityRejector.java +++ b/src/minecraft/assemblyline/common/machine/TileEntityRejector.java @@ -1,5 +1,7 @@ package assemblyline.common.machine; +import java.io.DataInputStream; +import java.io.InputStream; import java.util.ArrayList; import java.util.List; @@ -46,7 +48,7 @@ public class TileEntityRejector extends TileEntityAssemblyNetwork implements IRo */ private enum PacketTypes { - ANIMATION, GUI, SETTINGON + ANIMATION, INVENTORY, SETTINGON } /** @@ -124,7 +126,7 @@ public class TileEntityRejector extends TileEntityAssemblyNetwork implements IRo @Override public Packet getDescriptionPacket() { - return PacketManager.getPacket(AssemblyLine.CHANNEL, this, this.getPacketData(PacketTypes.GUI)); + return PacketManager.getPacket(AssemblyLine.CHANNEL, this, this.getPacketData(PacketTypes.INVENTORY)); } /** @@ -199,7 +201,7 @@ public class TileEntityRejector extends TileEntityAssemblyNetwork implements IRo public Object[] getPacketData(PacketTypes id) { if (id == PacketTypes.ANIMATION) { return new Object[] { id.ordinal(), this.firePiston }; } - if (id == PacketTypes.GUI) + if (id == PacketTypes.INVENTORY) { Object[] da = new Object[this.guiButtons.length + 1]; da[0] = id.ordinal(); @@ -220,12 +222,13 @@ public class TileEntityRejector extends TileEntityAssemblyNetwork implements IRo { int id = dataStream.readInt(); PacketTypes pID = PacketTypes.values()[id]; + DataInputStream inputStream = new DataInputStream((InputStream) dataStream); if (pID == PacketTypes.ANIMATION) { this.firePiston = dataStream.readBoolean(); } - else if (pID == PacketTypes.GUI) + else if (pID == PacketTypes.INVENTORY) { for (int i = 0; i < this.guiButtons.length; i++) {