From 61475f86eaccd1ee982449b1eb805951b5ca8dcc Mon Sep 17 00:00:00 2001 From: Astoria Date: Sat, 1 Apr 2023 18:00:43 -0500 Subject: [PATCH] Pushing data, two way connections --- .../afloydwiremod/api/AbstractWireTile.java | 5 +- .../api/AbstractWireTileEntity.java | 26 +++++---- .../afloydwiremod/api/WireConnection.java | 13 ++--- .../afloydwiremod/gui/GuiButtonExtended.java | 2 +- .../afloydwiremod/gui/GuiProgrammer.java | 4 -- .../afloydwiremod/gui/GuiWiring.java | 23 ++++++-- .../mixin/MixinBlockRenderer.java | 56 +++++++++++++++++++ .../tileentity/ChipTileEntity.java | 2 +- .../tileentity/RedstoneLinkTileEntity.java | 2 +- src/main/resources/afloydwiremod.mixins.json | 3 +- 10 files changed, 103 insertions(+), 33 deletions(-) create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinBlockRenderer.java diff --git a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTile.java b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTile.java index b17c187..0be15e6 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTile.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTile.java @@ -3,7 +3,6 @@ package net.brokenmoon.afloydwiremod.api; import net.brokenmoon.afloydwiremod.WireMod; import net.brokenmoon.afloydwiremod.item.ToolWiring; import net.brokenmoon.afloydwiremod.mixinInterfaces.IEntityPlayer; -import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; import net.minecraft.src.*; public abstract class AbstractWireTile extends BlockContainer { @@ -55,4 +54,8 @@ public abstract class AbstractWireTile extends BlockContainer { //Singleplayer ((IEntityPlayer)player).displayGuiSettings(chip); } + @Override + public int getRenderType(){ + return 28; + } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java index 6c06070..49eb20a 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java @@ -75,18 +75,24 @@ public abstract class AbstractWireTileEntity extends TileEntity { } public void updateIO(){ - if(inputs != null) { - for (int i = 0; i < inputs.length; ++i) { - if (inputs[i].wire != null && inputs[i].wire.thisslot > -1) { - WireConnection wire = inputs[i].wire; + if(outputs != null) { + for (int i = 0; i < outputs.length; ++i) { + if (outputs[i].wire != null && outputs[i].wire.thisslot > -1) { + WireConnection wire = outputs[i].wire; AbstractWireTileEntity otherChip = (AbstractWireTileEntity)this.worldObj.getBlockTileEntity(wire.x, wire.y, wire.z); - if(otherChip == null) break; - if(otherChip.outputs == null) break; - if(inputs[i].floatvalue != otherChip.outputs[wire.thatslot].floatvalue) { - inputs[i].floatvalue = otherChip.outputs[wire.thatslot].floatvalue; + if(otherChip == null){ + this.outputs[i].wire = new WireConnection(); + break; } - if(!inputs[i].stringvalue.equals(otherChip.outputs[wire.thatslot].stringvalue)) { - inputs[i].stringvalue = otherChip.outputs[wire.thatslot].stringvalue; + if(otherChip.outputs == null) { + this.outputs[i].wire = new WireConnection(); + break; + } + if(outputs[i].floatvalue != otherChip.inputs[wire.thatslot].floatvalue) { + otherChip.inputs[wire.thatslot].floatvalue = outputs[i].floatvalue; + } + if(!outputs[i].stringvalue.equals(otherChip.inputs[wire.thatslot].stringvalue)) { + otherChip.inputs[wire.thatslot].stringvalue = outputs[i].stringvalue; } } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java b/src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java index 48fcd5a..079e504 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java @@ -1,9 +1,9 @@ package net.brokenmoon.afloydwiremod.api; -import net.brokenmoon.afloydwiremod.gui.WiringButton; import net.minecraft.src.NBTTagCompound; public class WireConnection { + public boolean isMade; public int x; public int y; public int z; @@ -11,13 +11,7 @@ public class WireConnection { public int thatslot; public WireConnection(){ - - } - public WireConnection(int x, int y, int z, int thisslot){ - this.x = x; - this.y = y; - this.z = z; - this.thisslot = thisslot; + this.isMade = false; } public WireConnection(int x, int y, int z, int thisslot, int thatslot){ @@ -26,12 +20,14 @@ public class WireConnection { this.z = z; this.thisslot = thisslot; this.thatslot = thatslot; + this.isMade = true; } public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) { nbttagcompound.setInteger("wx", this.x); nbttagcompound.setInteger("wy", this.y); nbttagcompound.setInteger("wz", this.z); + nbttagcompound.setBoolean("made", this.isMade); nbttagcompound.setInteger("wthisslot", thisslot); nbttagcompound.setInteger("wthatslot", thatslot); return nbttagcompound; @@ -41,6 +37,7 @@ public class WireConnection { this.x = nbttagcompound.getInteger("wx"); this.y = nbttagcompound.getInteger("wy"); this.z = nbttagcompound.getInteger("wz"); + this.isMade = nbttagcompound.getBoolean("made"); this.thisslot = nbttagcompound.getInteger("wthisslot"); this.thatslot = nbttagcompound.getInteger("wthatslot"); } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java index f36b160..847bf01 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java @@ -28,7 +28,7 @@ public class GuiButtonExtended extends GuiButton { FontRenderer fontrenderer = minecraft.fontRenderer; GL11.glBindTexture(3553, minecraft.renderEngine.getTexture("/gui/gui.png")); GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - boolean flag = i >= this.xPosition && j >= this.yPosition && i < this.xPosition + this.width && j < this.yPosition + this.height; + boolean flag = i >= this.xPosition && j >= this.yPosition + scroll && i < this.xPosition + this.width && j < this.yPosition + scroll + this.height; int k = this.getButtonState(flag); this.drawTexturedModalRect(this.xPosition, this.yPosition + scroll, 0, 46 + k * 20, this.width / 2, this.height); this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition + scroll, 200 - this.width / 2, 46 + k * 20, this.width / 2, this.height); diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java index b12921f..b78b4d3 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java @@ -3,14 +3,11 @@ package net.brokenmoon.afloydwiremod.gui; import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; import net.minecraft.src.*; -import org.lwjgl.input.Mouse; public class GuiProgrammer extends GuiScrollable { private AbstractWireTileEntity wireEntity; - private int scroll; - @Override public void initGui() { //this.height - 240 is top @@ -29,7 +26,6 @@ public class GuiProgrammer extends GuiScrollable { if(wireEntity instanceof ChipTileEntity) { if (guibutton.id == 1) { ((ChipTileEntity) wireEntity).setMode("constant"); - System.out.println("ae"); } else if (guibutton.id == 2) { ((ChipTileEntity) wireEntity).setMode("count"); } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java index cb46fa4..d8b931e 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java @@ -3,6 +3,7 @@ package net.brokenmoon.afloydwiremod.gui; import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; import net.brokenmoon.afloydwiremod.api.WireConnection; import net.brokenmoon.afloydwiremod.item.ToolWiring; +import net.minecraft.client.Minecraft; import net.minecraft.src.EntityPlayer; import net.minecraft.src.GuiButton; import net.minecraft.src.GuiScreen; @@ -20,15 +21,15 @@ public class GuiWiring extends GuiScrollable { //this.height - 240 is top //This.width / 2 - 214 is left //Inputs - if(wireEntity.inputs != null && this.tool.type.equals("output")) { + if(wireEntity.inputs != null && !this.tool.type.equals("input")) { for (int i = 0; i < wireEntity.inputs.length; i++) { - this.controlList.add(new GuiButtonExtended(i + 1, this.width, wireEntity.inputs[i].buttonString, "Input", wireEntity.inputs[i].slot)); + this.controlList.add(new GuiButtonExtended(i + 1, this.width - 50, wireEntity.inputs[i].buttonString, "Input", wireEntity.inputs[i].slot)); } } //Outputs if(wireEntity.outputs != null && !this.tool.type.equals("output")) { for (int i = 0; i < wireEntity.outputs.length; i++) { - this.controlList.add(new GuiButtonExtended(i + 1, this.width, wireEntity.outputs[i].buttonString, "Output", wireEntity.outputs[i].slot)); + this.controlList.add(new GuiButtonExtended(i + 1, this.width + 50, wireEntity.outputs[i].buttonString, "Output", wireEntity.outputs[i].slot)); } } } @@ -61,9 +62,19 @@ public class GuiWiring extends GuiScrollable { this.tool.y = y; this.tool.z = z; } - } else if(this.tool.type.equals("output")) { - this.wireEntity.inputs[guibutton.slot].wire = new WireConnection(tool.x, tool.y, tool.z, guibutton.slot, tool.slot); - tool.type = "unpaired"; + } else if(!this.tool.type.equals("unpaired")) { + if(this.tool.type.equals("output")) { + AbstractWireTileEntity otherEntity = (AbstractWireTileEntity)Minecraft.getMinecraft().theWorld.getBlockTileEntity(tool.x, tool.y, tool.z); + otherEntity.outputs[guibutton.slot].wire = new WireConnection(this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, tool.slot, guibutton.slot); + Minecraft.getMinecraft().theWorld.markBlocksDirty(x, y, z, x, y, z); + Minecraft.getMinecraft().theWorld.markBlocksDirty(this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord); + tool.type = "unpaired"; + } else if(this.tool.type.equals("input")) { + this.wireEntity.outputs[guibutton.slot].wire = new WireConnection(this.tool.x, this.tool.y, this.tool.z, guibutton.slot, tool.slot); + Minecraft.getMinecraft().theWorld.markBlocksDirty(x, y, z, x, y, z); + Minecraft.getMinecraft().theWorld.markBlocksDirty(this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord); + tool.type = "unpaired"; + } } this.mc.displayGuiScreen(null); } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinBlockRenderer.java b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinBlockRenderer.java new file mode 100644 index 0000000..97adec9 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinBlockRenderer.java @@ -0,0 +1,56 @@ +package net.brokenmoon.afloydwiremod.mixin; + +import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; +import net.minecraft.src.Block; +import net.minecraft.src.RenderBlocks; +import net.minecraft.src.World; +import org.lwjgl.opengl.GL11; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(value = RenderBlocks.class, remap = false) +public class MixinBlockRenderer { + @Shadow + public boolean renderStandardBlock(Block block, int i, int j, int k) { return false; } + @Shadow + World world; + @Inject(method = "Lnet/minecraft/src/RenderBlocks;renderBlockByRenderType(Lnet/minecraft/src/Block;III)Z", at = @At("HEAD")) + public void injectMethod(Block block, int i, int j, int k, CallbackInfoReturnable cir){ + if(block.getRenderType() == 28){ + AbstractWireTileEntity wireEntity = (AbstractWireTileEntity)this.world.getBlockTileEntity(i, j, k); + if(wireEntity.outputs != null){ + for(int it = 0; it < wireEntity.outputs.length; it++){ + if(wireEntity.outputs[it].wire != null && wireEntity.outputs[it].wire.isMade){ + this.renderLineBetweenTwoPoints(i, j, k, wireEntity.outputs[it].wire.x, wireEntity.outputs[it].wire.y, wireEntity.outputs[it].wire.z); + } + } + } + this.renderStandardBlock(block, i, j, k); + + } + } + + public void renderLineBetweenTwoPoints(long x1, long y1, long z1, long x2, long y2, long z2, float red, float green, float blue, float alpha, float width){ + GL11.glPushMatrix(); + GL11.glColor4f(red, green, blue, alpha); + GL11.glLineWidth(width); + GL11.glBegin(GL11.GL_LINES); + GL11.glVertex3f(Math.floorMod(x1, 16l), Math.floorMod(y1, 16l), Math.floorMod(z1, 16l)); + GL11.glVertex3f(Math.floorMod(x1, 16l) - (x1 - x2), Math.floorMod(y1, 16l) - (y1 - y2), Math.floorMod(z1, 16l) - (z1 - z2)); + GL11.glEnd(); + GL11.glPopMatrix(); + } + public void renderLineBetweenTwoPoints(long x1, long y1, long z1, long x2, long y2, long z2, float red, float green, float blue, float alpha){ + renderLineBetweenTwoPoints(x1, y1, z1, x2, y2, z2, red, green, blue, alpha, 1); + } + + public void renderLineBetweenTwoPoints(long x1, long y1, long z1, long x2, long y2, long z2, float red, float green, float blue){ + renderLineBetweenTwoPoints(x1, y1, z1, x2, y2, z2, red, green, blue, 255, 1); + } + public void renderLineBetweenTwoPoints(long x1, long y1, long z1, long x2, long y2, long z2){ + renderLineBetweenTwoPoints(x1, y1, z1, x2, y2, z2, 255, 0, 0, 255, 5); + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java index fc3aa53..a9b95df 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java @@ -10,12 +10,12 @@ public class ChipTileEntity extends AbstractWireTileEntity { @Override public void updateEntity() { - updateIO(); switch (mode) { case "count": doIncrement(); break; } + updateIO(); } public void doIncrement() { diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java index 59752e2..33a1cf9 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java @@ -32,7 +32,6 @@ public class RedstoneLinkTileEntity extends AbstractWireTileEntity { } @Override public void updateEntity() { - updateIO(); if(inputs[0].floatvalue > 0 && !this.isActive && worldObj.blockExists(xCoord, yCoord, zCoord) && worldObj.getBlockId(xCoord, yCoord, zCoord) == WireMod.LinkTileInactive.blockID){ this.shouldnotremove = true; RedstoneLinkTile.updateLinkBlockState(true, this.worldObj, this.xCoord, this.yCoord, this.zCoord); @@ -44,5 +43,6 @@ public class RedstoneLinkTileEntity extends AbstractWireTileEntity { this.shouldnotremove = false; this.isActive = false; } + updateIO(); } } diff --git a/src/main/resources/afloydwiremod.mixins.json b/src/main/resources/afloydwiremod.mixins.json index 82d0380..7716fed 100644 --- a/src/main/resources/afloydwiremod.mixins.json +++ b/src/main/resources/afloydwiremod.mixins.json @@ -4,7 +4,8 @@ "package": "net.brokenmoon.afloydwiremod.mixin", "compatibilityLevel": "JAVA_8", "mixins": [ - "MixinEntityPlayerSP" + "MixinEntityPlayerSP", + "MixinBlockRenderer" ], "client": [ ],