aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlodBlock <60341015+GlodBlock@users.noreply.github.com>2021-08-17 10:51:56 +0800
committerGitHub <noreply@github.com>2021-08-17 10:51:56 +0800
commit0734e08309d0475441d2c60170272b67307aa0c3 (patch)
tree63bc6e4c9e4d7e2404937d05214cf5939bb7590e
parentb00aebd72df14381b08639d86d65a04439289302 (diff)
parent5fd50a358464907982a696b977a17e14227b44aa (diff)
downloadGT5-Unofficial-0734e08309d0475441d2c60170272b67307aa0c3.tar.gz
GT5-Unofficial-0734e08309d0475441d2c60170272b67307aa0c3.tar.bz2
GT5-Unofficial-0734e08309d0475441d2c60170272b67307aa0c3.zip
Merge pull request #7 from GTNewHorizons/neutron-sensor-gui-sync
Fix NeutronSensor GUI sync
-rw-r--r--src/main/java/GoodGenerator/Blocks/TEs/MetaTE/NeutronSensor.java13
-rw-r--r--src/main/java/GoodGenerator/Client/GUI/NeutronSensorGUIClient.java6
-rw-r--r--src/main/java/GoodGenerator/Main/GoodGenerator.java11
-rw-r--r--src/main/java/GoodGenerator/Network/MessageMTEBase.java98
-rw-r--r--src/main/java/GoodGenerator/Network/MessageOpenNeutronSensorGUI.java50
-rw-r--r--src/main/java/GoodGenerator/Network/MessageSetNeutronSensorData.java52
6 files changed, 223 insertions, 7 deletions
diff --git a/src/main/java/GoodGenerator/Blocks/TEs/MetaTE/NeutronSensor.java b/src/main/java/GoodGenerator/Blocks/TEs/MetaTE/NeutronSensor.java
index 0c9071671e..137173711c 100644
--- a/src/main/java/GoodGenerator/Blocks/TEs/MetaTE/NeutronSensor.java
+++ b/src/main/java/GoodGenerator/Blocks/TEs/MetaTE/NeutronSensor.java
@@ -3,6 +3,7 @@ package GoodGenerator.Blocks.TEs.MetaTE;
import GoodGenerator.Client.GUI.NeutronSensorGUIClient;
import GoodGenerator.Common.Container.NeutronSensorGUIContainer;
import GoodGenerator.Main.GoodGenerator;
+import GoodGenerator.Network.MessageOpenNeutronSensorGUI;
import gregtech.api.enums.Textures;
import gregtech.api.interfaces.IIconContainer;
import gregtech.api.interfaces.ITexture;
@@ -12,6 +13,7 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GT_Log;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -56,7 +58,6 @@ public class NeutronSensor extends GT_MetaTileEntity_Hatch {
@Override
public void initDefaultModes(NBTTagCompound aNBT) {
getBaseMetaTileEntity().setActive(true);
- texts = aNBT.getString("mBoxContext");
}
@Override
@@ -81,7 +82,6 @@ public class NeutronSensor extends GT_MetaTileEntity_Hatch {
@Override
public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) {
- GT_Log.out.print(texts + "\n");
return new NeutronSensorGUIClient(aPlayerInventory, aBaseMetaTileEntity, GoodGenerator.MOD_ID + ":textures/gui/NeutronSensorGUI.png", this.texts);
}
@@ -93,12 +93,15 @@ public class NeutronSensor extends GT_MetaTileEntity_Hatch {
@Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) {
if (aBaseMetaTileEntity.isClientSide()) return true;
- if (aSide == aBaseMetaTileEntity.getFrontFacing()) aBaseMetaTileEntity.openGUI(aPlayer);
- return true;
+ if (aSide == aBaseMetaTileEntity.getFrontFacing() && aPlayer instanceof EntityPlayerMP) {
+ GoodGenerator.CHANNEL.sendTo(new MessageOpenNeutronSensorGUI(aBaseMetaTileEntity, texts), (EntityPlayerMP) aPlayer);
+ return true;
+ }
+ return false;
}
public void setText(String text) {
- texts = text;
+ texts = text == null ? "" : text;
}
@Override
diff --git a/src/main/java/GoodGenerator/Client/GUI/NeutronSensorGUIClient.java b/src/main/java/GoodGenerator/Client/GUI/NeutronSensorGUIClient.java
index b80f1d7d90..5be9b180de 100644
--- a/src/main/java/GoodGenerator/Client/GUI/NeutronSensorGUIClient.java
+++ b/src/main/java/GoodGenerator/Client/GUI/NeutronSensorGUIClient.java
@@ -1,7 +1,7 @@
package GoodGenerator.Client.GUI;
-import GoodGenerator.Blocks.TEs.MetaTE.NeutronSensor;
import GoodGenerator.Main.GoodGenerator;
+import GoodGenerator.Network.MessageSetNeutronSensorData;
import GoodGenerator.util.CharExchanger;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -79,8 +79,10 @@ public class NeutronSensorGUIClient extends GT_GUIContainerMetaTile_Machine {
this.TextBox.mouseClicked(x - this.getLeft(), y - this.getTop(), btn);
}
+ @Override
public void onGuiClosed() {
- ((NeutronSensor) mTile).setText(context);
+ if (CharExchanger.isValidCompareExpress(rawProcessExp(TextBox.getText())))
+ GoodGenerator.CHANNEL.sendToServer(new MessageSetNeutronSensorData(mContainer.mTileEntity, TextBox.getText()));
super.onGuiClosed();
}
diff --git a/src/main/java/GoodGenerator/Main/GoodGenerator.java b/src/main/java/GoodGenerator/Main/GoodGenerator.java
index 2832075878..6c3a7f7b8c 100644
--- a/src/main/java/GoodGenerator/Main/GoodGenerator.java
+++ b/src/main/java/GoodGenerator/Main/GoodGenerator.java
@@ -6,6 +6,8 @@ import GoodGenerator.Items.MyMaterial;
import GoodGenerator.Loader.FuelRecipeLoader;
import GoodGenerator.Loader.Loaders;
import GoodGenerator.Loader.RecipeLoader;
+import GoodGenerator.Network.MessageOpenNeutronSensorGUI;
+import GoodGenerator.Network.MessageSetNeutronSensorData;
import GoodGenerator.Tabs.MyTabs;
import GoodGenerator.Blocks.MyFluids.FluidsBuilder;
import com.github.bartimaeusnek.bartworks.API.WerkstoffAdderRegistry;
@@ -13,6 +15,9 @@ import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
+import cpw.mods.fml.common.network.NetworkRegistry;
+import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
+import cpw.mods.fml.relauncher.Side;
import net.minecraft.creativetab.CreativeTabs;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent;
@@ -34,6 +39,12 @@ public final class GoodGenerator {
@SidedProxy(clientSide = "GoodGenerator.Client.ClientProxy",serverSide = "GoodGenerator.Common.CommonProxy")
public static CommonProxy proxy;
+ public static SimpleNetworkWrapper CHANNEL = NetworkRegistry.INSTANCE.newSimpleChannel(MOD_ID);
+
+ static {
+ CHANNEL.registerMessage(MessageSetNeutronSensorData.ServerHandler.class, MessageSetNeutronSensorData.class, 0, Side.SERVER);
+ CHANNEL.registerMessage(MessageOpenNeutronSensorGUI.ClientHandler.class, MessageOpenNeutronSensorGUI.class, 1, Side.CLIENT);
+ }
@Mod.Instance(GoodGenerator.MOD_ID)
public static GoodGenerator instance;
diff --git a/src/main/java/GoodGenerator/Network/MessageMTEBase.java b/src/main/java/GoodGenerator/Network/MessageMTEBase.java
new file mode 100644
index 0000000000..e54249e545
--- /dev/null
+++ b/src/main/java/GoodGenerator/Network/MessageMTEBase.java
@@ -0,0 +1,98 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2021 Glease
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package GoodGenerator.Network;
+
+import com.github.technus.tectech.TecTech;
+import cpw.mods.fml.common.network.simpleimpl.IMessage;
+import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
+import cpw.mods.fml.common.network.simpleimpl.MessageContext;
+import cpw.mods.fml.relauncher.Side;
+import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import io.netty.buffer.ByteBuf;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.World;
+import net.minecraftforge.common.DimensionManager;
+
+public abstract class MessageMTEBase implements IMessage {
+ protected int w;
+ protected int x;
+ protected short y;
+ protected int z;
+
+ public MessageMTEBase() {
+ }
+
+ public MessageMTEBase(IGregTechTileEntity tile) {
+ this.w = tile.getWorld().provider.dimensionId;
+ this.x = tile.getXCoord();
+ this.y = tile.getYCoord();
+ this.z = tile.getZCoord();
+ }
+
+ @Override
+ public void fromBytes(ByteBuf buf) {
+ x = buf.readInt();
+ y = buf.readShort();
+ z = buf.readInt();
+ w = buf.readInt();
+ }
+
+ @Override
+ public void toBytes(ByteBuf buf) {
+ buf.writeInt(x);
+ buf.writeShort(y);
+ buf.writeInt(z);
+ buf.writeInt(w);
+ }
+
+ public static abstract class Handler<REQ extends MessageMTEBase, REPLY extends IMessage> implements IMessageHandler<REQ, REPLY> {
+ protected abstract REPLY onError(REQ message, MessageContext ctx);
+
+ protected abstract REPLY onSuccess(REQ message, MessageContext ctx, IMetaTileEntity mte);
+
+ @Override
+ public REPLY onMessage(REQ message, MessageContext ctx) {
+ World world;
+ if (ctx.side == Side.SERVER) {
+ world = DimensionManager.getWorld(message.w);
+ } else {
+ world = TecTech.proxy.getClientWorld();
+ if (world.provider.dimensionId != message.w)
+ return onError(message, ctx);
+ }
+ if (world == null)
+ return onError(message, ctx);
+ if (world.blockExists(message.x, message.y, message.z)) {
+ TileEntity te = world.getTileEntity(message.x, message.y, message.z);
+ if (te instanceof IGregTechTileEntity && !((IGregTechTileEntity) te).isInvalidTileEntity()) {
+ IMetaTileEntity mte = ((IGregTechTileEntity) te).getMetaTileEntity();
+ if (mte != null)
+ return onSuccess(message, ctx, mte);
+ }
+ }
+ return onError(message, ctx);
+ }
+ }
+}
diff --git a/src/main/java/GoodGenerator/Network/MessageOpenNeutronSensorGUI.java b/src/main/java/GoodGenerator/Network/MessageOpenNeutronSensorGUI.java
new file mode 100644
index 0000000000..0b3c045ece
--- /dev/null
+++ b/src/main/java/GoodGenerator/Network/MessageOpenNeutronSensorGUI.java
@@ -0,0 +1,50 @@
+package GoodGenerator.Network;
+
+import GoodGenerator.Blocks.TEs.MetaTE.NeutronSensor;
+import com.github.technus.tectech.TecTech;
+import cpw.mods.fml.common.network.ByteBufUtils;
+import cpw.mods.fml.common.network.simpleimpl.IMessage;
+import cpw.mods.fml.common.network.simpleimpl.MessageContext;
+import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import io.netty.buffer.ByteBuf;
+
+public class MessageOpenNeutronSensorGUI extends MessageMTEBase {
+ protected String data;
+
+ public MessageOpenNeutronSensorGUI() {
+ }
+
+ public MessageOpenNeutronSensorGUI(IGregTechTileEntity tile, String data) {
+ super(tile);
+ this.data = data;
+ }
+
+ @Override
+ public void fromBytes(ByteBuf buf) {
+ super.fromBytes(buf);
+ data = ByteBufUtils.readUTF8String(buf);
+ }
+
+ @Override
+ public void toBytes(ByteBuf buf) {
+ super.toBytes(buf);
+ ByteBufUtils.writeUTF8String(buf, data);
+ }
+
+ public static class ClientHandler extends MessageMTEBase.Handler<MessageOpenNeutronSensorGUI, IMessage> {
+ @Override
+ protected IMessage onError(MessageOpenNeutronSensorGUI message, MessageContext ctx) {
+ return null;
+ }
+
+ @Override
+ protected IMessage onSuccess(MessageOpenNeutronSensorGUI message, MessageContext ctx, IMetaTileEntity mte) {
+ if (mte instanceof NeutronSensor) {
+ ((NeutronSensor) mte).setText(message.data);
+ mte.getBaseMetaTileEntity().openGUI(TecTech.proxy.getPlayer());
+ }
+ return null;
+ }
+ }
+}
diff --git a/src/main/java/GoodGenerator/Network/MessageSetNeutronSensorData.java b/src/main/java/GoodGenerator/Network/MessageSetNeutronSensorData.java
new file mode 100644
index 0000000000..39d08d92c3
--- /dev/null
+++ b/src/main/java/GoodGenerator/Network/MessageSetNeutronSensorData.java
@@ -0,0 +1,52 @@
+package GoodGenerator.Network;
+
+import GoodGenerator.Blocks.TEs.MetaTE.NeutronSensor;
+import com.github.technus.tectech.TecTech;
+import cpw.mods.fml.common.network.ByteBufUtils;
+import cpw.mods.fml.common.network.simpleimpl.IMessage;
+import cpw.mods.fml.common.network.simpleimpl.MessageContext;
+import cpw.mods.fml.relauncher.Side;
+import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import io.netty.buffer.ByteBuf;
+
+public class MessageSetNeutronSensorData extends MessageMTEBase {
+ protected String data;
+
+ public MessageSetNeutronSensorData() {
+ }
+
+ public MessageSetNeutronSensorData(IGregTechTileEntity tile, String data) {
+ super(tile);
+ this.data = data;
+ }
+
+ @Override
+ public void fromBytes(ByteBuf buf) {
+ super.fromBytes(buf);
+ data = ByteBufUtils.readUTF8String(buf);
+ }
+
+ @Override
+ public void toBytes(ByteBuf buf) {
+ super.toBytes(buf);
+ ByteBufUtils.writeUTF8String(buf, data);
+ }
+
+ public static class ServerHandler extends MessageMTEBase.Handler<MessageSetNeutronSensorData, IMessage> {
+ @Override
+ protected IMessage onError(MessageSetNeutronSensorData message, MessageContext ctx) {
+ return null;
+ }
+
+ @Override
+ protected IMessage onSuccess(MessageSetNeutronSensorData message, MessageContext ctx, IMetaTileEntity mte) {
+ if (mte instanceof NeutronSensor) {
+ ((NeutronSensor) mte).setText(message.data);
+ if (ctx.side == Side.CLIENT)
+ mte.getBaseMetaTileEntity().openGUI(TecTech.proxy.getPlayer());
+ }
+ return null;
+ }
+ }
+}