aboutsummaryrefslogtreecommitdiff
path: root/goodgen/src/main/java/goodgenerator/network
diff options
context:
space:
mode:
authorRaven Szewczyk <git@eigenraven.me>2024-05-25 14:09:28 +0100
committerRaven Szewczyk <git@eigenraven.me>2024-05-25 14:09:28 +0100
commita7e6e9fa443440063e2a0b9b7b017852d4e023ee (patch)
tree35a05b74d32420c6be83810ebafec8d88092d9a3 /goodgen/src/main/java/goodgenerator/network
parent13d47567b6b1103647e5a819e601b426911bb89d (diff)
parent84481c22d7d4e0834de97a150d257ce6e85ad690 (diff)
downloadGT5-Unofficial-a7e6e9fa443440063e2a0b9b7b017852d4e023ee.tar.gz
GT5-Unofficial-a7e6e9fa443440063e2a0b9b7b017852d4e023ee.tar.bz2
GT5-Unofficial-a7e6e9fa443440063e2a0b9b7b017852d4e023ee.zip
Merge in GoodGenerator with history
git-subtree-dir: goodgen git-subtree-mainline: 13d47567b6b1103647e5a819e601b426911bb89d git-subtree-split: 84481c22d7d4e0834de97a150d257ce6e85ad690
Diffstat (limited to 'goodgen/src/main/java/goodgenerator/network')
-rw-r--r--goodgen/src/main/java/goodgenerator/network/MessageMTEBase.java88
1 files changed, 88 insertions, 0 deletions
diff --git a/goodgen/src/main/java/goodgenerator/network/MessageMTEBase.java b/goodgen/src/main/java/goodgenerator/network/MessageMTEBase.java
new file mode 100644
index 0000000000..4a9982d8d8
--- /dev/null
+++ b/goodgen/src/main/java/goodgenerator/network/MessageMTEBase.java
@@ -0,0 +1,88 @@
+/*
+ * 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 net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.World;
+import net.minecraftforge.common.DimensionManager;
+
+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;
+
+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 abstract static 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);
+ }
+ }
+}