aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMatt <mtthw8198@gmail.com>2021-06-06 07:54:55 -0700
committerMatt <mtthw8198@gmail.com>2021-06-06 07:54:55 -0700
commit5c68f72256dd5641a113a345700d307312b8693c (patch)
tree0782193e00eea657679faaa34819218f31d630bd /src/main/java
parent51fcb8af2bd2022d9a9111e2874e508d4059d8d0 (diff)
downloadGT5-Unofficial-5c68f72256dd5641a113a345700d307312b8693c.tar.gz
GT5-Unofficial-5c68f72256dd5641a113a345700d307312b8693c.tar.bz2
GT5-Unofficial-5c68f72256dd5641a113a345700d307312b8693c.zip
Uses GT_WirelessRedstoneCover packets now
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_WirelessRedstoneCover.java44
-rw-r--r--src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java84
2 files changed, 73 insertions, 55 deletions
diff --git a/src/main/java/gregtech/api/net/GT_Packet_WirelessRedstoneCover.java b/src/main/java/gregtech/api/net/GT_Packet_WirelessRedstoneCover.java
index c4196f17aa..64ac09c59e 100644
--- a/src/main/java/gregtech/api/net/GT_Packet_WirelessRedstoneCover.java
+++ b/src/main/java/gregtech/api/net/GT_Packet_WirelessRedstoneCover.java
@@ -3,6 +3,7 @@ package gregtech.api.net;
import com.google.common.io.ByteArrayDataInput;
import gregtech.api.interfaces.tileentity.ICoverable;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.INetHandler;
import net.minecraft.network.NetHandlerPlayServer;
@@ -13,27 +14,25 @@ import net.minecraftforge.common.DimensionManager;
public class GT_Packet_WirelessRedstoneCover extends GT_Packet_TileEntityCover {
private static final int PRIVATE_MASK = 0xFFFE0000;
- private static final int PUBLIC_MASK = 0x0000FFFF;
- private static final int CHECKBOX_MASK = 0x00010000;
-
- protected int mX;
- protected short mY;
- protected int mZ;
-
- protected byte side;
- protected int coverID, coverData, dimID;
private EntityPlayerMP mPlayer;
+ private int mPublicChannel;
+ private int mCheckBoxValue;
public GT_Packet_WirelessRedstoneCover() {
super();
}
- public GT_Packet_WirelessRedstoneCover(int mX, short mY, int mZ, byte coverSide, int coverID, int coverData, int dimID) {
+ public GT_Packet_WirelessRedstoneCover(int mX, short mY, int mZ, byte coverSide, int coverID, int coverData, int dimID, int publicChannel, int checkBoxValue) {
super(mX, mY, mZ, coverSide, coverID, coverData, dimID);
+ mPublicChannel = publicChannel;
+ mCheckBoxValue = checkBoxValue;
}
- public GT_Packet_WirelessRedstoneCover(byte coverSide, int coverID, int coverData, ICoverable tile) {
+
+ public GT_Packet_WirelessRedstoneCover(byte coverSide, int coverID, int coverData, ICoverable tile, int publicChannel, int checkBoxValue) {
super(coverSide, coverID, coverData, tile);
+ mPublicChannel = publicChannel;
+ mCheckBoxValue = checkBoxValue;
}
@Override
@@ -49,6 +48,22 @@ public class GT_Packet_WirelessRedstoneCover extends GT_Packet_TileEntityCover {
}
@Override
+ public void encode(ByteBuf aOut) {
+ aOut.writeInt(mX);
+ aOut.writeShort(mY);
+ aOut.writeInt(mZ);
+
+ aOut.writeByte(side);
+ aOut.writeInt(coverID);
+ aOut.writeInt(coverData);
+
+ aOut.writeInt(dimID);
+
+ aOut.writeInt(mPublicChannel);
+ aOut.writeInt(mCheckBoxValue);
+ }
+
+ @Override
public GT_Packet_New decode(ByteArrayDataInput aData) {
return new GT_Packet_WirelessRedstoneCover(
aData.readInt(),
@@ -59,6 +74,9 @@ public class GT_Packet_WirelessRedstoneCover extends GT_Packet_TileEntityCover {
aData.readInt(),
aData.readInt(),
+ aData.readInt(),
+
+ aData.readInt(),
aData.readInt());
}
@@ -68,7 +86,9 @@ public class GT_Packet_WirelessRedstoneCover extends GT_Packet_TileEntityCover {
if (world != null && world.blockExists(mX, mY, mZ)) {
TileEntity tile = world.getTileEntity(mX, mY, mZ);
if (tile instanceof IGregTechTileEntity && !((IGregTechTileEntity) tile).isDead()) {
- ((IGregTechTileEntity) tile).receiveCoverData(side, coverID, (mPlayer.getUniqueID().hashCode() & PRIVATE_MASK) | (coverData & PUBLIC_MASK | CHECKBOX_MASK));
+ int tPrivateChannel = (mCheckBoxValue > 0) ? mPlayer.getUniqueID().hashCode() & PRIVATE_MASK : 0;
+ int tCoverData = tPrivateChannel | mCheckBoxValue | mPublicChannel;
+ ((IGregTechTileEntity) tile).receiveCoverData(side, coverID, tCoverData);
}
}
}
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 e71461a817..fac6fa1d34 100644
--- a/src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java
+++ b/src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java
@@ -9,6 +9,7 @@ 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.net.GT_Packet_WirelessRedstoneCover;
import gregtech.api.util.GT_CoverBehavior;
import gregtech.api.util.GT_Utility;
import net.minecraft.client.gui.GuiButton;
@@ -63,15 +64,17 @@ public abstract class GT_Cover_RedstoneWirelessBase extends GT_CoverBehavior {
tAdjustVal = 1024;
}
- int tCoverVariable = (aCoverVariable & PUBLIC_MASK) + tAdjustVal;
+ int tPublicChannel = (aCoverVariable & PUBLIC_MASK) + tAdjustVal;
- if (tCoverVariable < 0) {
- aCoverVariable = aCoverVariable & (PRIVATE_MASK | CHECKBOX_MASK);
+ if (tPublicChannel < 0) {
+ aCoverVariable = aCoverVariable & ~PUBLIC_MASK;
}
-
- if (tCoverVariable > MAX_CHANNEL) {
+ else if (tPublicChannel > MAX_CHANNEL) {
aCoverVariable = (aCoverVariable & (PRIVATE_MASK | CHECKBOX_MASK)) | MAX_CHANNEL;
}
+ else {
+ aCoverVariable = (aCoverVariable & (PRIVATE_MASK | CHECKBOX_MASK)) | tPublicChannel;
+ }
}
GT_Utility.sendChatToPlayer(aPlayer, trans("081", "Frequency: ") + aCoverVariable);
return aCoverVariable;
@@ -175,19 +178,19 @@ public abstract class GT_Cover_RedstoneWirelessBase extends GT_CoverBehavior {
if (box.isFocused()) {
int step = Math.max(1, Math.abs(delta / 120));
step = (isShiftKeyDown() ? 1000 : isCtrlKeyDown() ? 50 : 1) * (delta > 0 ? step : -step);
- long i;
+ long tCoverVariable;
try {
- i = Long.parseLong(box.getText());
+ tCoverVariable = Long.parseLong(box.getText());
} catch (NumberFormatException e) {
return;
}
- i = i + step;
- if (i > MAX_CHANNEL)
- i = MAX_CHANNEL;
- else if (i < 0)
- i = 0;
+ tCoverVariable = tCoverVariable + step;
+ if (tCoverVariable > MAX_CHANNEL)
+ tCoverVariable = MAX_CHANNEL;
+ else if (tCoverVariable < 0)
+ tCoverVariable = 0;
- box.setText(String.valueOf(i));
+ box.setText(String.valueOf(tCoverVariable));
return;
}
}
@@ -195,28 +198,31 @@ public abstract class GT_Cover_RedstoneWirelessBase extends GT_CoverBehavior {
@Override
public void applyTextBox(GT_GuiIntegerTextBox box) {
- int i;
+ int tPublicChannel;
String s = box.getText().trim();
try {
- i = Integer.parseInt(s);
+ tPublicChannel = Integer.parseInt(s);
} catch (NumberFormatException e) {
resetTextBox(box);
return;
}
- if (i > MAX_CHANNEL)
- i = MAX_CHANNEL;
- else if (i < 0)
- i = 0;
+ if (tPublicChannel > MAX_CHANNEL)
+ tPublicChannel = MAX_CHANNEL;
+ else if (tPublicChannel < 0)
+ tPublicChannel = 0;
+
+ int tCheckBoxValue = ((GT_GuiIconCheckButton)this.buttonList.get(0)).isChecked() ? CHECKBOX_MASK : 0;
- coverVariable = (coverVariable & (PRIVATE_MASK | CHECKBOX_MASK)) | (i & PUBLIC_MASK);
- fBox.setText(Integer.toString(coverVariable & PUBLIC_MASK));
- GT_Values.NW.sendToServer(new GT_Packet_TileEntityCover(side, coverID, coverVariable, tile));
+ coverVariable = tCheckBoxValue | tPublicChannel;
+
+ fBox.setText(Integer.toString(tPublicChannel));
+ GT_Values.NW.sendToServer(new GT_Packet_WirelessRedstoneCover(side, coverID, coverVariable, tile, tPublicChannel, tCheckBoxValue));
}
@Override
public void resetTextBox(GT_GuiIntegerTextBox box) {
- box.setText(String.valueOf(coverVariable & PUBLIC_MASK));
+ box.setText(String.valueOf(0));
}
@Override
@@ -226,25 +232,18 @@ public abstract class GT_Cover_RedstoneWirelessBase extends GT_CoverBehavior {
tBtn.setChecked(!tBtn.isChecked());
- if (tBtn.isChecked()) {
- //set bit 16
- coverVariable = coverVariable | CHECKBOX_MASK;
- }
- else {
- //un-set bit 16
- coverVariable = coverVariable & ~CHECKBOX_MASK;
- }
+ int tPublicChannel = 0;
+ String tText = fBox.getText().trim();
- if ((coverVariable & CHECKBOX_MASK) > 0) {
- //clear out upper 15 bits and replace them with the upper 15 bits of the hashed player name
- coverVariable = (coverVariable & (PUBLIC_MASK | CHECKBOX_MASK)) | (lastPlayer.getUniqueID().hashCode() & PRIVATE_MASK);
- }
- else {
- //clear out upper 16 bits
- coverVariable = coverVariable & PUBLIC_MASK;
+ if (tText.length() > 0) {
+ tPublicChannel = Integer.parseInt(tText);
}
- GT_Values.NW.sendToServer(new GT_Packet_TileEntityCover(side, coverID, coverVariable, tile));
+ int tCheckBoxValue = tBtn.isChecked() ? CHECKBOX_MASK : 0;
+
+ coverVariable = tCheckBoxValue | tPublicChannel;
+
+ GT_Values.NW.sendToServer(new GT_Packet_WirelessRedstoneCover(side, coverID, coverVariable, tile, tPublicChannel, tCheckBoxValue));
}
private class GT_GuiShortTextBox extends GT_GuiIntegerTextBox {
@@ -255,17 +254,16 @@ public abstract class GT_Cover_RedstoneWirelessBase extends GT_CoverBehavior {
@Override
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) {
+ String tText = getText().trim();
+ if (tText.length() > 0) {
try {
- tValue = Integer.parseInt(newText);
+ tValue = Integer.parseInt(tText);
} catch (NumberFormatException ignored) {}
if (tValue > MAX_CHANNEL)