From d50e817bcdccdbc0605531e405e67586b43387ea Mon Sep 17 00:00:00 2001 From: Astoria Date: Sun, 2 Apr 2023 14:11:12 -0500 Subject: [PATCH] Funky fresh colorful, transparent wires --- .../afloydwiremod/api/AbstractWireTile.java | 6 ++- .../afloydwiremod/api/WireConnection.java | 22 +++++++- .../afloydwiremod/gui/GuiWireTool.java | 49 ++++++++++++++++++ .../afloydwiremod/gui/GuiWiring.java | 6 +-- .../afloydwiremod/item/ToolWiring.java | 43 +++++++++++---- .../mixin/MixinBlockRenderer.java | 26 ++++++---- .../mixin/MixinEntityPlayerSP.java | 6 +++ .../mixinInterfaces/IEntityPlayer.java | 1 + .../assets/afloydwiremod/block/chip.png | Bin 349 -> 4413 bytes 9 files changed, 134 insertions(+), 25 deletions(-) create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWireTool.java diff --git a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTile.java b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTile.java index 50d512b..57a456a 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTile.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTile.java @@ -25,7 +25,6 @@ public abstract class AbstractWireTile extends BlockContainer { return true; } } - System.out.println(world.getBlockMetadata(x, y, z)); return false; } public void displayWiringGui(EntityPlayer player, AbstractWireTileEntity chip, ToolWiring tool, int x, int y, int z) { @@ -59,4 +58,9 @@ public abstract class AbstractWireTile extends BlockContainer { public int getRenderType(){ return 28; } + + @Override + public int getRenderBlockPass() { + return 1; + } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java b/src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java index 7096591..3a5ba07 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java @@ -17,12 +17,17 @@ public class WireConnection { public ArrayList zadd = new ArrayList(); public ArrayList sideadd = new ArrayList(); public boolean backwired = false; + public float red = 1; + public float green = 0; + public float blue = 0; + public float alpha = 1; + public float width = 5f; public WireConnection(){ this.isMade = false; } - public WireConnection(int x, int y, int z, int slot, int slot1, ArrayList xadd, ArrayList yadd, ArrayList zadd, ArrayList sideadd, boolean backwired) { + public WireConnection(int x, int y, int z, int slot, int slot1, ArrayList xadd, ArrayList yadd, ArrayList zadd, ArrayList sideadd, boolean backwired, float red, float green, float blue, float alpha, float width) { this.x = x; this.y = y; this.z = z; @@ -31,6 +36,11 @@ public class WireConnection { this.xadd = xadd; this.yadd = yadd; this.zadd = zadd; + this.red = red; + this.green = green; + this.blue = blue; + this.alpha = alpha; + this.width = width; this.sideadd = sideadd; this.backwired = backwired; this.isMade = true; @@ -45,6 +55,11 @@ public class WireConnection { nbttagcompound.setInteger("wthatslot", thatslot); nbttagcompound.setInteger("wexsize", xadd.size()); nbttagcompound.setBoolean("wback", backwired); + nbttagcompound.setFloat("wred", red); + nbttagcompound.setFloat("wgreen", green); + nbttagcompound.setFloat("wblue", blue); + nbttagcompound.setFloat("walpha", alpha); + nbttagcompound.setFloat("wwidth", width); for(int i = 0; i < xadd.size(); i++){ nbttagcompound.setInteger("xadd" + i, xadd.get(i)); nbttagcompound.setInteger("yadd" + i, yadd.get(i)); @@ -62,6 +77,11 @@ public class WireConnection { this.thisslot = nbttagcompound.getInteger("wthisslot"); this.thatslot = nbttagcompound.getInteger("wthatslot"); this.backwired = nbttagcompound.getBoolean("wback"); + this.red = nbttagcompound.getFloat("wred"); + this.green = nbttagcompound.getFloat("wgreen"); + this.blue = nbttagcompound.getFloat("wblue"); + this.alpha = nbttagcompound.getFloat("walpha"); + this.width = nbttagcompound.getFloat("wwidth"); for(int i = 0; i < nbttagcompound.getInteger("wexsize"); i++){ this.xadd.add(i, nbttagcompound.getInteger("xadd" + i)); this.yadd.add(i, nbttagcompound.getInteger("yadd" + i)); diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWireTool.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWireTool.java new file mode 100644 index 0000000..2197757 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWireTool.java @@ -0,0 +1,49 @@ +package net.brokenmoon.afloydwiremod.gui; + +import net.brokenmoon.afloydwiremod.item.ToolWiring; +import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; +import net.minecraft.src.EntityPlayerSP; +import net.minecraft.src.GuiButton; +import net.minecraft.src.GuiScreen; +import net.minecraft.src.GuiSlider; + +public class GuiWireTool extends GuiScreen { + public ToolWiring tool; + public GuiWireTool(EntityPlayerSP entityPlayerSP, ToolWiring toolWiring) { + super.initGui(); + this.tool = toolWiring; + } + + @Override + public void initGui() { + this.controlList.add(new GuiSlider(1, this.width/2-100, this.height/2-40, 200, 20, "Red", tool.red)); + this.controlList.add(new GuiSlider(2, this.width/2-100, this.height/2-20, 200, 20, "Green", tool.green)); + this.controlList.add(new GuiSlider(3, this.width/2-100, this.height/2+00, 200, 20, "Blue", tool.blue)); + this.controlList.add(new GuiSlider(4, this.width/2-100, this.height/2+20, 200, 20, "Alpha", tool.alpha)); + this.controlList.add(new GuiSlider(5, this.width/2-100, this.height/2+40, 200, 20, "Width", tool.width)); + } + + @Override + protected void actionPerformed(GuiButton guiButton){ + if(guiButton instanceof GuiSlider){ + switch(guiButton.id){ + case 1: + tool.red = ((GuiSlider) guiButton).sliderValue; + break; + case 2: + tool.green = ((GuiSlider) guiButton).sliderValue; + break; + case 3: + tool.blue = ((GuiSlider) guiButton).sliderValue; + break; + case 4: + tool.alpha = ((GuiSlider) guiButton).sliderValue; + break; + case 5: + tool.width = ((GuiSlider) guiButton).sliderValue; + break; + } + } + } + +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java index 956388f..17485d5 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java @@ -72,8 +72,7 @@ public class GuiWiring extends GuiScrollable { } } else if(!this.tool.type.equals("unpaired")) { if(this.tool.type.equals("input")) { - AbstractWireTileEntity otherEntity = (AbstractWireTileEntity)Minecraft.getMinecraft().theWorld.getBlockTileEntity(tool.x, tool.y, tool.z); - wireEntity.outputs[guibutton.slot].wire = new WireConnection(this.tool.x, this.tool.y, this.tool.z, guibutton.slot, tool.slot, tool.xadd, tool.yadd, tool.zadd, tool.sideadd, false); + wireEntity.outputs[guibutton.slot].wire = new WireConnection(this.tool.x, this.tool.y, this.tool.z, guibutton.slot, tool.slot, tool.xadd, tool.yadd, tool.zadd, tool.sideadd, false, tool.red, tool.green, tool.blue, tool.alpha, tool.width); 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.xadd = new ArrayList(); @@ -83,7 +82,8 @@ public class GuiWiring extends GuiScrollable { tool.type = "unpaired"; } else if(this.tool.type.equals("output")) { AbstractWireTileEntity otherEntity = (AbstractWireTileEntity)Minecraft.getMinecraft().theWorld.getBlockTileEntity(tool.x, tool.y, tool.z); - otherEntity.outputs[tool.slot].wire = new WireConnection(this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, tool.slot, guibutton.slot, tool.xadd, tool.yadd, tool.zadd, tool.sideadd, true); + if(otherEntity != null) + otherEntity.outputs[tool.slot].wire = new WireConnection(this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, tool.slot, guibutton.slot, tool.xadd, tool.yadd, tool.zadd, tool.sideadd, true, tool.red, tool.green, tool.blue, tool.alpha, tool.width); 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.xadd = new ArrayList(); diff --git a/src/main/java/net/brokenmoon/afloydwiremod/item/ToolWiring.java b/src/main/java/net/brokenmoon/afloydwiremod/item/ToolWiring.java index 9822930..c5df477 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/item/ToolWiring.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/item/ToolWiring.java @@ -1,9 +1,8 @@ package net.brokenmoon.afloydwiremod.item; -import net.minecraft.src.EntityPlayer; -import net.minecraft.src.Item; -import net.minecraft.src.ItemStack; -import net.minecraft.src.World; +import net.brokenmoon.afloydwiremod.WireMod; +import net.brokenmoon.afloydwiremod.mixinInterfaces.IEntityPlayer; +import net.minecraft.src.*; import java.util.ArrayList; import java.util.Stack; @@ -19,17 +18,41 @@ public class ToolWiring extends Item { public ArrayList sideadd = new ArrayList(); public String type = "unpaired"; public int slot; + + public float red = 1; + public float green = 0; + public float blue = 0; + public float alpha = 1; + public float width = 0.5f; + public ToolWiring(int i) { super(i); this.maxStackSize = 1; } public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l, double heightPlaced) { - xadd.add(i); - yadd.add(j); - zadd.add(k); - sideadd.add(l); - System.out.println(l); + if(entityplayer.isSneaking()){ + if (!world.isMultiplayerAndNotHost) { + this.displayWireSettings(entityplayer, this); + return true; + } + } else { + xadd.add(i); + yadd.add(j); + zadd.add(k); + sideadd.add(l); + return false; + } return false; } -} + + private void displayWireSettings(EntityPlayer player, ToolWiring toolWiring) { + if(player instanceof EntityPlayerMP) { + //Multiplayer + ((IEntityPlayer)player).displayGuiWireSettings(toolWiring); + return; + } + //Singleplayer + ((IEntityPlayer)player).displayGuiWireSettings(toolWiring); + } + } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinBlockRenderer.java b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinBlockRenderer.java index 948ffb7..4088dd4 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinBlockRenderer.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinBlockRenderer.java @@ -23,27 +23,30 @@ public class MixinBlockRenderer { 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")) + @Inject(method = "Lnet/minecraft/src/RenderBlocks;renderBlockByRenderType(Lnet/minecraft/src/Block;III)Z", at = @At("HEAD"), cancellable = true) 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(block instanceof AbstractWireTileSided) { + this.renderSidedBlock(block, i, j, k); + } else { + this.renderStandardBlock(block, 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, + this.renderLineBetweenTwoPoints( + i, j, k, wireEntity.outputs[it].wire.x, wireEntity.outputs[it].wire.y, wireEntity.outputs[it].wire.z, + wireEntity.outputs[it].wire.red, wireEntity.outputs[it].wire.green, wireEntity.outputs[it].wire.blue, wireEntity.outputs[it].wire.alpha, wireEntity.outputs[it].wire.width * 10, wireEntity.outputs[it].wire.xadd, wireEntity.outputs[it].wire.yadd, wireEntity.outputs[it].wire.zadd, wireEntity.outputs[it].wire.sideadd, wireEntity.outputs[it].wire.backwired, - block instanceof AbstractWireTileSided, Block.getBlock(world.getBlockId(wireEntity.outputs[it].wire.x, wireEntity.outputs[it].wire.y, wireEntity.outputs[it].wire.z)) instanceof AbstractWireTileSided); + block instanceof AbstractWireTileSided, + Block.getBlock(world.getBlockId(wireEntity.outputs[it].wire.x, wireEntity.outputs[it].wire.y, wireEntity.outputs[it].wire.z)) instanceof AbstractWireTileSided); } } } - if(block instanceof AbstractWireTileSided) { - this.renderSidedBlock(block, i, j, k); - } else { - this.renderStandardBlock(block, i, j, k); - } - + cir.setReturnValue(true); } } @@ -107,6 +110,8 @@ public class MixinBlockRenderer { 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, ArrayList xadd, ArrayList yadd, ArrayList zadd, ArrayList sideadd, boolean backwired, boolean firstblocksided, boolean secondblocksided){ GL11.glPushMatrix(); GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glColor4f(red, green, blue, alpha); GL11.glLineWidth(width); GL11.glBegin(GL11.GL_LINE_STRIP); @@ -356,6 +361,7 @@ public class MixinBlockRenderer { } } GL11.glEnd(); + GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glPopMatrix(); } @@ -367,6 +373,6 @@ public class MixinBlockRenderer { renderLineBetweenTwoPoints(x1, y1, z1, x2, y2, z2, red, green, blue, 255, 1, xadd, yadd, zadd, sideadd, backwired, firstblocksided, secondblocksided); } public void renderLineBetweenTwoPoints(long x1, long y1, long z1, long x2, long y2, long z2, ArrayList xadd, ArrayList yadd, ArrayList zadd, ArrayList sideadd, boolean backwired, boolean firstblocksided, boolean secondblocksided){ - renderLineBetweenTwoPoints(x1, y1, z1, x2, y2, z2, 255, 0, 0, 255 / 2, 5, xadd, yadd, zadd, sideadd, backwired, firstblocksided, secondblocksided); + renderLineBetweenTwoPoints(x1, y1, z1, x2, y2, z2, 255, 0, 0, 255f / 2, 5, xadd, yadd, zadd, sideadd, backwired, firstblocksided, secondblocksided); } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java index 91aa9d4..787d54f 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java @@ -3,6 +3,7 @@ package net.brokenmoon.afloydwiremod.mixin; import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; import net.brokenmoon.afloydwiremod.gui.GuiProgrammer; import net.brokenmoon.afloydwiremod.gui.GuiSettings; +import net.brokenmoon.afloydwiremod.gui.GuiWireTool; import net.brokenmoon.afloydwiremod.gui.GuiWiring; import net.brokenmoon.afloydwiremod.item.ToolWiring; import net.brokenmoon.afloydwiremod.mixinInterfaces.IEntityPlayer; @@ -29,4 +30,9 @@ public class MixinEntityPlayerSP implements IEntityPlayer { public void displayGuiSettings(AbstractWireTileEntity chip) { this.mc.displayGuiScreen(new GuiSettings(((EntityPlayerSP)(Object)this), chip)); } + + @Override + public void displayGuiWireSettings(ToolWiring toolWiring) { + this.mc.displayGuiScreen(new GuiWireTool(((EntityPlayerSP)(Object)this), toolWiring)); + } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java b/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java index d4797f8..e6f04a2 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java @@ -9,4 +9,5 @@ public interface IEntityPlayer { public void displayGuiWiring(ToolWiring tool, AbstractWireTileEntity chip, int x, int y, int z); public void displayGuiSettings(AbstractWireTileEntity chip); + public void displayGuiWireSettings(ToolWiring toolWiring); } diff --git a/src/main/resources/assets/afloydwiremod/block/chip.png b/src/main/resources/assets/afloydwiremod/block/chip.png index 9588be73647cce127d8c069c16b0b6fe9b1c2952..37ddbd2e0de71bf5b34081d9d2f63f2f09b25479 100644 GIT binary patch literal 4413 zcm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