From dbdd7ba11ba94651116bc21d5b376f86ce8527e0 Mon Sep 17 00:00:00 2001 From: Astoria Date: Sat, 1 Apr 2023 11:29:41 -0500 Subject: [PATCH] Better constant, settings! --- .../afloydwiremod/api/AbstractWireTile.java | 13 +++++++- .../api/AbstractWireTileEntity.java | 3 ++ .../afloydwiremod/gui/GuiButtonExtended.java | 25 +++++++++++++++ .../afloydwiremod/gui/GuiProgrammer.java | 17 ++-------- .../afloydwiremod/gui/GuiScrollable.java | 31 +++++++++++++++++++ .../afloydwiremod/gui/GuiWiring.java | 16 +--------- .../mixin/MixinEntityPlayerSP.java | 6 ++++ .../mixinInterfaces/IEntityPlayer.java | 1 + .../tileentity/ChipTileEntity.java | 2 ++ 9 files changed, 83 insertions(+), 31 deletions(-) create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/gui/GuiScrollable.java diff --git a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTile.java b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTile.java index 45c0154..b17c187 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTile.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTile.java @@ -21,6 +21,9 @@ public abstract class AbstractWireTile extends BlockContainer { ToolWiring tool = ((ToolWiring)player.inventory.getCurrentItem().getItem()); this.displayWiringGui(player, wireEntity, tool, x, y, z); return true; + } else if(player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem().itemID == WireMod.ToolProgrammer.itemID && wireEntity.initialized && wireEntity.hasSettings) { + this.displaySettingsGui(player, wireEntity); + return true; } } return false; @@ -42,6 +45,14 @@ public abstract class AbstractWireTile extends BlockContainer { } //Singleplayer ((IEntityPlayer)player).displayGuiProgrammer(chip); - + } + public void displaySettingsGui(EntityPlayer player, AbstractWireTileEntity chip){ + if(player instanceof EntityPlayerMP) { + //Multiplayer + ((IEntityPlayer)player).displayGuiSettings(chip); + return; + } + //Singleplayer + ((IEntityPlayer)player).displayGuiSettings(chip); } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java index f55259c..b6d4223 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java @@ -9,6 +9,7 @@ public abstract class AbstractWireTileEntity extends TileEntity { public WiringButton[] inputs = null; public WiringButton[] outputs = null; public boolean initialized = false; + public boolean hasSettings = false; @Override public void updateEntity() { @@ -19,6 +20,7 @@ public abstract class AbstractWireTileEntity extends TileEntity { public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); this.initialized = nbttagcompound.getBoolean("init"); + this.initialized = nbttagcompound.getBoolean("set"); if(nbttagcompound.getBoolean("inputExists")){ this.inputs = new WiringButton[nbttagcompound.getInteger("inputLength")]; NBTTagList nbttaglistInputs = nbttagcompound.getTagList("Inputs"); @@ -43,6 +45,7 @@ public abstract class AbstractWireTileEntity extends TileEntity { public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); nbttagcompound.setBoolean("init", this.initialized); + nbttagcompound.setBoolean("set", this.hasSettings); if(inputs != null){ nbttagcompound.setBoolean("inputExists", true); nbttagcompound.setInteger("inputLength", inputs.length); diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java index 8411194..f36b160 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java @@ -1,11 +1,15 @@ package net.brokenmoon.afloydwiremod.gui; +import net.minecraft.client.Minecraft; +import net.minecraft.src.FontRenderer; import net.minecraft.src.GuiButton; +import org.lwjgl.opengl.GL11; public class GuiButtonExtended extends GuiButton { public String type; public int slot; + public int scroll; public static final int width = 50; public static final int height = 10; public GuiButtonExtended(int id, int xPosition, String s, String extra, int slot) { @@ -16,4 +20,25 @@ public class GuiButtonExtended extends GuiButton { public GuiButtonExtended(int id, int xPosition, String s) { super(id, xPosition / 2 - (width / 2), 50 - height + (height * id), width, height, s); } + @Override + public void drawButton(Minecraft minecraft, int i, int j) { + if (!this.visible) { + return; + } + 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; + 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); + this.mouseDragged(minecraft, i, j); + if (!this.enabled) { + this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2 + scroll, -6250336); + } else if (flag) { + this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2 + scroll, 0xFFFFA0); + } else { + this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2 + scroll, 0xE0E0E0); + } + } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java index f6eef74..b12921f 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java @@ -5,7 +5,7 @@ import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; import net.minecraft.src.*; import org.lwjgl.input.Mouse; -public class GuiProgrammer extends GuiScreen { +public class GuiProgrammer extends GuiScrollable { private AbstractWireTileEntity wireEntity; @@ -19,20 +19,6 @@ public class GuiProgrammer extends GuiScreen { this.controlList.add(new GuiButtonExtended(2, this.width, "Count")); } - @Override - public void drawScreen(int x, int y, float renderPartialTicks) { - int wheel = Mouse.getDWheel(); - for (int i = 0; i < this.controlList.size(); ++i) { - GuiButton guibutton = this.controlList.get(i); - if(wheel > 0) - guibutton.yPosition = guibutton.yPosition + 1; - if(wheel < 0) - guibutton.yPosition = guibutton.yPosition - 1; - if(guibutton.yPosition >= 50 && guibutton.yPosition <= 200) - guibutton.drawButton(this.mc, x, y); - } - } - public GuiProgrammer(EntityPlayer player, AbstractWireTileEntity wireEntity) { super.initGui(); this.wireEntity = wireEntity; @@ -43,6 +29,7 @@ public class GuiProgrammer extends GuiScreen { 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/GuiScrollable.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiScrollable.java new file mode 100644 index 0000000..cef5180 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiScrollable.java @@ -0,0 +1,31 @@ +package net.brokenmoon.afloydwiremod.gui; + +import net.minecraft.src.GuiButton; +import net.minecraft.src.GuiScreen; +import org.lwjgl.input.Mouse; + +public class GuiScrollable extends GuiScreen { + private int scroll; + @Override + public void drawScreen(int x, int y, float renderPartialTicks) { + //TODO: Tweak these values later to fit all the stuff + int wheel = Mouse.getDWheel(); + if(wheel > 0) + scroll++; + if (wheel < 0) + scroll--; + if(scroll > 150) + scroll = 150; + if(scroll < 0) + scroll = 0; + for (int i = 0; i < this.controlList.size(); ++i) { + GuiButtonExtended guibutton = (GuiButtonExtended)this.controlList.get(i); + if(scroll >= 0) + guibutton.scroll = scroll; + if(scroll <= 0) + guibutton.scroll = scroll; + if(guibutton.yPosition >= 50 && guibutton.yPosition <= 200) + guibutton.drawButton(this.mc, x, y); + } + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java index 5f10bb4..cb46fa4 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java @@ -8,7 +8,7 @@ import net.minecraft.src.GuiButton; import net.minecraft.src.GuiScreen; import org.lwjgl.input.Mouse; -public class GuiWiring extends GuiScreen { +public class GuiWiring extends GuiScrollable { private ToolWiring tool; private int x; @@ -33,20 +33,6 @@ public class GuiWiring extends GuiScreen { } } - @Override - public void drawScreen(int x, int y, float renderPartialTicks) { - int wheel = Mouse.getDWheel(); - for (int i = 0; i < this.controlList.size(); ++i) { - GuiButton guibutton = this.controlList.get(i); - if(wheel > 0) - guibutton.yPosition = guibutton.yPosition + 1; - if(wheel < 0) - guibutton.yPosition = guibutton.yPosition - 1; - if(guibutton.yPosition >= 50 && guibutton.yPosition <= 200) - guibutton.drawButton(this.mc, x, y); - } - } - public GuiWiring(EntityPlayer player, ToolWiring tool, AbstractWireTileEntity wireEntity, int x, int y, int z) { super.initGui(); this.tool = tool; diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java index 7d867b0..91aa9d4 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java @@ -2,6 +2,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.GuiWiring; import net.brokenmoon.afloydwiremod.item.ToolWiring; import net.brokenmoon.afloydwiremod.mixinInterfaces.IEntityPlayer; @@ -23,4 +24,9 @@ public class MixinEntityPlayerSP implements IEntityPlayer { public void displayGuiWiring(ToolWiring tool, AbstractWireTileEntity chip, int x, int y, int z) { this.mc.displayGuiScreen(new GuiWiring(((EntityPlayerSP)(Object)this), tool, chip, x, y, z)); } + + @Override + public void displayGuiSettings(AbstractWireTileEntity chip) { + this.mc.displayGuiScreen(new GuiSettings(((EntityPlayerSP)(Object)this), chip)); + } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java b/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java index dafcee6..d4797f8 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java @@ -8,4 +8,5 @@ public interface IEntityPlayer { public void displayGuiProgrammer(AbstractWireTileEntity chip); public void displayGuiWiring(ToolWiring tool, AbstractWireTileEntity chip, int x, int y, int z); + public void displayGuiSettings(AbstractWireTileEntity chip); } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java index 9bf0ffc..fc3aa53 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java @@ -50,7 +50,9 @@ public class ChipTileEntity extends AbstractWireTileEntity { mode = string; this.inputs = new WiringButton[0]; this.outputs = new WiringButton[1]; + this.outputs[0] = new WiringButton(214, 240, "Output", 0); initialized = true; + hasSettings = true; } else if (string.equals("count")) { mode = string; this.inputs = new WiringButton[3];