mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-16 01:54:59 +00:00
Rewrite Level Maintainer/Terminal Logic (#294)
Co-authored-by: boubou19 <[email protected]>
This commit is contained in:
1 parent
1ffcea9dd9
commit
6ac5ea30f0
18 files changed
+1050
-1427
No files matched your search
@@ -1,16 +1,9 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
import com.glodblock.github.client.gui.container.ContainerLevelMaintainer;
|
||||
import com.glodblock.github.common.tile.TileLevelMaintainer;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
@@ -19,28 +12,18 @@ import io.netty.buffer.ByteBuf;
|
||||
public class CPacketLevelMaintainer implements IMessage {
|
||||
|
||||
public enum Action {
|
||||
Refresh,
|
||||
Quantity,
|
||||
Batch,
|
||||
Enable,
|
||||
Disable
|
||||
Disable,
|
||||
}
|
||||
|
||||
private Action action;
|
||||
private long size;
|
||||
private int slotIndex;
|
||||
|
||||
public CPacketLevelMaintainer() {
|
||||
this.action = Action.Refresh;
|
||||
this.slotIndex = 0;
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
public CPacketLevelMaintainer(Action action) {
|
||||
this.action = action;
|
||||
this.slotIndex = 0;
|
||||
this.size = 0;
|
||||
}
|
||||
@SuppressWarnings("unused")
|
||||
public CPacketLevelMaintainer() {}
|
||||
|
||||
public CPacketLevelMaintainer(Action action, int slotIndex) {
|
||||
this.action = action;
|
||||
@@ -70,43 +53,17 @@ public class CPacketLevelMaintainer implements IMessage {
|
||||
|
||||
public static class Handler implements IMessageHandler<CPacketLevelMaintainer, IMessage> {
|
||||
|
||||
private List<IAEItemStack> refresh(ContainerLevelMaintainer cca) {
|
||||
List<IAEItemStack> toSend = new ArrayList<>(TileLevelMaintainer.REQ_COUNT);
|
||||
for (int i = 0; i < TileLevelMaintainer.REQ_COUNT; i++) {
|
||||
IAEItemStack ias = cca.getTile().requests.getAEItemStack(i);
|
||||
if (ias != null) {
|
||||
toSend.add(ias);
|
||||
}
|
||||
}
|
||||
return toSend;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IMessage onMessage(CPacketLevelMaintainer message, MessageContext ctx) {
|
||||
if (ctx.getServerHandler().playerEntity.openContainer instanceof final ContainerLevelMaintainer clm) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
List<IAEItemStack> toSend = switch (message.action) {
|
||||
case Quantity -> {
|
||||
clm.getTile().updateQuantity(message.slotIndex, message.size);
|
||||
yield this.refresh(clm);
|
||||
}
|
||||
case Batch -> {
|
||||
clm.getTile().updateBatchSize(message.slotIndex, message.size);
|
||||
yield this.refresh(clm);
|
||||
}
|
||||
case Enable -> {
|
||||
clm.getTile().updateStatus(message.slotIndex, false);
|
||||
yield this.refresh(clm);
|
||||
}
|
||||
case Disable -> {
|
||||
clm.getTile().updateStatus(message.slotIndex, true);
|
||||
yield this.refresh(clm);
|
||||
}
|
||||
case Refresh -> this.refresh(clm);
|
||||
};
|
||||
|
||||
SPacketMEUpdateBuffer.scheduleItemUpdate(player, toSend);
|
||||
switch (message.action) {
|
||||
case Quantity -> clm.getTile().updateQuantity(message.slotIndex, message.size);
|
||||
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);
|
||||
}
|
||||
clm.updateGui();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
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;
|
||||
private boolean onlyState;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public SPacketLevelMaintainerGuiUpdate() {}
|
||||
|
||||
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;
|
||||
} 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];
|
||||
this.onlyState = buf.readBoolean();
|
||||
|
||||
for (int i = 0; i < REQ_COUNT; i++) {
|
||||
if (buf.readBoolean()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeBoolean(this.onlyState);
|
||||
for (Info info : this.infoList) {
|
||||
buf.writeBoolean(info != null);
|
||||
if (info == null) continue;
|
||||
if (!this.onlyState) {
|
||||
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;
|
||||
}
|
||||
|
||||
Info(LevelState state) {
|
||||
this.quantity = 0;
|
||||
this.batchSize = 0;
|
||||
this.enable = false;
|
||||
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;
|
||||
if (message.onlyState) {
|
||||
gui.updateComponent(i, info.state);
|
||||
} else {
|
||||
gui.updateComponent(i, info.quantity, info.batchSize, info.enable, info.state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,17 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.common.util.Constants.NBT;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.glodblock.github.api.registries.LevelItemInfo;
|
||||
import com.glodblock.github.api.registries.LevelState;
|
||||
import com.glodblock.github.client.gui.GuiLevelTerminal;
|
||||
|
||||
import appeng.core.AEConfig;
|
||||
@@ -27,58 +22,28 @@ 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;
|
||||
import io.netty.buffer.ByteBufInputStream;
|
||||
import io.netty.buffer.ByteBufOutputStream;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
/**
|
||||
* Packet used for level terminal updates. Packet allows the server to send an array of command packets, which are then
|
||||
* processed in order. This allows for chaining commands to produce the desired update.
|
||||
*/
|
||||
public class SPacketLevelTerminalUpdate implements IMessage {
|
||||
|
||||
public static final int CLEAR_ALL_BIT = 1;
|
||||
public static final int DISCONNECT_BIT = 2;
|
||||
|
||||
private final List<PacketEntry> commands = new ArrayList<>();
|
||||
private int statusFlags;
|
||||
|
||||
public SPacketLevelTerminalUpdate() {}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
this.statusFlags = buf.readByte();
|
||||
int numEntries = buf.readInt();
|
||||
int entryNum = buf.readInt();
|
||||
|
||||
for (int i = 0; i < numEntries; ++i) {
|
||||
try {
|
||||
PacketType type = PacketType.values()[buf.readByte()];
|
||||
for (int i = 0; i < entryNum; i++) {
|
||||
PacketType type = PacketType.values()[buf.readByte()];
|
||||
|
||||
switch (type) {
|
||||
case ADD -> this.commands.add(new PacketAdd(buf));
|
||||
case REMOVE -> this.commands.add(new PacketRemove(buf));
|
||||
case OVERWRITE -> this.commands.add(new PacketOverwrite(buf));
|
||||
case RENAME -> this.commands.add(new PacketRename(buf));
|
||||
default -> throw new IOException("Unknown packet type received of index " + type);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (AEConfig.instance.isFeatureEnabled(AEFeature.PacketLogging)) {
|
||||
AELog.info(
|
||||
"Corrupted packet commands: (" + i
|
||||
+ ") of ("
|
||||
+ numEntries
|
||||
+ ") -> "
|
||||
+ this.commands.size()
|
||||
+ " : "
|
||||
+ this.commands.stream().map(packetEntry -> packetEntry.getClass().getSimpleName())
|
||||
.collect(Collectors.groupingBy(String::new, Collectors.counting())));
|
||||
if (AEConfig.instance.isFeatureEnabled(AEFeature.DebugLogging)) {
|
||||
AELog.info(" <- Parsed content: " + this.commands);
|
||||
}
|
||||
}
|
||||
AELog.debug(e);
|
||||
return;
|
||||
switch (type) {
|
||||
case ADD -> this.commands.add(new PacketAdd(buf));
|
||||
case REMOVE -> this.commands.add(new PacketRemove(buf));
|
||||
case RENAME -> this.commands.add(new PacketRename(buf));
|
||||
case DISCONNECT -> this.commands.add(new PacketDisconnect(buf));
|
||||
case OVERWRITE_SLOT -> this.commands.add(new PacketOverwriteSlot(buf));
|
||||
case OVERWITE_ALL_SLOT -> this.commands.add(new PacketOverwirteAllSlot(buf));
|
||||
}
|
||||
}
|
||||
|
||||
if (AEConfig.instance.isFeatureEnabled(AEFeature.PacketLogging)) {
|
||||
AELog.info(
|
||||
" <- Received commands " + this.commands.size()
|
||||
@@ -88,80 +53,49 @@ public class SPacketLevelTerminalUpdate implements IMessage {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
try {
|
||||
if (AEConfig.instance.isFeatureEnabled(AEFeature.PacketLogging)) {
|
||||
AELog.info(
|
||||
" <- Sent commands " + this.commands.size()
|
||||
+ " : "
|
||||
+ this.commands.stream().map(packetEntry -> packetEntry.getClass().getSimpleName())
|
||||
.collect(Collectors.groupingBy(String::new, Collectors.counting())));
|
||||
if (AEConfig.instance.isFeatureEnabled(AEFeature.DebugLogging)) {
|
||||
AELog.info(" -> Sent commands: " + this.commands);
|
||||
}
|
||||
}
|
||||
buf.writeInt(commands.size());
|
||||
for (PacketEntry entry : this.commands) {
|
||||
buf.writeByte(entry.getType().ordinal());
|
||||
entry.write(buf);
|
||||
}
|
||||
|
||||
buf.writeByte(statusFlags);
|
||||
buf.writeInt(commands.size());
|
||||
for (PacketEntry entry : commands) {
|
||||
entry.write(buf);
|
||||
if (AEConfig.instance.isFeatureEnabled(AEFeature.PacketLogging)) {
|
||||
AELog.info(
|
||||
" <- Sent commands " + this.commands.size()
|
||||
+ " : "
|
||||
+ this.commands.stream().map(packetEntry -> packetEntry.getClass().getSimpleName())
|
||||
.collect(Collectors.groupingBy(String::new, Collectors.counting())));
|
||||
if (AEConfig.instance.isFeatureEnabled(AEFeature.DebugLogging)) {
|
||||
AELog.info(" -> Sent commands: " + this.commands);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all entries on the terminal. This is done BEFORE any entries are processed, so you can set this to clear
|
||||
* old entries, and add new ones after in one packet.
|
||||
*/
|
||||
public void setClear() {
|
||||
statusFlags |= CLEAR_ALL_BIT;
|
||||
public void addNewEntry(long id, int x, int y, int z, int dim, int side, int rows, int rowSize, String name,
|
||||
LevelItemInfo[] infolist) {
|
||||
this.commands.add(new PacketAdd(id, x, y, z, dim, side, rows, rowSize, name, infolist));
|
||||
}
|
||||
|
||||
/**
|
||||
* The terminal disconnected. Entries are still processed, but indicates for the GUI to darken/turn off the
|
||||
* terminal. No further updates will arrive until the terminal reconnects.
|
||||
*/
|
||||
public void setDisconnect() {
|
||||
this.statusFlags |= DISCONNECT_BIT;
|
||||
public void addRemoveEntry(long id) {
|
||||
this.commands.add(new PacketRemove(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new entry. Fill out the rest of the command using the {@link PacketAdd#setItems(int, int, NBTTagList)} and
|
||||
* {@link PacketAdd#setLocation(int, int, int, int, int)}.
|
||||
*
|
||||
* @return the packet, which needs to have information filled out.
|
||||
*/
|
||||
public PacketAdd addNewEntry(long id, String name, boolean online) {
|
||||
PacketAdd packet = new PacketAdd(id, name, online);
|
||||
|
||||
commands.add(packet);
|
||||
return packet;
|
||||
public void addRenameEntry(long id, String newName) {
|
||||
this.commands.add(new PacketRename(id, newName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the entry with the id from the terminal.
|
||||
*/
|
||||
public void addRemovalEntry(long id) {
|
||||
commands.add(new PacketRemove(id));
|
||||
public void addDisconnectEntry() {
|
||||
this.commands.add(new PacketDisconnect());
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename the entry
|
||||
*/
|
||||
public void addRenamedEntry(long id, String newName) {
|
||||
commands.add(new PacketRename(id, newName));
|
||||
public void addOverwriteSlotEntry(long id, int index, LevelItemInfo info) {
|
||||
this.commands.add(new PacketOverwriteSlot(id, index, info));
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite the entry with new items or new status
|
||||
*/
|
||||
public PacketOverwrite addOverwriteEntry(long id) {
|
||||
PacketOverwrite packet = new PacketOverwrite(id);
|
||||
|
||||
commands.add(packet);
|
||||
return packet;
|
||||
public void addOverwriteAllSlotEntry(long id, LevelItemInfo[] info) {
|
||||
this.commands.add(new PacketOverwirteAllSlot(id, info));
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<SPacketLevelTerminalUpdate, IMessage> {
|
||||
@@ -172,23 +106,22 @@ public class SPacketLevelTerminalUpdate implements IMessage {
|
||||
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
|
||||
|
||||
if (gs instanceof GuiLevelTerminal levelTerminal) {
|
||||
levelTerminal.postUpdate(message.commands, message.statusFlags);
|
||||
levelTerminal.receivePackets(message.commands);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
enum PacketType {
|
||||
protected enum PacketType {
|
||||
ADD,
|
||||
REMOVE,
|
||||
OVERWRITE,
|
||||
RENAME,
|
||||
DISCONNECT,
|
||||
OVERWRITE_SLOT,
|
||||
OVERWITE_ALL_SLOT,
|
||||
}
|
||||
|
||||
/**
|
||||
* A packet for updating an entry.
|
||||
*/
|
||||
public abstract static class PacketEntry {
|
||||
|
||||
public final long entryId;
|
||||
@@ -197,181 +130,87 @@ public class SPacketLevelTerminalUpdate implements IMessage {
|
||||
this.entryId = entryId;
|
||||
}
|
||||
|
||||
protected PacketEntry(ByteBuf buf) throws IOException {
|
||||
public PacketEntry(ByteBuf buf) {
|
||||
this.entryId = buf.readLong();
|
||||
read(buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Needs to write the packet id.
|
||||
*/
|
||||
protected abstract void write(ByteBuf buf) throws IOException;
|
||||
protected abstract PacketType getType();
|
||||
|
||||
/**
|
||||
* Reading the entry id is not needed.
|
||||
*/
|
||||
protected abstract void read(ByteBuf buf) throws IOException;
|
||||
protected void write(ByteBuf buf) {
|
||||
buf.writeLong(this.entryId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A command for sending a new entry.
|
||||
*/
|
||||
public static class PacketAdd extends PacketEntry {
|
||||
|
||||
public String name;
|
||||
public int x, y, z, dim, side;
|
||||
public int rows, rowSize;
|
||||
public boolean online;
|
||||
public ItemStack selfItemStack;
|
||||
public ItemStack displayItemStack;
|
||||
public NBTTagList items;
|
||||
public String name;
|
||||
public LevelItemInfo[] infolist;
|
||||
|
||||
PacketAdd(long id, String name, boolean online) {
|
||||
PacketAdd(long id, int x, int y, int z, int dim, int side, int rows, int rowSize, String name,
|
||||
LevelItemInfo[] infolist) {
|
||||
super(id);
|
||||
this.name = name;
|
||||
this.online = online;
|
||||
}
|
||||
|
||||
PacketAdd(ByteBuf buf) throws IOException {
|
||||
super(buf);
|
||||
}
|
||||
|
||||
public PacketAdd setLocation(int x, int y, int z, int dim, int side) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.dim = dim;
|
||||
this.side = side;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PacketAdd setItems(int rows, int rowSize, NBTTagList items) {
|
||||
this.rows = rows;
|
||||
this.rowSize = rowSize;
|
||||
this.items = items;
|
||||
|
||||
return this;
|
||||
this.name = name;
|
||||
this.infolist = infolist;
|
||||
}
|
||||
|
||||
public PacketAdd setViewItemStack(ItemStack selfItemStack, ItemStack displayItemStack) {
|
||||
this.selfItemStack = selfItemStack;
|
||||
this.displayItemStack = displayItemStack;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void write(ByteBuf buf) throws IOException {
|
||||
buf.writeByte(PacketType.ADD.ordinal());
|
||||
buf.writeLong(entryId);
|
||||
ByteBufUtils.writeUTF8String(buf, this.name);
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
buf.writeInt(dim);
|
||||
buf.writeByte(side);
|
||||
buf.writeInt(rows);
|
||||
buf.writeInt(rowSize);
|
||||
|
||||
ByteBuf tempBuf = Unpooled.directBuffer(256);
|
||||
try {
|
||||
try (ByteBufOutputStream stream = new ByteBufOutputStream(tempBuf)) {
|
||||
|
||||
NBTTagCompound wrapper = new NBTTagCompound();
|
||||
|
||||
if (selfItemStack != null) {
|
||||
wrapper.setTag("self", selfItemStack.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
if (displayItemStack != null) {
|
||||
wrapper.setTag("display", displayItemStack.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
wrapper.setTag("data", items);
|
||||
CompressedStreamTools.writeCompressed(wrapper, stream);
|
||||
}
|
||||
buf.writeInt(tempBuf.readableBytes());
|
||||
buf.writeBytes(tempBuf);
|
||||
} finally {
|
||||
tempBuf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void read(ByteBuf buf) throws IOException {
|
||||
this.name = ByteBufUtils.readUTF8String(buf);
|
||||
public PacketAdd(ByteBuf buf) {
|
||||
super(buf);
|
||||
this.x = buf.readInt();
|
||||
this.y = buf.readInt();
|
||||
this.z = buf.readInt();
|
||||
this.dim = buf.readInt();
|
||||
this.side = buf.readByte();
|
||||
this.side = buf.readInt();
|
||||
this.rows = buf.readInt();
|
||||
this.rowSize = buf.readInt();
|
||||
int payloadSize = buf.readInt();
|
||||
try (ByteBufInputStream stream = new ByteBufInputStream(buf, payloadSize)) {
|
||||
NBTTagCompound payload = CompressedStreamTools.readCompressed(stream);
|
||||
int available = stream.available();
|
||||
if (available > 0) {
|
||||
byte[] left = new byte[available];
|
||||
int read = stream.read(left);
|
||||
if (AEConfig.instance.isFeatureEnabled(AEFeature.PacketLogging)) {
|
||||
AELog.info(
|
||||
"Unread bytes detected (" + read
|
||||
+ "): "
|
||||
+ Arrays.toString(left)
|
||||
+ " at "
|
||||
+ dim
|
||||
+ "#("
|
||||
+ x
|
||||
+ ":"
|
||||
+ y
|
||||
+ ":"
|
||||
+ z
|
||||
+ ")@"
|
||||
+ ForgeDirection.getOrientation(side));
|
||||
}
|
||||
}
|
||||
|
||||
if (payload.hasKey("self", NBT.TAG_COMPOUND)) {
|
||||
this.selfItemStack = ItemStack.loadItemStackFromNBT(payload.getCompoundTag("self"));
|
||||
}
|
||||
|
||||
if (payload.hasKey("display", NBT.TAG_COMPOUND)) {
|
||||
this.displayItemStack = ItemStack.loadItemStackFromNBT(payload.getCompoundTag("display"));
|
||||
}
|
||||
|
||||
this.items = payload.getTagList("data", NBT.TAG_COMPOUND);
|
||||
this.name = ByteBufUtils.readUTF8String(buf);
|
||||
int infoSize = buf.readInt();
|
||||
infolist = new LevelItemInfo[infoSize];
|
||||
for (int i = 0; i < infoSize; i++) {
|
||||
if (!buf.readBoolean()) continue;
|
||||
ItemStack stack = ByteBufUtils.readItemStack(buf);
|
||||
long quantity = buf.readLong();
|
||||
long batchSize = buf.readLong();
|
||||
LevelState state = LevelState.values()[buf.readInt()];
|
||||
infolist[i] = new LevelItemInfo(stack, quantity, batchSize, state);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PacketAdd{" + "name='"
|
||||
+ name
|
||||
+ '\''
|
||||
+ ", x="
|
||||
+ x
|
||||
+ ", y="
|
||||
+ y
|
||||
+ ", z="
|
||||
+ z
|
||||
+ ", dim="
|
||||
+ dim
|
||||
+ ", side="
|
||||
+ side
|
||||
+ ", rows="
|
||||
+ rows
|
||||
+ ", rowSize="
|
||||
+ rowSize
|
||||
+ ", online="
|
||||
+ online
|
||||
+ ", selfItemStack="
|
||||
+ selfItemStack
|
||||
+ ", displayItemStack="
|
||||
+ displayItemStack
|
||||
+ ", items="
|
||||
+ items
|
||||
+ ", entryId="
|
||||
+ entryId
|
||||
+ '}';
|
||||
protected PacketType getType() {
|
||||
return PacketType.ADD;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void write(ByteBuf buf) {
|
||||
super.write(buf);
|
||||
buf.writeInt(this.x);
|
||||
buf.writeInt(this.y);
|
||||
buf.writeInt(this.z);
|
||||
buf.writeInt(this.dim);
|
||||
buf.writeInt(this.side);
|
||||
buf.writeInt(this.rows);
|
||||
buf.writeInt(this.rowSize);
|
||||
ByteBufUtils.writeUTF8String(buf, this.name);
|
||||
buf.writeInt(this.infolist.length);
|
||||
for (int i = 0; i < this.infolist.length; i++) {
|
||||
LevelItemInfo info = this.infolist[i];
|
||||
buf.writeBoolean(info != null);
|
||||
if (info == null) continue;
|
||||
// System.out.println("Writing info: " + info.stack != null);
|
||||
ByteBufUtils.writeItemStack(buf, info.stack);
|
||||
buf.writeLong(info.quantity);
|
||||
buf.writeLong(info.batchSize);
|
||||
buf.writeInt(info.state.ordinal());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,205 +220,147 @@ public class SPacketLevelTerminalUpdate implements IMessage {
|
||||
super(id);
|
||||
}
|
||||
|
||||
PacketRemove(ByteBuf buf) throws IOException {
|
||||
PacketRemove(ByteBuf buf) {
|
||||
super(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PacketType getType() {
|
||||
return PacketType.REMOVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void write(ByteBuf buf) {
|
||||
buf.writeByte(PacketType.REMOVE.ordinal());
|
||||
buf.writeLong(entryId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void read(ByteBuf buf) {}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PacketRemove{" + "entryId=" + entryId + '}';
|
||||
super.write(buf);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite online status or inventory of the entry.
|
||||
*/
|
||||
public static class PacketOverwrite extends PacketEntry {
|
||||
|
||||
public static final int ONLINE_BIT = 1;
|
||||
public static final int ONLINE_VALID = 1 << 1;
|
||||
public static final int ITEMS_VALID = 1 << 2;
|
||||
public static final int ALL_ITEM_UPDATE_BIT = 1 << 3;
|
||||
public boolean onlineValid;
|
||||
public boolean online;
|
||||
public boolean itemsValid;
|
||||
public boolean allItemUpdate;
|
||||
public int[] validIndices;
|
||||
public NBTTagList items;
|
||||
|
||||
protected PacketOverwrite(long id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
protected PacketOverwrite(ByteBuf buf) throws IOException {
|
||||
super(buf);
|
||||
}
|
||||
|
||||
public PacketOverwrite setOnline(boolean online) {
|
||||
this.onlineValid = true;
|
||||
this.online = online;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PacketOverwrite setItems(int[] validIndices, NBTTagList items) {
|
||||
this.itemsValid = true;
|
||||
this.allItemUpdate = validIndices == null || validIndices.length == 0;
|
||||
this.validIndices = validIndices;
|
||||
this.items = items;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PacketOverwrite setItems(int newSize, NBTTagList items) {
|
||||
this.itemsValid = true;
|
||||
this.allItemUpdate = true;
|
||||
this.validIndices = new int[newSize];
|
||||
this.items = items;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void write(ByteBuf buf) throws IOException {
|
||||
buf.writeByte(PacketType.OVERWRITE.ordinal());
|
||||
buf.writeLong(entryId);
|
||||
|
||||
int flags = 0;
|
||||
|
||||
if (onlineValid) {
|
||||
flags |= ONLINE_VALID;
|
||||
flags |= online ? ONLINE_BIT : 0;
|
||||
}
|
||||
if (itemsValid) {
|
||||
flags |= ITEMS_VALID;
|
||||
if (allItemUpdate) {
|
||||
flags |= ALL_ITEM_UPDATE_BIT;
|
||||
buf.writeByte(flags);
|
||||
buf.writeInt(validIndices.length);
|
||||
} else {
|
||||
buf.writeByte(flags);
|
||||
buf.writeInt(validIndices.length);
|
||||
for (int validIndex : validIndices) {
|
||||
buf.writeInt(validIndex);
|
||||
}
|
||||
}
|
||||
ByteBuf tempBuf = Unpooled.directBuffer(256);
|
||||
try {
|
||||
try (ByteBufOutputStream stream = new ByteBufOutputStream(tempBuf)) {
|
||||
|
||||
NBTTagCompound wrapper = new NBTTagCompound();
|
||||
|
||||
wrapper.setTag("data", items);
|
||||
CompressedStreamTools.writeCompressed(wrapper, stream);
|
||||
}
|
||||
buf.writeInt(tempBuf.readableBytes());
|
||||
buf.writeBytes(tempBuf);
|
||||
} finally {
|
||||
tempBuf.release();
|
||||
}
|
||||
} else {
|
||||
buf.writeByte(flags);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void read(ByteBuf buf) throws IOException {
|
||||
int flags = buf.readByte();
|
||||
|
||||
/* Decide whether to use online flag or not */
|
||||
if ((flags & ONLINE_VALID) == ONLINE_VALID) {
|
||||
this.onlineValid = true;
|
||||
this.online = (flags & ONLINE_BIT) == ONLINE_BIT;
|
||||
}
|
||||
/* Decide whether to read item list or not */
|
||||
if ((flags & ITEMS_VALID) == ITEMS_VALID) {
|
||||
this.itemsValid = true;
|
||||
if ((flags & ALL_ITEM_UPDATE_BIT) == ALL_ITEM_UPDATE_BIT) {
|
||||
this.allItemUpdate = true;
|
||||
int numItems = buf.readInt();
|
||||
this.validIndices = new int[numItems];
|
||||
} else {
|
||||
int numItems = buf.readInt();
|
||||
this.validIndices = new int[numItems];
|
||||
for (int i = 0; i < numItems; ++i) {
|
||||
this.validIndices[i] = buf.readInt();
|
||||
}
|
||||
}
|
||||
int payloadSize = buf.readInt();
|
||||
try (ByteBufInputStream stream = new ByteBufInputStream(buf, payloadSize)) {
|
||||
this.items = CompressedStreamTools.readCompressed(stream).getTagList("data", NBT.TAG_COMPOUND);
|
||||
int available = stream.available();
|
||||
if (available > 0) {
|
||||
byte[] left = new byte[available];
|
||||
int read = stream.read(left);
|
||||
if (AEConfig.instance.isFeatureEnabled(AEFeature.PacketLogging)) {
|
||||
AELog.info("Unread bytes detected (" + read + "): " + Arrays.toString(left));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PacketOverwrite{" + "onlineValid="
|
||||
+ onlineValid
|
||||
+ ", online="
|
||||
+ online
|
||||
+ ", itemsValid="
|
||||
+ itemsValid
|
||||
+ ", allItemUpdate="
|
||||
+ allItemUpdate
|
||||
+ ", validIndices="
|
||||
+ Arrays.toString(validIndices)
|
||||
+ ", items="
|
||||
+ items
|
||||
+ ", entryId="
|
||||
+ entryId
|
||||
+ '}';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename the entry.
|
||||
*/
|
||||
public static class PacketRename extends PacketEntry {
|
||||
|
||||
public String newName;
|
||||
|
||||
protected PacketRename(long id, String newName) {
|
||||
PacketRename(long id, String newName) {
|
||||
super(id);
|
||||
this.newName = newName;
|
||||
}
|
||||
|
||||
protected PacketRename(ByteBuf buf) throws IOException {
|
||||
PacketRename(ByteBuf buf) {
|
||||
super(buf);
|
||||
this.newName = ByteBufUtils.readUTF8String(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PacketType getType() {
|
||||
return PacketType.RENAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void write(ByteBuf buf) {
|
||||
buf.writeByte(PacketType.RENAME.ordinal());
|
||||
buf.writeLong(entryId);
|
||||
ByteBufUtils.writeUTF8String(buf, newName);
|
||||
super.write(buf);
|
||||
ByteBufUtils.writeUTF8String(buf, this.newName);
|
||||
}
|
||||
}
|
||||
|
||||
public static class PacketDisconnect extends PacketEntry {
|
||||
|
||||
PacketDisconnect() {
|
||||
super(0); // Ignored id
|
||||
}
|
||||
|
||||
PacketDisconnect(ByteBuf buf) {
|
||||
super(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void read(ByteBuf buf) {
|
||||
newName = ByteBufUtils.readUTF8String(buf);
|
||||
protected PacketType getType() {
|
||||
return PacketType.DISCONNECT;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PacketOverwriteSlot extends PacketEntry {
|
||||
|
||||
public int index;
|
||||
public LevelItemInfo info;
|
||||
|
||||
PacketOverwriteSlot(long id, int index, LevelItemInfo info) {
|
||||
super(id);
|
||||
this.index = index;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
PacketOverwriteSlot(ByteBuf buf) {
|
||||
super(buf);
|
||||
this.index = buf.readInt();
|
||||
if (buf.readBoolean()) {
|
||||
this.info = new LevelItemInfo(
|
||||
ByteBufUtils.readItemStack(buf),
|
||||
buf.readLong(),
|
||||
buf.readLong(),
|
||||
LevelState.values()[buf.readInt()]);
|
||||
} else {
|
||||
this.info = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PacketRename{" + "newName='" + newName + '\'' + ", entryId=" + entryId + '}';
|
||||
protected PacketType getType() {
|
||||
return PacketType.OVERWRITE_SLOT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void write(ByteBuf buf) {
|
||||
super.write(buf);
|
||||
buf.writeInt(index);
|
||||
buf.writeBoolean(info != null);
|
||||
ByteBufUtils.writeItemStack(buf, info.stack);
|
||||
buf.writeLong(info.quantity);
|
||||
buf.writeLong(info.batchSize);
|
||||
buf.writeInt(info.state.ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
public static class PacketOverwirteAllSlot extends PacketEntry {
|
||||
|
||||
public LevelItemInfo[] infoList;
|
||||
|
||||
PacketOverwirteAllSlot(long id, LevelItemInfo[] info) {
|
||||
super(id);
|
||||
this.infoList = info;
|
||||
}
|
||||
|
||||
PacketOverwirteAllSlot(ByteBuf buf) {
|
||||
super(buf);
|
||||
int infoSize = buf.readInt();
|
||||
this.infoList = new LevelItemInfo[infoSize];
|
||||
for (int i = 0; i < infoSize; i++) {
|
||||
if (!buf.readBoolean()) continue;
|
||||
ItemStack stack = ByteBufUtils.readItemStack(buf);
|
||||
long quantity = buf.readLong();
|
||||
long batchSize = buf.readLong();
|
||||
LevelState state = LevelState.values()[buf.readInt()];
|
||||
this.infoList[i] = new LevelItemInfo(stack, quantity, batchSize, state);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PacketType getType() {
|
||||
return PacketType.OVERWITE_ALL_SLOT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void write(ByteBuf buf) {
|
||||
super.write(buf);
|
||||
buf.writeInt(this.infoList.length);
|
||||
for (int i = 0; i < this.infoList.length; i++) {
|
||||
LevelItemInfo info = this.infoList[i];
|
||||
buf.writeBoolean(info != null);
|
||||
if (info == null) continue;
|
||||
buf.writeInt(i);
|
||||
ByteBufUtils.writeItemStack(buf, info.stack);
|
||||
buf.writeLong(info.quantity);
|
||||
buf.writeLong(info.batchSize);
|
||||
buf.writeInt(info.state.ordinal());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import com.glodblock.github.client.gui.GuiFluidCraftConfirm;
|
||||
import com.glodblock.github.client.gui.GuiItemMonitor;
|
||||
import com.glodblock.github.client.gui.GuiLevelMaintainer;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
@@ -97,8 +96,6 @@ public class SPacketMEItemInvUpdate implements IMessage {
|
||||
((GuiItemMonitor) gs).postUpdate(message.list, message.resort);
|
||||
} else if (gs instanceof GuiFluidCraftConfirm) {
|
||||
((GuiFluidCraftConfirm) gs).postUpdate(message.list, message.ref);
|
||||
} else if (gs instanceof GuiLevelMaintainer) {
|
||||
((GuiLevelMaintainer) gs).postUpdate(message.list);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user