commit 8cda425a0d7e6466a2eaec9c8197d3f5e916dfb6
parent b7855d04c695364bafc2124bb6033c5f8158d0f8
Author: Ambos <51835548+Amb0s@users.noreply.github.com>
Date: Sat, 4 Nov 2023 16:44:34 +0100
Added multiplayer support (#12)
Diffstat:
10 files changed, 158 insertions(+), 16 deletions(-)
diff --git a/gradle.properties b/gradle.properties
@@ -7,7 +7,7 @@ bta_version=1.7.7.0_02
loader_version=0.14.19-babric.1-bta
# HalpLibe
-halplibe_version=2.1.6
+halplibe_version=2.5.0
# Mod
mod_version=0.2.0
diff --git a/src/main/java/turniplabs/simpletech/IPlayerDisplayer.java b/src/main/java/turniplabs/simpletech/IPlayerDisplayer.java
@@ -0,0 +1,7 @@
+package turniplabs.simpletech;
+
+import turniplabs.simpletech.block.entity.TileEntityAllocator;
+
+public interface IPlayerDisplayer {
+ void simple_tech$displayGUIAllocator(TileEntityAllocator allocator);
+}
diff --git a/src/main/java/turniplabs/simpletech/SimpleTech.java b/src/main/java/turniplabs/simpletech/SimpleTech.java
@@ -13,6 +13,9 @@ import org.slf4j.LoggerFactory;
import turniplabs.halplibe.helper.BlockBuilder;
import turniplabs.halplibe.helper.EntityHelper;
import turniplabs.halplibe.helper.RecipeHelper;
+import turniplabs.halplibe.util.ConfigUpdater;
+import turniplabs.halplibe.util.TomlConfigHandler;
+import turniplabs.halplibe.util.toml.Toml;
import turniplabs.simpletech.block.*;
import turniplabs.simpletech.block.entity.TileEntityAllocator;
import turniplabs.simpletech.block.entity.TileEntityFan;
@@ -21,13 +24,42 @@ import turniplabs.simpletech.block.entity.TileEntityLightSensor;
public class SimpleTech implements ModInitializer {
public static final String MOD_ID = "simpletech";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
- public static final int FAN_RANGE = 4;
- public static final int UNPOWERED_FAN_ID = 3789;
- public static final int POWERED_FAN_ID = 3790;
- public static final int JUMP_PAD_ID = 3791;
- public static final int TRAPPED_CHEST_ID = 3792;
- public static final int LIGHT_SENSOR_ID = 3793;
- public static final int ALLOCATOR_ID = 3794;
+ public static final TomlConfigHandler config;
+ public static final int FAN_RANGE;
+ public static final int UNPOWERED_FAN_ID;
+ public static final int POWERED_FAN_ID;
+ public static final int JUMP_PAD_ID;
+ public static final int TRAPPED_CHEST_ID;
+ public static final int LIGHT_SENSOR_ID;
+ public static final int ALLOCATOR_ID;
+ public static final int ALLOCATOR_GUI_ID;
+ static {
+ Toml configToml = new Toml();
+ configToml.addCategory("BlockIDs");
+ configToml.addEntry("BlockIDs.UNPOWERED_FAN_ID", 3789);
+ configToml.addEntry("BlockIDs.POWERED_FAN_ID", 3790);
+ configToml.addEntry("BlockIDs.JUMP_PAD_ID", 3791);
+ configToml.addEntry("BlockIDs.TRAPPED_CHEST_ID", 3792);
+ configToml.addEntry("BlockIDs.LIGHT_SENSOR_ID", 3793);
+ configToml.addEntry("BlockIDs.ALLOCATOR_ID", 3794);
+ configToml.addCategory("Settings");
+ configToml.addEntry("Settings.FAN_RANGE", 4);
+ configToml.addCategory("GUI");
+ configToml.addEntry("GUI.ALLOCATOR_GUI_ID", 13);
+ ConfigUpdater stupidDesignDecision = new ConfigUpdater() {public void update() {}};
+
+
+ config = new TomlConfigHandler(stupidDesignDecision, MOD_ID, configToml);
+ FAN_RANGE = config.getInt("Settings.FAN_RANGE");
+ UNPOWERED_FAN_ID = config.getInt("BlockIDs.UNPOWERED_FAN_ID");
+ POWERED_FAN_ID = config.getInt("BlockIDs.POWERED_FAN_ID");
+ JUMP_PAD_ID = config.getInt("BlockIDs.JUMP_PAD_ID");
+ TRAPPED_CHEST_ID = config.getInt("BlockIDs.TRAPPED_CHEST_ID");
+ LIGHT_SENSOR_ID = config.getInt("BlockIDs.LIGHT_SENSOR_ID");
+ ALLOCATOR_ID = config.getInt("BlockIDs.ALLOCATOR_ID");
+ ALLOCATOR_GUI_ID = config.getInt("GUI.ALLOCATOR_GUI_ID");
+ }
+
// Builders
public static final BlockBuilder stoneBlockBuilder = new BlockBuilder(MOD_ID)
diff --git a/src/main/java/turniplabs/simpletech/block/BlockAllocator.java b/src/main/java/turniplabs/simpletech/block/BlockAllocator.java
@@ -1,6 +1,5 @@
package turniplabs.simpletech.block;
-import net.minecraft.client.Minecraft;
import net.minecraft.core.block.Block;
import net.minecraft.core.block.BlockTileEntity;
import net.minecraft.core.block.entity.TileEntity;
@@ -20,7 +19,7 @@ import net.minecraft.core.util.helper.Direction;
import net.minecraft.core.util.helper.Side;
import net.minecraft.core.util.phys.AABB;
import net.minecraft.core.world.World;
-import turniplabs.simpletech.gui.GuiAllocator;
+import turniplabs.simpletech.IPlayerDisplayer;
import turniplabs.simpletech.SimpleTech;
import turniplabs.simpletech.block.entity.TileEntityAllocator;
@@ -50,11 +49,7 @@ public class BlockAllocator extends BlockTileEntity {
return true;
} else {
TileEntityAllocator allocator = (TileEntityAllocator) world.getBlockTileEntity(x, y, z);
-
- if (allocator != null) {
- Minecraft.getMinecraft(Minecraft.class).displayGuiScreen(new GuiAllocator(player.inventory, allocator));
- }
-
+ ((IPlayerDisplayer)player).simple_tech$displayGUIAllocator(allocator);
return true;
}
}
diff --git a/src/main/java/turniplabs/simpletech/gui/GuiAllocator.java b/src/main/java/turniplabs/simpletech/gui/GuiAllocator.java
@@ -7,7 +7,7 @@ import turniplabs.simpletech.block.entity.TileEntityAllocator;
import turniplabs.simpletech.player.inventory.ContainerAllocator;
public class GuiAllocator extends GuiContainer {
- private TileEntityAllocator allocatorInv;
+ private final TileEntityAllocator allocatorInv;
public GuiAllocator(InventoryPlayer playerInventory, TileEntityAllocator allocator) {
super(new ContainerAllocator(playerInventory, allocator));
diff --git a/src/main/java/turniplabs/simpletech/mixin/EntityPlayerMPMixin.java b/src/main/java/turniplabs/simpletech/mixin/EntityPlayerMPMixin.java
@@ -0,0 +1,35 @@
+package turniplabs.simpletech.mixin;
+
+import net.minecraft.core.entity.player.EntityPlayer;
+import net.minecraft.core.net.packet.Packet100OpenWindow;
+import net.minecraft.core.world.World;
+import net.minecraft.server.entity.player.EntityPlayerMP;
+import net.minecraft.server.net.handler.NetServerHandler;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import turniplabs.simpletech.IPlayerDisplayer;
+import turniplabs.simpletech.SimpleTech;
+import turniplabs.simpletech.block.entity.TileEntityAllocator;
+import turniplabs.simpletech.player.inventory.ContainerAllocator;
+
+@Mixin(value = EntityPlayerMP.class, remap = false)
+public abstract class EntityPlayerMPMixin extends EntityPlayer implements IPlayerDisplayer {
+ @Shadow protected abstract void getNextWindowId();
+
+ @Shadow public NetServerHandler playerNetServerHandler;
+
+ @Shadow private int currentWindowId;
+
+ public EntityPlayerMPMixin(World world) {
+ super(world);
+ }
+
+ @Override
+ public void simple_tech$displayGUIAllocator(TileEntityAllocator allocator) {
+ this.getNextWindowId();
+ this.playerNetServerHandler.sendPacket(new Packet100OpenWindow(this.currentWindowId, SimpleTech.ALLOCATOR_GUI_ID, allocator.getInvName(), allocator.getSizeInventory()));
+ this.craftingInventory = new ContainerAllocator(this.inventory, allocator);
+ this.craftingInventory.windowId = this.currentWindowId;
+ this.craftingInventory.onContainerInit((EntityPlayerMP)(Object)this);
+ }
+}
diff --git a/src/main/java/turniplabs/simpletech/mixin/EntityPlayerMixin.java b/src/main/java/turniplabs/simpletech/mixin/EntityPlayerMixin.java
@@ -0,0 +1,14 @@
+package turniplabs.simpletech.mixin;
+
+import net.minecraft.core.entity.player.EntityPlayer;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Unique;
+import turniplabs.simpletech.IPlayerDisplayer;
+import turniplabs.simpletech.block.entity.TileEntityAllocator;
+
+@Mixin(value = EntityPlayer.class, remap = false)
+public class EntityPlayerMixin implements IPlayerDisplayer {
+ @Unique
+ public void simple_tech$displayGUIAllocator(TileEntityAllocator allocator) {
+ }
+}
diff --git a/src/main/java/turniplabs/simpletech/mixin/EntityPlayerSPMixin.java b/src/main/java/turniplabs/simpletech/mixin/EntityPlayerSPMixin.java
@@ -0,0 +1,27 @@
+package turniplabs.simpletech.mixin;
+
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.entity.player.EntityPlayerSP;
+import net.minecraft.core.entity.player.EntityPlayer;
+import net.minecraft.core.world.World;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import turniplabs.simpletech.IPlayerDisplayer;
+import turniplabs.simpletech.block.entity.TileEntityAllocator;
+import turniplabs.simpletech.gui.GuiAllocator;
+
+@Mixin(value = EntityPlayerSP.class, remap = false)
+public abstract class EntityPlayerSPMixin extends EntityPlayer implements IPlayerDisplayer {
+ @Shadow protected Minecraft mc;
+
+ public EntityPlayerSPMixin(World world) {
+ super(world);
+ }
+
+ @Override
+ public void simple_tech$displayGUIAllocator(TileEntityAllocator allocator) {
+ if (allocator != null){
+ this.mc.displayGuiScreen(new GuiAllocator(inventory, allocator));
+ }
+ }
+}
diff --git a/src/main/java/turniplabs/simpletech/mixin/NetClientHandlerMixin.java b/src/main/java/turniplabs/simpletech/mixin/NetClientHandlerMixin.java
@@ -0,0 +1,28 @@
+package turniplabs.simpletech.mixin;
+
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.net.handler.NetClientHandler;
+import net.minecraft.core.net.packet.Packet100OpenWindow;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+import turniplabs.simpletech.IPlayerDisplayer;
+import turniplabs.simpletech.SimpleTech;
+import turniplabs.simpletech.block.entity.TileEntityAllocator;
+
+@Mixin(value = NetClientHandler.class, remap = false)
+public class NetClientHandlerMixin {
+ @Shadow private Minecraft mc;
+
+ @Inject(method = "handleOpenWindow(Lnet/minecraft/core/net/packet/Packet100OpenWindow;)V", at = @At("HEAD"), cancellable = true)
+ public void handleAllocator(Packet100OpenWindow packet100openwindow, CallbackInfo ci){
+ if (packet100openwindow.inventoryType == SimpleTech.ALLOCATOR_GUI_ID) {
+ TileEntityAllocator tileEntityAllocator = new TileEntityAllocator();
+ ((IPlayerDisplayer)this.mc.thePlayer).simple_tech$displayGUIAllocator(tileEntityAllocator);
+ this.mc.thePlayer.craftingInventory.windowId = packet100openwindow.windowId;
+ ci.cancel();
+ }
+ }
+}
diff --git a/src/main/resources/simpletech.mixins.json b/src/main/resources/simpletech.mixins.json
@@ -5,7 +5,11 @@
"compatibilityLevel": "JAVA_8",
"mixins": [
"EntityItemMixin",
+ "EntityPlayerMixin",
+ "EntityPlayerMPMixin",
+ "EntityPlayerSPMixin",
"MinecraftMixin",
+ "NetClientHandlerMixin",
"RenderBlocksMixin"
],
"client": [