mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-15 17:44:46 +00:00
Improve gui sync
This commit is contained in:
4 files changed
+63
-34
No files matched your search
@@ -122,7 +122,6 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
TileLevelMaintainer tile = this.cont.getTile();
|
||||
for (int i = 0; i < TileLevelMaintainer.REQ_COUNT; i++) {
|
||||
component[i] = new Component(
|
||||
new Widget(
|
||||
@@ -140,14 +139,6 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
|
||||
new GuiFCImgButton(guiLeft + 9, guiTop + 20 + 19 * i, "DISABLE", "DISABLE", false),
|
||||
new FCGuiLineField(fontRendererObj, guiLeft + 47, guiTop + 33 + 19 * i, 125),
|
||||
this.buttonList);
|
||||
|
||||
if (tile.requests[i] == null) continue;
|
||||
component[i].setEnable(tile.requests[i].isEnable());
|
||||
component[i].setState(tile.requests[i].getState());
|
||||
component[i].getQty().textField.setText(String.valueOf(tile.requests[i].getQuantity()));
|
||||
component[i].getBatch().textField.setText(String.valueOf(tile.requests[i].getBatchSize()));
|
||||
component[i].getQty().validate();
|
||||
component[i].getBatch().validate();
|
||||
}
|
||||
if (this.icon != null) {
|
||||
this.originalGuiBtn = new GuiTabButton(
|
||||
@@ -159,8 +150,6 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
|
||||
this.originalGuiBtn.setHideEdge(13);
|
||||
this.buttonList.add(originalGuiBtn);
|
||||
}
|
||||
|
||||
FluidCraft.proxy.netHandler.sendToServer(new CPacketLevelMaintainer());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -178,11 +167,7 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
|
||||
mc.getTextureManager().bindTexture(TEX_BG);
|
||||
drawTexturedModalRect(offsetX, offsetY, 0, 0, 176, ySize);
|
||||
|
||||
TileLevelMaintainer tile = this.cont.getTile();
|
||||
for (int i = 0; i < TileLevelMaintainer.REQ_COUNT; i++) {
|
||||
if (tile.requests[i] != null) {
|
||||
this.component[i].setState(tile.requests[i].getState());
|
||||
}
|
||||
this.component[i].draw();
|
||||
}
|
||||
}
|
||||
@@ -346,6 +331,11 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
|
||||
component[index].getBatch().validate();
|
||||
}
|
||||
|
||||
public void updateComponent(int index, LevelState state) {
|
||||
if (index < 0 || index >= TileLevelMaintainer.REQ_COUNT) return;
|
||||
component[index].setState(state);
|
||||
}
|
||||
|
||||
private class Component {
|
||||
|
||||
public boolean isEnable = false;
|
||||
|
||||
+22
-1
@@ -5,9 +5,11 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.common.tile.TileLevelMaintainer;
|
||||
import com.glodblock.github.inventory.AeItemStackHandler;
|
||||
import com.glodblock.github.inventory.slot.SlotFluidConvertingFake;
|
||||
import com.glodblock.github.network.SPacketLevelMaintainerGuiUpdate;
|
||||
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.container.AEBaseContainer;
|
||||
@@ -19,6 +21,10 @@ public class ContainerLevelMaintainer extends AEBaseContainer {
|
||||
private final TileLevelMaintainer tile;
|
||||
private final SlotFluidConvertingFake[] requestSlots = new SlotFluidConvertingFake[TileLevelMaintainer.REQ_COUNT];
|
||||
|
||||
private static final int UPDATE_INTERVAL = 20;
|
||||
private boolean isFirstUpdate = true;
|
||||
private int updateCount = UPDATE_INTERVAL;
|
||||
|
||||
public ContainerLevelMaintainer(InventoryPlayer ipl, TileLevelMaintainer tile) {
|
||||
super(ipl, tile);
|
||||
this.tile = tile;
|
||||
@@ -79,8 +85,23 @@ public class ContainerLevelMaintainer extends AEBaseContainer {
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
if (Platform.isClient()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.verifyPermissions(SecurityPermissions.BUILD, false);
|
||||
|
||||
super.detectAndSendChanges();
|
||||
if (this.updateCount++ >= UPDATE_INTERVAL) {
|
||||
this.updateGui();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateGui() {
|
||||
FluidCraft.proxy.netHandler.sendTo(
|
||||
new SPacketLevelMaintainerGuiUpdate(this.tile.requests, !this.isFirstUpdate),
|
||||
(EntityPlayerMP) this.getInventoryPlayer().player);
|
||||
this.isFirstUpdate = false;
|
||||
this.updateCount = 0;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.glodblock.github.network;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.client.gui.container.ContainerLevelMaintainer;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
@@ -17,18 +16,14 @@ public class CPacketLevelMaintainer implements IMessage {
|
||||
Batch,
|
||||
Enable,
|
||||
Disable,
|
||||
UPDATE,
|
||||
}
|
||||
|
||||
private Action action;
|
||||
private long size;
|
||||
private int slotIndex;
|
||||
|
||||
public CPacketLevelMaintainer() {
|
||||
this.action = Action.UPDATE;
|
||||
this.slotIndex = 0;
|
||||
this.size = 0;
|
||||
}
|
||||
@SuppressWarnings("unused")
|
||||
public CPacketLevelMaintainer() {}
|
||||
|
||||
public CPacketLevelMaintainer(Action action, int slotIndex) {
|
||||
this.action = action;
|
||||
@@ -67,8 +62,8 @@ 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);
|
||||
}
|
||||
clm.updateGui();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -17,12 +17,15 @@ import io.netty.buffer.ByteBuf;
|
||||
public class SPacketLevelMaintainerGuiUpdate implements IMessage {
|
||||
|
||||
private Info[] infoList;
|
||||
private boolean onlyState;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public SPacketLevelMaintainerGuiUpdate() {}
|
||||
|
||||
SPacketLevelMaintainerGuiUpdate(RequestInfo[] requests) {
|
||||
public SPacketLevelMaintainerGuiUpdate(RequestInfo[] requests, boolean onlyState) {
|
||||
this.infoList = new Info[REQ_COUNT];
|
||||
this.onlyState = onlyState;
|
||||
|
||||
for (int i = 0; i < REQ_COUNT; i++) {
|
||||
if (requests[i] == null) {
|
||||
this.infoList[i] = null;
|
||||
@@ -39,13 +42,19 @@ public class SPacketLevelMaintainerGuiUpdate implements IMessage {
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
this.infoList = new Info[REQ_COUNT];
|
||||
this.onlyState = buf.readBoolean();
|
||||
|
||||
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()]);
|
||||
if (this.onlyState) {
|
||||
this.infoList[i] = new Info(LevelState.values()[buf.readInt()]);
|
||||
} else {
|
||||
this.infoList[i] = new Info(
|
||||
buf.readLong(),
|
||||
buf.readLong(),
|
||||
buf.readBoolean(),
|
||||
LevelState.values()[buf.readInt()]);
|
||||
}
|
||||
} else {
|
||||
this.infoList[i] = null;
|
||||
}
|
||||
@@ -54,12 +63,15 @@ public class SPacketLevelMaintainerGuiUpdate implements IMessage {
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeBoolean(this.onlyState);
|
||||
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);
|
||||
if (!this.onlyState) {
|
||||
buf.writeLong(info.quantity);
|
||||
buf.writeLong(info.batchSize);
|
||||
buf.writeBoolean(info.enable);
|
||||
}
|
||||
buf.writeInt(info.state.ordinal());
|
||||
}
|
||||
}
|
||||
@@ -77,6 +89,13 @@ public class SPacketLevelMaintainerGuiUpdate implements IMessage {
|
||||
this.enable = enable;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
Info(LevelState state) {
|
||||
this.quantity = 0;
|
||||
this.batchSize = 0;
|
||||
this.enable = false;
|
||||
this.state = state;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<SPacketLevelMaintainerGuiUpdate, IMessage> {
|
||||
@@ -89,7 +108,11 @@ public class SPacketLevelMaintainerGuiUpdate implements IMessage {
|
||||
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);
|
||||
if (message.onlyState) {
|
||||
gui.updateComponent(i, info.state);
|
||||
} else {
|
||||
gui.updateComponent(i, info.quantity, info.batchSize, info.enable, info.state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user