diff options
author | Matt <mtthw8198@gmail.com> | 2021-06-04 14:18:06 -0700 |
---|---|---|
committer | Matt <mtthw8198@gmail.com> | 2021-06-04 14:18:06 -0700 |
commit | cc5df9c1762e81535c4f91c2c077220bf4af4f8b (patch) | |
tree | 7b8a8fce2cb7899c16a3937d729d2b93554c0aee /src/main/java/gregtech/common | |
parent | f87217e9a044b0f017d4b821017f697ca6568f42 (diff) | |
download | GT5-Unofficial-cc5df9c1762e81535c4f91c2c077220bf4af4f8b.tar.gz GT5-Unofficial-cc5df9c1762e81535c4f91c2c077220bf4af4f8b.tar.bz2 GT5-Unofficial-cc5df9c1762e81535c4f91c2c077220bf4af4f8b.zip |
User can only manually change the lower 16 bits of the coverVariable
Diffstat (limited to 'src/main/java/gregtech/common')
-rw-r--r-- | src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java | 91 |
1 files changed, 63 insertions, 28 deletions
diff --git a/src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java b/src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java index 5ad10b0edb..056f316bb1 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java @@ -3,16 +3,22 @@ package gregtech.common.covers; import gregtech.api.GregTech_API; import gregtech.api.enums.GT_Values; import gregtech.api.gui.GT_GUICover; +import gregtech.api.gui.widgets.GT_GuiIcon; +import gregtech.api.gui.widgets.GT_GuiIconCheckButton; import gregtech.api.gui.widgets.GT_GuiIntegerTextBox; import gregtech.api.interfaces.IGuiScreen; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; +import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.fluids.Fluid; public abstract class GT_Cover_RedstoneWirelessBase extends GT_CoverBehavior { + + private static int MAX_CHANNEL = 65535; + @Override public boolean onCoverRemoval(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, boolean aForced) { GregTech_API.sWirelessRedstone.put(Integer.valueOf(aCoverVariable), Byte.valueOf((byte) 0)); @@ -23,10 +29,10 @@ public abstract class GT_Cover_RedstoneWirelessBase extends GT_CoverBehavior { public boolean onCoverRightclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { if (((aX > 0.375D) && (aX < 0.625D)) || ((aSide > 3) && ((aY > 0.375D) && (aY < 0.625D)))) { GregTech_API.sWirelessRedstone.put(Integer.valueOf(aCoverVariable), Byte.valueOf((byte) 0)); - aCoverVariable = GT_Utility.stackToInt(aPlayer.inventory.getCurrentItem()); + aCoverVariable = ((Integer)GT_Utility.stackToInt(aPlayer.inventory.getCurrentItem())).hashCode(); int playerHash = aPlayer.getDisplayName().hashCode(); - aCoverVariable = playerHash << 16 | aCoverVariable >> 16; + aCoverVariable = playerHash & 0xffff0000 | aCoverVariable & 0x0000ffff; aTileEntity.setCoverDataAtSide(aSide, aCoverVariable); GT_Utility.sendChatToPlayer(aPlayer, trans("081", "Frequency: ") + aCoverVariable); @@ -40,18 +46,26 @@ public abstract class GT_Cover_RedstoneWirelessBase extends GT_CoverBehavior { if (((aX > 0.375D) && (aX < 0.625D)) || ((aSide <= 3) || (((aY > 0.375D) && (aY < 0.625D)) || ((((aZ <= 0.375D) || (aZ >= 0.625D))))))) { GregTech_API.sWirelessRedstone.put(Integer.valueOf(aCoverVariable), Byte.valueOf((byte) 0)); float[] tCoords = GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ); + + short tAdjustVal = 0; + switch ((byte) ((byte) (int) (tCoords[0] * 2.0F) + 2 * (byte) (int) (tCoords[1] * 2.0F))) { case 0: - aCoverVariable -= 32; + tAdjustVal = -32; break; case 1: - aCoverVariable += 32; + tAdjustVal = 32; break; case 2: - aCoverVariable -= 1024; + tAdjustVal = -1024; break; case 3: - aCoverVariable += 1024; + tAdjustVal = 1024; + } + + if ((aCoverVariable & 0x0000ffff) > Short.MAX_VALUE) + { + } } GT_Utility.sendChatToPlayer(aPlayer, trans("081", "Frequency: ") + aCoverVariable); @@ -129,16 +143,19 @@ public abstract class GT_Cover_RedstoneWirelessBase extends GT_CoverBehavior { this.coverID = aCoverID; this.coverVariable = aCoverVariable; - fBox = new GT_GuiIntegerTextBoxWithMinus(this, 2,startX + spaceX*0,startY+spaceY*0 + 2, spaceX*4-3,12); - fBox.setText(String.valueOf(coverVariable)); + fBox = new GT_GuiShortTextBox(this, 2,startX + spaceX*0,startY+spaceY*0 + 2, spaceX*4-3,12); + fBox.setText(String.valueOf(coverVariable & 0x0000ffff)); fBox.setMaxStringLength(12); + GuiButton b; + b = new GT_GuiIconCheckButton(this, 0, startX + spaceX * 0, startY + spaceY * 2, GT_GuiIcon.CHECKMARK, null); } @Override public void drawExtras(int mouseX, int mouseY, float parTicks) { super.drawExtras(mouseX, mouseY, parTicks); this.getFontRenderer().drawString(trans("246","Frequency" ), startX + spaceX*4, 4+startY+spaceY*0, 0xFF555555); + this.getFontRenderer().drawString(trans("601", "Use Private Frequency"), startX + spaceX * 1, startY + spaceY * 2 + 4, 0xFF555555); } @Override @@ -159,10 +176,10 @@ public abstract class GT_Cover_RedstoneWirelessBase extends GT_CoverBehavior { return; } i = i + step; - if (i > Integer.MAX_VALUE) - i = Integer.MAX_VALUE; - else if (i < Integer.MIN_VALUE) - i = Integer.MIN_VALUE; + if (i > MAX_CHANNEL) + i = MAX_CHANNEL; + else if (i < 0) + i = 0; box.setText(String.valueOf(i)); return; @@ -172,42 +189,60 @@ public abstract class GT_Cover_RedstoneWirelessBase extends GT_CoverBehavior { @Override public void applyTextBox(GT_GuiIntegerTextBox box) { - long i; + int i; String s = box.getText().trim(); try { - i = Long.parseLong(s); + i = Integer.parseInt(s); } catch (NumberFormatException e) { resetTextBox(box); return; } - if (i > Integer.MAX_VALUE) - i = Integer.MAX_VALUE; - else if (i < Integer.MIN_VALUE) - i = Integer.MIN_VALUE; - + if (i > MAX_CHANNEL) + i = MAX_CHANNEL; + else if (i < 0) + i = 0; - coverVariable = (int) i; - fBox.setText(String.valueOf(coverVariable)); + coverVariable = (coverVariable & 0xffff0000) | (i & 0x0000ffff); + fBox.setText(Integer.toString(coverVariable & 0x0000ffff)); GT_Values.NW.sendToServer(new GT_Packet_TileEntityCover(side, coverID, coverVariable, tile)); } @Override public void resetTextBox(GT_GuiIntegerTextBox box) { - box.setText(String.valueOf(coverVariable)); + box.setText(String.valueOf(coverVariable & 0x0000ffff)); } - private class GT_GuiIntegerTextBoxWithMinus extends GT_GuiIntegerTextBox { + private class GT_GuiShortTextBox extends GT_GuiIntegerTextBox { - public GT_GuiIntegerTextBoxWithMinus(IGuiScreen gui, int id, int x, int y, int width, int height) { + public GT_GuiShortTextBox(IGuiScreen gui, int id, int x, int y, int width, int height) { super(gui, id, x, y, width, height); } @Override - public boolean validChar(char c, int key) { - if (getCursorPosition() == 0 && key == 12) // minus first allowed. - return true; - return super.validChar(c, key); + public boolean textboxKeyTyped(char c, int key) { + String tText = getText().trim(); + int tValue = 0; + + super.textboxKeyTyped(c, key); + + int cursorPos = this.getCursorPosition(); + + String newText = getText().trim(); + if (newText.length() > 0) { + try { + tValue = Integer.parseInt(newText); + } catch (NumberFormatException ignored) {} + + if (tValue > MAX_CHANNEL) + setText(String.valueOf(MAX_CHANNEL)); + else + setText(String.valueOf(tValue)); + + setCursorPosition(cursorPos); + } + + return true; } } } |