mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-11 15:57:55 +00:00
Correct split client-server code
This commit is contained in:
1 parent
db8aee2c25
commit
6e96cba6fe
7 files changed
+84
-37
No files matched your search
@@ -318,19 +318,18 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public GuiType getOriginalGui() {
|
||||
return originalGui;
|
||||
}
|
||||
|
||||
public void switchGui() {
|
||||
FluidCraft.proxy.netHandler.sendToServer(
|
||||
new CPacketLevelTerminalCommands(
|
||||
CPacketLevelTerminalCommands.Action.BACK,
|
||||
originalBlockPos.x,
|
||||
originalBlockPos.y,
|
||||
originalBlockPos.z,
|
||||
originalBlockPos.getDimension(),
|
||||
originalBlockPos.getSide()));
|
||||
CPacketLevelTerminalCommands message = new CPacketLevelTerminalCommands(
|
||||
CPacketLevelTerminalCommands.Action.BACK,
|
||||
originalBlockPos.x,
|
||||
originalBlockPos.y,
|
||||
originalBlockPos.z,
|
||||
originalBlockPos.getDimension(),
|
||||
originalBlockPos.getSide());
|
||||
if (originalGui != null) {
|
||||
message.setOriginalGui(originalGui.ordinal());
|
||||
}
|
||||
FluidCraft.proxy.netHandler.sendToServer(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,6 +35,8 @@ public class GuiRenamer extends AEBaseGui implements IDropToFillTextField {
|
||||
|
||||
protected ItemStack icon = null;
|
||||
|
||||
protected GuiType originalGui;
|
||||
|
||||
public GuiRenamer(InventoryPlayer ip, ITerminalHost monitorable) {
|
||||
super(new ContainerRenamer(ip, monitorable));
|
||||
this.host = monitorable;
|
||||
@@ -51,12 +53,16 @@ public class GuiRenamer extends AEBaseGui implements IDropToFillTextField {
|
||||
FluidCraft.proxy.netHandler.sendToServer(new CPacketRenamer(CPacketRenamer.Action.GET_TEXT));
|
||||
if (host instanceof PartLevelTerminal) {
|
||||
icon = ItemAndBlockHolder.LEVEL_TERMINAL.stack();
|
||||
originalGui = GuiType.LEVEL_TERMINAL;
|
||||
} else if (host instanceof IWirelessTerminal terminal && terminal.isUniversal(host)) {
|
||||
icon = ItemAndBlockHolder.WIRELESS_ULTRA_TERM.stack();
|
||||
originalGui = ItemWirelessUltraTerminal.readMode(terminal.getItemStack());
|
||||
} else if (host instanceof WirelessLevelTerminalInventory) {
|
||||
icon = ItemAndBlockHolder.WIRELESS_LEVEL_TERM.stack();
|
||||
originalGui = GuiType.WIRELESS_LEVEL_TERMINAL;
|
||||
} else if (host instanceof WirelessInterfaceTerminalInventory) {
|
||||
icon = ItemAndBlockHolder.WIRELESS_INTERFACE_TERM.stack();
|
||||
originalGui = GuiType.WIRELESS_INTERFACE_TERMINAL;
|
||||
}
|
||||
if (this.icon != null) {
|
||||
this.buttonList.add(
|
||||
@@ -114,13 +120,9 @@ public class GuiRenamer extends AEBaseGui implements IDropToFillTextField {
|
||||
}
|
||||
|
||||
public void switchGui() {
|
||||
if (host instanceof PartLevelTerminal) InventoryHandler.switchGui(GuiType.LEVEL_TERMINAL);
|
||||
else if (host instanceof IWirelessTerminal terminal && terminal.isUniversal(host))
|
||||
InventoryHandler.switchGui(ItemWirelessUltraTerminal.readMode(terminal.getItemStack()));
|
||||
else if (host instanceof WirelessInterfaceTerminalInventory)
|
||||
InventoryHandler.switchGui(GuiType.WIRELESS_INTERFACE_TERMINAL);
|
||||
else if (host instanceof WirelessLevelTerminalInventory)
|
||||
InventoryHandler.switchGui(GuiType.WIRELESS_LEVEL_TERMINAL);
|
||||
if (originalGui != null) {
|
||||
InventoryHandler.switchGui(originalGui);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTextFieldValue(final String displayName, final int mousex, final int mousey, final ItemStack stack) {
|
||||
|
||||
@@ -348,7 +348,8 @@ public class TileLevelMaintainer extends AENetworkTile
|
||||
}
|
||||
|
||||
private ItemStack removeRecursion(ItemStack itemStack) {
|
||||
if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey(TLMTags.Stack.tagName)) {
|
||||
if (itemStack != null && itemStack.hasTagCompound()
|
||||
&& itemStack.getTagCompound().hasKey(TLMTags.Stack.tagName)) {
|
||||
return removeRecursion(loadItemStackFromTag(itemStack));
|
||||
}
|
||||
return itemStack;
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.glodblock.github.network.SPacketMEFluidInvUpdate;
|
||||
import com.glodblock.github.network.SPacketMEItemInvUpdate;
|
||||
import com.glodblock.github.network.SPacketSetItemAmount;
|
||||
import com.glodblock.github.network.SPacketStringUpdate;
|
||||
import com.glodblock.github.network.SPacketSwitchBack;
|
||||
import com.glodblock.github.network.wrapper.FCNetworkWrapper;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -66,6 +67,7 @@ public class ChannelLoader implements Runnable {
|
||||
netHandler.registerMessage(new SPacketSetItemAmount.Handler(), SPacketSetItemAmount.class, id++, Side.CLIENT);
|
||||
netHandler.registerMessage(new CPacketRenamer.Handler(), CPacketRenamer.class, id++, Side.SERVER);
|
||||
netHandler.registerMessage(new SPacketStringUpdate.Handler(), SPacketStringUpdate.class, id++, Side.CLIENT);
|
||||
netHandler.registerMessage(new SPacketSwitchBack.Handler(), SPacketSwitchBack.class, id++, Side.CLIENT);
|
||||
netHandler.registerMessage(
|
||||
new SPacketLevelTerminalUpdate.Handler(),
|
||||
SPacketLevelTerminalUpdate.class,
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.glodblock.github.client.gui.GuiLevelMaintainer;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.inventory.item.IClickableInTerminal;
|
||||
@@ -28,6 +25,7 @@ public class CPacketLevelTerminalCommands implements IMessage {
|
||||
private int z;
|
||||
private int dim;
|
||||
private ForgeDirection side;
|
||||
private int originalGui = -1;
|
||||
|
||||
public enum Action {
|
||||
EDIT,
|
||||
@@ -49,17 +47,30 @@ public class CPacketLevelTerminalCommands implements IMessage {
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
public CPacketLevelTerminalCommands setOriginalGui(int originalGui) {
|
||||
this.originalGui = originalGui;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
action = Action.values()[buf.readInt()];
|
||||
switch (action) {
|
||||
case EDIT, BACK -> {
|
||||
case EDIT -> {
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
dim = buf.readInt();
|
||||
side = ForgeDirection.getOrientation(buf.readInt());
|
||||
}
|
||||
case BACK -> {
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
dim = buf.readInt();
|
||||
side = ForgeDirection.getOrientation(buf.readInt());
|
||||
originalGui = buf.readInt();
|
||||
}
|
||||
case ENABLE -> {}
|
||||
case DISABLE -> {}
|
||||
case ENABLE_ALL -> {}
|
||||
@@ -71,13 +82,21 @@ public class CPacketLevelTerminalCommands implements IMessage {
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(action.ordinal());
|
||||
switch (action) {
|
||||
case EDIT, BACK -> {
|
||||
case EDIT -> {
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
buf.writeInt(dim);
|
||||
buf.writeInt(side.ordinal());
|
||||
}
|
||||
case BACK -> {
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
buf.writeInt(dim);
|
||||
buf.writeInt(side.ordinal());
|
||||
buf.writeInt(originalGui);
|
||||
}
|
||||
case ENABLE -> {}
|
||||
case DISABLE -> {}
|
||||
case ENABLE_ALL -> {}
|
||||
@@ -103,11 +122,7 @@ public class CPacketLevelTerminalCommands implements IMessage {
|
||||
GuiType.LEVEL_MAINTAINER);
|
||||
}
|
||||
case BACK -> {
|
||||
GuiType originalGui = null;
|
||||
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
|
||||
if (gs instanceof GuiLevelMaintainer guiLevelMaintainer) {
|
||||
originalGui = guiLevelMaintainer.getOriginalGui();
|
||||
}
|
||||
GuiType originalGui = GuiType.getByOrdinal(message.originalGui);
|
||||
if (originalGui == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.client.gui.GuiRenamer;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.inventory.item.IClickableInTerminal;
|
||||
@@ -179,10 +176,7 @@ public class CPacketRenamer implements IMessage {
|
||||
.getTileEntity(intMsg.x, intMsg.y, intMsg.z);
|
||||
this.setName(tile, intMsg.getSide(), message.text);
|
||||
|
||||
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
|
||||
if (gs instanceof GuiRenamer guiRenamer) {
|
||||
guiRenamer.switchGui();
|
||||
}
|
||||
FluidCraft.proxy.netHandler.sendTo(new SPacketSwitchBack(), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import com.glodblock.github.client.gui.GuiRenamer;
|
||||
|
||||
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 io.netty.buffer.ByteBuf;
|
||||
|
||||
public class SPacketSwitchBack implements IMessage {
|
||||
|
||||
public SPacketSwitchBack() {}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {}
|
||||
|
||||
public static class Handler implements IMessageHandler<SPacketSwitchBack, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(SPacketSwitchBack message, MessageContext ctx) {
|
||||
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
|
||||
if (gs instanceof GuiRenamer) {
|
||||
((GuiRenamer) gs).switchGui();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user