From 8a6accae6ff91cfd861cf3e96881a3a7b22d248f Mon Sep 17 00:00:00 2001 From: Astoria Date: Mon, 3 Apr 2023 18:42:44 -0500 Subject: [PATCH] Add Display --- .../net/brokenmoon/afloydwiremod/WireMod.java | 9 ++- .../afloydwiremod/ter/TERDisplay.java | 73 ++++++++++++++++++ .../{tileentity => ter}/TERWire.java | 2 +- .../afloydwiremod/tile/DisplayTile.java | 17 ++++ .../tileentity/DisplayTileEntity.java | 35 +++++++++ .../assets/afloydwiremod/block/display.png | Bin 0 -> 312 bytes 6 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/ter/TERDisplay.java rename src/main/java/net/brokenmoon/afloydwiremod/{tileentity => ter}/TERWire.java (99%) create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/tile/DisplayTile.java create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/tileentity/DisplayTileEntity.java create mode 100644 src/main/resources/assets/afloydwiremod/block/display.png diff --git a/src/main/java/net/brokenmoon/afloydwiremod/WireMod.java b/src/main/java/net/brokenmoon/afloydwiremod/WireMod.java index 03ed5d9..dece9f0 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/WireMod.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/WireMod.java @@ -2,12 +2,13 @@ package net.brokenmoon.afloydwiremod; import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; import net.brokenmoon.afloydwiremod.item.ToolWiring; +import net.brokenmoon.afloydwiremod.ter.TERDisplay; +import net.brokenmoon.afloydwiremod.ter.TERWire; import net.brokenmoon.afloydwiremod.tile.ChipTile; import net.brokenmoon.afloydwiremod.item.ToolProgrammer; +import net.brokenmoon.afloydwiremod.tile.DisplayTile; import net.brokenmoon.afloydwiremod.tile.RedstoneLinkTile; -import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; -import net.brokenmoon.afloydwiremod.tileentity.RedstoneLinkTileEntity; -import net.brokenmoon.afloydwiremod.tileentity.TERWire; +import net.brokenmoon.afloydwiremod.tileentity.*; import net.fabricmc.api.ModInitializer; import net.minecraft.src.Block; import net.minecraft.src.Item; @@ -30,6 +31,7 @@ public class WireMod implements ModInitializer { public static Block LinkTileInactive = BlockHelper.createBlock(MOD_ID, new RedstoneLinkTile(908, Material.iron, false), "linkTile", "linkOff.png", Block.soundStoneFootstep, 5, 5, 0); public static Block LinkTileActive = BlockHelper.createBlock(MOD_ID, new RedstoneLinkTile(909, Material.iron, true), "linkTile", "linkOn.png", Block.soundStoneFootstep, 5, 5, 0); + public static Block ScreenTile = BlockHelper.createBlock(MOD_ID, new DisplayTile(910, Material.glass), "displayTile", "display.png", Block.soundGlassFootstep, 5, 5, 0); @Override public void onInitialize() { @@ -38,5 +40,6 @@ public class WireMod implements ModInitializer { EntityHelper.createTileEntity(ChipTileEntity.class, "Chip"); EntityHelper.createTileEntity(RedstoneLinkTileEntity.class, "Redstone Link"); EntityHelper.createSpecialTileEntity(AbstractWireTileEntity.class, new TERWire(), "Wire"); + EntityHelper.createSpecialTileEntity(DisplayTileEntity.class, new TERDisplay(), "Display"); } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/ter/TERDisplay.java b/src/main/java/net/brokenmoon/afloydwiremod/ter/TERDisplay.java new file mode 100644 index 0000000..a6afc62 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/ter/TERDisplay.java @@ -0,0 +1,73 @@ +package net.brokenmoon.afloydwiremod.ter; + +import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; +import net.brokenmoon.afloydwiremod.api.AbstractWireTileSided; +import net.brokenmoon.afloydwiremod.tileentity.DisplayTileEntity; +import net.minecraft.client.Minecraft; +import net.minecraft.src.Block; +import net.minecraft.src.FontRenderer; +import net.minecraft.src.TileEntity; +import net.minecraft.src.TileEntitySpecialRenderer; +import org.lwjgl.opengl.GL11; + +import java.awt.*; + +public class TERDisplay extends TileEntitySpecialRenderer { + @Override + public void renderTileEntityAt(TileEntity tileEntity, double d, double e, double f, float g) { + this.renderDisplay((DisplayTileEntity)tileEntity, d, e, f, g); + } + + private void renderDisplay(DisplayTileEntity tileEntity, double d, double e, double f, float g) { + if(tileEntity.inputs != null){ + for(int it = 0; it < tileEntity.inputs.length; it++){ + if(tileEntity.inputs[it] != null && tileEntity.isLineReversed != null){ + this.renderTextLine(d, e, f, it, tileEntity.inputs[it].floatvalue, tileEntity.inputs[it].stringvalue, tileEntity.isLineReversed[it], Minecraft.getMinecraft().theWorld.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord)); + } + } + } + } + + private void renderTextLine(double d, double d1, double d2, int line, float floatvalue, String stringvalue, boolean reversed, int meta) { + String strToRender; + if(reversed) { + strToRender = floatvalue + stringvalue; + }else{ + strToRender = stringvalue + floatvalue; + } + FontRenderer fontRenderer = this.getFontRenderer(); + GL11.glPushMatrix(); + GL11.glTranslatef((float)d, (float)d1, (float)d2); + float yoff = 0.151f; + switch(meta) { + case 5: + GL11.glTranslatef(0.5f, yoff, 0.53f); + GL11.glRotatef(-90f, 1, 0, 0); + break; + case 0: + GL11.glTranslatef(0.5f, 1 - yoff, 0.47f); + GL11.glRotatef(90f, 1, 0, 0); + break; + case 4: + GL11.glTranslatef(0.5f, 0.47f, 1 - yoff); + GL11.glRotatef(180f, 0, 1, 0); + break; + case 3: + GL11.glTranslatef(0.5f, 0.47f, yoff); + break; + case 1: + GL11.glRotatef(90f, 0, 1, 0); + GL11.glTranslatef(-0.5f, 0.47f, yoff); + break; + case 2: + GL11.glRotatef(-90f, 0, 1, 0); + GL11.glTranslatef(0.5f, 0.47f, - 1 + yoff); + break; + } + GL11.glScalef(0.02f, -0.02f, 0.02f); + fontRenderer.drawString(strToRender, -fontRenderer.getStringWidth(strToRender) / 2, line * 10 - 4 * 5, 0xFFFFFF); + fontRenderer.drawString(strToRender, -fontRenderer.getStringWidth(strToRender) / 2, line * 10 - 4 * 5, 0xFFFFFF); + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + GL11.glPopMatrix(); + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/TERWire.java b/src/main/java/net/brokenmoon/afloydwiremod/ter/TERWire.java similarity index 99% rename from src/main/java/net/brokenmoon/afloydwiremod/tileentity/TERWire.java rename to src/main/java/net/brokenmoon/afloydwiremod/ter/TERWire.java index a332963..d08c033 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/TERWire.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/ter/TERWire.java @@ -1,4 +1,4 @@ -package net.brokenmoon.afloydwiremod.tileentity; +package net.brokenmoon.afloydwiremod.ter; import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; import net.brokenmoon.afloydwiremod.api.AbstractWireTileSided; diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tile/DisplayTile.java b/src/main/java/net/brokenmoon/afloydwiremod/tile/DisplayTile.java new file mode 100644 index 0000000..3287949 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/tile/DisplayTile.java @@ -0,0 +1,17 @@ +package net.brokenmoon.afloydwiremod.tile; + +import net.brokenmoon.afloydwiremod.api.AbstractWireTileSided; +import net.brokenmoon.afloydwiremod.tileentity.DisplayTileEntity; +import net.minecraft.src.Material; +import net.minecraft.src.TileEntity; + +public class DisplayTile extends AbstractWireTileSided { + public DisplayTile(int i, Material material) { + super(i, material); + } + + @Override + protected TileEntity getBlockEntity() { + return new DisplayTileEntity(); + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/DisplayTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/DisplayTileEntity.java new file mode 100644 index 0000000..cb5ff18 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/DisplayTileEntity.java @@ -0,0 +1,35 @@ +package net.brokenmoon.afloydwiremod.tileentity; + +import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; +import net.brokenmoon.afloydwiremod.gui.WiringButton; +import net.minecraft.src.NBTTagCompound; + +public class DisplayTileEntity extends AbstractWireTileEntity { + public boolean[] isLineReversed = new boolean[4]; + public DisplayTileEntity(){ + super(); + inputs = new WiringButton[4]; + inputs[0] = new WiringButton(214, 220, "Line 1", 0); + inputs[1] = new WiringButton(214, 220, "Line 2", 1); + inputs[2] = new WiringButton(214, 220, "Line 3", 2); + inputs[3] = new WiringButton(214, 220, "Line 4", 3); + outputs = new WiringButton[0]; + this.initialized = true; + } + + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) { + super.readFromNBT(nbttagcompound); + for(int i = 0; i < isLineReversed.length; i++){ + isLineReversed[i] = nbttagcompound.getBoolean("reverse" + i); + } + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) { + super.writeToNBT(nbttagcompound); + for(int i = 0; i < isLineReversed.length; i++){ + nbttagcompound.setBoolean("reverse" + i, isLineReversed[i]); + } + } +} diff --git a/src/main/resources/assets/afloydwiremod/block/display.png b/src/main/resources/assets/afloydwiremod/block/display.png new file mode 100644 index 0000000000000000000000000000000000000000..528e252034db58d016083b2436c3c4ea07b3007e GIT binary patch literal 312 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1Igx&WULS49bF zYX$XM3**&+2Iot)KWugU|E~GOmDuFf_SUuj`r*MErVi5birU()R`zi|8Lj?Hc1(J4 z;OqYv_aD4iy!=o`{!9nYVjWXo5eYqS*`Q37lsQ@jXY{N82bKRnwD5nY@iSM;wfe3V zvi|