mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-16 10:34:40 +00:00
Add GUI update packet
This commit is contained in:
4 files changed
+126
-4
No files matched your search
@@ -159,6 +159,8 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
|
||||
this.originalGuiBtn.setHideEdge(13);
|
||||
this.buttonList.add(originalGuiBtn);
|
||||
}
|
||||
|
||||
FluidCraft.proxy.netHandler.sendToServer(new CPacketLevelMaintainer());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -344,6 +346,16 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void updateComponent(int index, long quantity, long batchSize, boolean isEnabled, LevelState state) {
|
||||
if (index < 0 || index >= TileLevelMaintainer.REQ_COUNT) return;
|
||||
component[index].setEnable(isEnabled);
|
||||
component[index].setState(state);
|
||||
component[index].getQty().textField.setText(String.valueOf(quantity));
|
||||
component[index].getBatch().textField.setText(String.valueOf(batchSize));
|
||||
component[index].getQty().validate();
|
||||
component[index].getBatch().validate();
|
||||
}
|
||||
|
||||
private class Component {
|
||||
|
||||
public boolean isEnable = true;
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.glodblock.github.network.CPacketSwitchGuis;
|
||||
import com.glodblock.github.network.CPacketTransferRecipe;
|
||||
import com.glodblock.github.network.CPacketValueConfig;
|
||||
import com.glodblock.github.network.SPacketFluidUpdate;
|
||||
import com.glodblock.github.network.SPacketLevelMaintainerGuiUpdate;
|
||||
import com.glodblock.github.network.SPacketLevelTerminalUpdate;
|
||||
import com.glodblock.github.network.SPacketMEFluidInvUpdate;
|
||||
import com.glodblock.github.network.SPacketMEItemInvUpdate;
|
||||
@@ -87,6 +88,11 @@ public class ChannelLoader implements Runnable {
|
||||
SPacketPatternItemRenamer.class,
|
||||
id++,
|
||||
Side.SERVER);
|
||||
netHandler.registerMessage(
|
||||
new SPacketLevelMaintainerGuiUpdate.Handler(),
|
||||
SPacketLevelMaintainerGuiUpdate.class,
|
||||
id++,
|
||||
Side.CLIENT);
|
||||
}
|
||||
|
||||
public static void sendPacketToAllPlayers(Packet packet, World world) {
|
||||
|
||||
@@ -2,9 +2,9 @@ package com.glodblock.github.network;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.client.gui.container.ContainerLevelMaintainer;
|
||||
|
||||
import appeng.helpers.Reflected;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
@@ -16,15 +16,19 @@ public class CPacketLevelMaintainer implements IMessage {
|
||||
Quantity,
|
||||
Batch,
|
||||
Enable,
|
||||
Disable
|
||||
Disable,
|
||||
UPDATE,
|
||||
}
|
||||
|
||||
private Action action;
|
||||
private long size;
|
||||
private int slotIndex;
|
||||
|
||||
@Reflected
|
||||
public CPacketLevelMaintainer() {}
|
||||
public CPacketLevelMaintainer() {
|
||||
this.action = Action.UPDATE;
|
||||
this.slotIndex = 0;
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
public CPacketLevelMaintainer(Action action, int slotIndex) {
|
||||
this.action = action;
|
||||
@@ -63,6 +67,7 @@ public class CPacketLevelMaintainer implements IMessage {
|
||||
case Batch -> clm.getTile().updateBatchSize(message.slotIndex, message.size);
|
||||
case Enable -> clm.getTile().updateStatus(message.slotIndex, false);
|
||||
case Disable -> clm.getTile().updateStatus(message.slotIndex, true);
|
||||
case UPDATE -> FluidCraft.proxy.netHandler.sendTo(new SPacketLevelMaintainerGuiUpdate(clm.getTile().requests), ctx.getServerHandler().playerEntity);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import static com.glodblock.github.common.tile.TileLevelMaintainer.REQ_COUNT;
|
||||
import static com.glodblock.github.common.tile.TileLevelMaintainer.RequestInfo;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import com.glodblock.github.api.registries.LevelState;
|
||||
import com.glodblock.github.client.gui.GuiLevelMaintainer;
|
||||
|
||||
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 SPacketLevelMaintainerGuiUpdate implements IMessage {
|
||||
|
||||
private Info[] infoList;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public SPacketLevelMaintainerGuiUpdate() {}
|
||||
|
||||
SPacketLevelMaintainerGuiUpdate(RequestInfo[] requests) {
|
||||
this.infoList = new Info[REQ_COUNT];
|
||||
for (int i = 0; i < REQ_COUNT; i++) {
|
||||
if (requests[i] == null) {
|
||||
this.infoList[i] = null;
|
||||
} else {
|
||||
this.infoList[i] = new Info(
|
||||
requests[i].getQuantity(),
|
||||
requests[i].getBatchSize(),
|
||||
requests[i].isEnable(),
|
||||
requests[i].getState());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
this.infoList = new Info[REQ_COUNT];
|
||||
for (int i = 0; i < REQ_COUNT; i++) {
|
||||
if (buf.readBoolean()) {
|
||||
this.infoList[i] = new Info(
|
||||
buf.readLong(),
|
||||
buf.readLong(),
|
||||
buf.readBoolean(),
|
||||
LevelState.values()[buf.readInt()]);
|
||||
} else {
|
||||
this.infoList[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
for (Info info : this.infoList) {
|
||||
buf.writeBoolean(info != null);
|
||||
if (info == null) continue;
|
||||
buf.writeLong(info.quantity);
|
||||
buf.writeLong(info.batchSize);
|
||||
buf.writeBoolean(info.enable);
|
||||
buf.writeInt(info.state.ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
private static class Info {
|
||||
|
||||
long quantity;
|
||||
long batchSize;
|
||||
boolean enable;
|
||||
LevelState state;
|
||||
|
||||
Info(long quantity, long batchSize, boolean enable, LevelState state) {
|
||||
this.quantity = quantity;
|
||||
this.batchSize = batchSize;
|
||||
this.enable = enable;
|
||||
this.state = state;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<SPacketLevelMaintainerGuiUpdate, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(SPacketLevelMaintainerGuiUpdate message, MessageContext ctx) {
|
||||
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
|
||||
|
||||
if (gs instanceof GuiLevelMaintainer gui) {
|
||||
for (int i = 0; i < REQ_COUNT; i++) {
|
||||
Info info = message.infoList[i];
|
||||
if (info == null) continue;
|
||||
gui.updateComponent(i, info.quantity, info.batchSize, info.enable, info.state);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user