Merge branch '8.0.x-1.16.1'

This commit is contained in:
Sebastian Hartte
2020-09-01 01:07:47 +02:00
5 changed files with 20 additions and 163 deletions
@@ -42,7 +42,7 @@ import appeng.api.networking.security.IActionHost;
import appeng.container.AEBaseContainer; import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.CompressedNBTPacket; import appeng.core.sync.packets.MEInterfaceUpdatePacket;
import appeng.helpers.DualityInterface; import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost; import appeng.helpers.IInterfaceHost;
import appeng.helpers.InventoryAction; import appeng.helpers.InventoryAction;
@@ -177,7 +177,7 @@ public final class InterfaceTerminalContainer extends AEBaseContainer {
if (!this.data.isEmpty()) { if (!this.data.isEmpty()) {
try { try {
NetworkHandler.instance().sendTo(new CompressedNBTPacket(this.data), NetworkHandler.instance().sendTo(new MEInterfaceUpdatePacket(this.data),
(ServerPlayerEntity) this.getPlayerInv().player); (ServerPlayerEntity) this.getPlayerInv().player);
} catch (final IOException e) { } catch (final IOException e) {
// :P // :P
@@ -29,7 +29,6 @@ import appeng.core.sync.packets.BlockTransitionEffectPacket;
import appeng.core.sync.packets.ClickPacket; import appeng.core.sync.packets.ClickPacket;
import appeng.core.sync.packets.CompassRequestPacket; import appeng.core.sync.packets.CompassRequestPacket;
import appeng.core.sync.packets.CompassResponsePacket; import appeng.core.sync.packets.CompassResponsePacket;
import appeng.core.sync.packets.CompressedNBTPacket;
import appeng.core.sync.packets.ConfigButtonPacket; import appeng.core.sync.packets.ConfigButtonPacket;
import appeng.core.sync.packets.ConfigValuePacket; import appeng.core.sync.packets.ConfigValuePacket;
import appeng.core.sync.packets.CraftRequestPacket; import appeng.core.sync.packets.CraftRequestPacket;
@@ -39,6 +38,7 @@ import appeng.core.sync.packets.ItemTransitionEffectPacket;
import appeng.core.sync.packets.JEIRecipePacket; import appeng.core.sync.packets.JEIRecipePacket;
import appeng.core.sync.packets.LightningPacket; import appeng.core.sync.packets.LightningPacket;
import appeng.core.sync.packets.MEFluidInventoryUpdatePacket; import appeng.core.sync.packets.MEFluidInventoryUpdatePacket;
import appeng.core.sync.packets.MEInterfaceUpdatePacket;
import appeng.core.sync.packets.MEInventoryUpdatePacket; import appeng.core.sync.packets.MEInventoryUpdatePacket;
import appeng.core.sync.packets.MatterCannonPacket; import appeng.core.sync.packets.MatterCannonPacket;
import appeng.core.sync.packets.MockExplosionPacket; import appeng.core.sync.packets.MockExplosionPacket;
@@ -101,7 +101,7 @@ public class BasePacketHandler {
PACKET_ASSEMBLER_ANIMATION(AssemblerAnimationPacket.class, AssemblerAnimationPacket::new), PACKET_ASSEMBLER_ANIMATION(AssemblerAnimationPacket.class, AssemblerAnimationPacket::new),
PACKET_COMPRESSED_NBT(CompressedNBTPacket.class, CompressedNBTPacket::new), PACKET_ME_INTERFACE_UPDATE(MEInterfaceUpdatePacket.class, MEInterfaceUpdatePacket::new),
PACKET_PAINTED_ENTITY(PaintedEntityPacket.class, PaintedEntityPacket::new), PACKET_PAINTED_ENTITY(PaintedEntityPacket.class, PaintedEntityPacket::new),
@@ -19,13 +19,9 @@
package appeng.core.sync.packets; package appeng.core.sync.packets;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.BufferOverflowException; import java.nio.BufferOverflowException;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@@ -41,7 +37,6 @@ import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.network.NetworkDirection; import net.minecraftforge.fml.network.NetworkDirection;
import appeng.api.storage.data.IAEFluidStack; import appeng.api.storage.data.IAEFluidStack;
import appeng.core.AELog;
import appeng.core.sync.BasePacket; import appeng.core.sync.BasePacket;
import appeng.core.sync.network.INetworkInfo; import appeng.core.sync.network.INetworkInfo;
import appeng.fluids.client.gui.FluidTerminalScreen; import appeng.fluids.client.gui.FluidTerminalScreen;
@@ -55,8 +50,6 @@ import appeng.fluids.util.AEFluidStack;
public class MEFluidInventoryUpdatePacket extends BasePacket { public class MEFluidInventoryUpdatePacket extends BasePacket {
private static final int UNCOMPRESSED_PACKET_BYTE_LIMIT = 16 * 1024 * 1024; private static final int UNCOMPRESSED_PACKET_BYTE_LIMIT = 16 * 1024 * 1024;
private static final int OPERATION_BYTE_LIMIT = 2 * 1024; private static final int OPERATION_BYTE_LIMIT = 2 * 1024;
private static final int TEMP_BUFFER_SIZE = 1024;
private static final int STREAM_MASK = 0xff;
// input. // input.
@Nullable @Nullable
@@ -66,47 +59,18 @@ public class MEFluidInventoryUpdatePacket extends BasePacket {
@Nullable @Nullable
private final PacketBuffer data; private final PacketBuffer data;
@Nullable
private final GZIPOutputStream compressFrame;
private int writtenBytes = 0; private int writtenBytes = 0;
private boolean empty = true; private boolean empty = true;
public MEFluidInventoryUpdatePacket(final PacketBuffer stream) { public MEFluidInventoryUpdatePacket(final PacketBuffer stream) {
this.data = null; this.data = null;
this.compressFrame = null;
this.list = new LinkedList<>(); this.list = new LinkedList<>();
this.ref = stream.readByte(); this.ref = stream.readByte();
try (final GZIPInputStream gzReader = new GZIPInputStream(new InputStream() { while (stream.readableBytes() > 0) {
@Override this.list.add(AEFluidStack.fromPacket(stream));
public int read() {
if (stream.readableBytes() <= 0) {
return -1;
}
return stream.readByte() & STREAM_MASK;
}
})) {
final PacketBuffer uncompressed = new PacketBuffer(Unpooled.buffer(stream.readableBytes()));
final byte[] tmp = new byte[TEMP_BUFFER_SIZE];
while (gzReader.available() != 0) {
final int bytes = gzReader.read(tmp);
if (bytes > 0) {
uncompressed.writeBytes(tmp, 0, bytes);
}
}
while (uncompressed.readableBytes() > 0) {
this.list.add(AEFluidStack.fromPacket(uncompressed));
}
} catch (IOException e) {
throw new RuntimeException("Failed to decompress packet.", e);
} }
this.empty = this.list.isEmpty(); this.empty = this.list.isEmpty();
} }
@@ -121,14 +85,6 @@ public class MEFluidInventoryUpdatePacket extends BasePacket {
this.data = new PacketBuffer(Unpooled.buffer(OPERATION_BYTE_LIMIT)); this.data = new PacketBuffer(Unpooled.buffer(OPERATION_BYTE_LIMIT));
this.data.writeInt(this.getPacketID()); this.data.writeInt(this.getPacketID());
this.data.writeByte(this.ref); this.data.writeByte(this.ref);
this.compressFrame = new GZIPOutputStream(new OutputStream() {
@Override
public void write(final int value) {
MEFluidInventoryUpdatePacket.this.data.writeByte(value);
}
});
this.list = null; this.list = null;
} }
@@ -145,28 +101,19 @@ public class MEFluidInventoryUpdatePacket extends BasePacket {
@Nullable @Nullable
@Override @Override
public IPacket<?> toPacket(NetworkDirection direction) { public IPacket<?> toPacket(NetworkDirection direction) {
try { this.configureWrite(this.data);
this.compressFrame.close(); return super.toPacket(direction);
this.configureWrite(this.data);
return super.toPacket(direction);
} catch (final IOException e) {
AELog.debug(e);
}
return null;
} }
public void appendFluid(final IAEFluidStack fs) throws IOException, BufferOverflowException { public void appendFluid(final IAEFluidStack fs) throws IOException, BufferOverflowException {
final PacketBuffer tmp = new PacketBuffer(Unpooled.buffer(OPERATION_BYTE_LIMIT)); final PacketBuffer tmp = new PacketBuffer(Unpooled.buffer(OPERATION_BYTE_LIMIT));
fs.writeToPacket(tmp); fs.writeToPacket(tmp);
this.compressFrame.flush();
if (this.writtenBytes + tmp.readableBytes() > UNCOMPRESSED_PACKET_BYTE_LIMIT) { if (this.writtenBytes + tmp.readableBytes() > UNCOMPRESSED_PACKET_BYTE_LIMIT) {
throw new BufferOverflowException(); throw new BufferOverflowException();
} else { } else {
this.writtenBytes += tmp.readableBytes(); this.writtenBytes += tmp.readableBytes();
this.compressFrame.write(tmp.array(), 0, tmp.readableBytes()); this.data.writeBytes(tmp.array(), 0, tmp.readableBytes());
this.empty = false; this.empty = false;
} }
} }
@@ -18,13 +18,7 @@
package appeng.core.sync.packets; package appeng.core.sync.packets;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@@ -32,7 +26,6 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@@ -41,55 +34,24 @@ import appeng.client.gui.implementations.InterfaceTerminalScreen;
import appeng.core.sync.BasePacket; import appeng.core.sync.BasePacket;
import appeng.core.sync.network.INetworkInfo; import appeng.core.sync.network.INetworkInfo;
//TODO, this is pointless, NBT is already compressed when written to a PacketBuffer. public class MEInterfaceUpdatePacket extends BasePacket {
public class CompressedNBTPacket extends BasePacket {
// input. // input.
private final CompoundNBT in; private final CompoundNBT in;
// output... // output...
private final PacketBuffer data; private final PacketBuffer data;
private final GZIPOutputStream compressFrame;
public CompressedNBTPacket(final PacketBuffer stream) { public MEInterfaceUpdatePacket(final PacketBuffer stream) {
this.data = null; this.data = null;
this.compressFrame = null; this.in = stream.readCompoundTag();
try (DataInputStream inStream = new DataInputStream(new GZIPInputStream(new InputStream() {
@Override
public int read() {
if (stream.readableBytes() <= 0) {
return -1;
}
return stream.readByte() & 0xff;
}
}))) {
this.in = CompressedStreamTools.read(inStream);
} catch (IOException e) {
throw new RuntimeException("Failed to decompress packet.", e);
}
} }
// api // api
public CompressedNBTPacket(final CompoundNBT din) throws IOException { public MEInterfaceUpdatePacket(final CompoundNBT din) throws IOException {
this.in = null;
this.data = new PacketBuffer(Unpooled.buffer(2048)); this.data = new PacketBuffer(Unpooled.buffer(2048));
this.data.writeInt(this.getPacketID()); this.data.writeInt(this.getPacketID());
this.data.writeCompoundTag(din);
this.in = din;
this.compressFrame = new GZIPOutputStream(new OutputStream() {
@Override
public void write(final int value) {
CompressedNBTPacket.this.data.writeByte(value);
}
});
CompressedStreamTools.write(din, new DataOutputStream(this.compressFrame));
this.compressFrame.close();
this.configureWrite(this.data); this.configureWrite(this.data);
} }
@@ -19,12 +19,10 @@
package appeng.core.sync.packets; package appeng.core.sync.packets;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.BufferOverflowException; import java.nio.BufferOverflowException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@@ -45,7 +43,6 @@ import appeng.client.gui.implementations.CraftConfirmScreen;
import appeng.client.gui.implementations.CraftingCPUScreen; import appeng.client.gui.implementations.CraftingCPUScreen;
import appeng.client.gui.implementations.MEMonitorableScreen; import appeng.client.gui.implementations.MEMonitorableScreen;
import appeng.client.gui.implementations.NetworkStatusScreen; import appeng.client.gui.implementations.NetworkStatusScreen;
import appeng.core.AELog;
import appeng.core.sync.BasePacket; import appeng.core.sync.BasePacket;
import appeng.core.sync.network.INetworkInfo; import appeng.core.sync.network.INetworkInfo;
import appeng.util.item.AEItemStack; import appeng.util.item.AEItemStack;
@@ -53,8 +50,6 @@ import appeng.util.item.AEItemStack;
public class MEInventoryUpdatePacket extends BasePacket { public class MEInventoryUpdatePacket extends BasePacket {
private static final int UNCOMPRESSED_PACKET_BYTE_LIMIT = 16 * 1024 * 1024; private static final int UNCOMPRESSED_PACKET_BYTE_LIMIT = 16 * 1024 * 1024;
private static final int OPERATION_BYTE_LIMIT = 2 * 1024; private static final int OPERATION_BYTE_LIMIT = 2 * 1024;
private static final int TEMP_BUFFER_SIZE = 1024;
private static final int STREAM_MASK = 0xff;
// input. // input.
@Nullable @Nullable
@@ -64,48 +59,18 @@ public class MEInventoryUpdatePacket extends BasePacket {
@Nullable @Nullable
private final PacketBuffer data; private final PacketBuffer data;
@Nullable
private final GZIPOutputStream compressFrame;
private int writtenBytes = 0; private int writtenBytes = 0;
private boolean empty = true; private boolean empty = true;
public MEInventoryUpdatePacket(final PacketBuffer stream) { public MEInventoryUpdatePacket(final PacketBuffer stream) {
this.data = null; this.data = null;
this.compressFrame = null;
this.list = new ArrayList<>(); this.list = new ArrayList<>();
this.ref = stream.readByte(); this.ref = stream.readByte();
// int originalBytes = stream.readableBytes(); while (stream.readableBytes() > 0) {
this.list.add(AEItemStack.fromPacket(stream));
try (GZIPInputStream gzReader = new GZIPInputStream(new InputStream() {
@Override
public int read() {
if (stream.readableBytes() <= 0) {
return -1;
}
return stream.readByte() & STREAM_MASK;
}
})) {
final PacketBuffer uncompressed = new PacketBuffer(Unpooled.buffer(stream.readableBytes()));
final byte[] tmp = new byte[TEMP_BUFFER_SIZE];
while (gzReader.available() != 0) {
final int bytes = gzReader.read(tmp);
if (bytes > 0) {
uncompressed.writeBytes(tmp, 0, bytes);
}
}
while (uncompressed.readableBytes() > 0) {
this.list.add(AEItemStack.fromPacket(uncompressed));
}
} catch (IOException e) {
throw new RuntimeException("Failed to decompress packet.", e);
} }
this.empty = this.list.isEmpty(); this.empty = this.list.isEmpty();
} }
@@ -120,14 +85,6 @@ public class MEInventoryUpdatePacket extends BasePacket {
this.data = new PacketBuffer(Unpooled.buffer(OPERATION_BYTE_LIMIT)); this.data = new PacketBuffer(Unpooled.buffer(OPERATION_BYTE_LIMIT));
this.data.writeInt(this.getPacketID()); this.data.writeInt(this.getPacketID());
this.data.writeByte(this.ref); this.data.writeByte(this.ref);
this.compressFrame = new GZIPOutputStream(new OutputStream() {
@Override
public void write(final int value) {
MEInventoryUpdatePacket.this.data.writeByte(value);
}
});
this.list = null; this.list = null;
} }
@@ -156,28 +113,19 @@ public class MEInventoryUpdatePacket extends BasePacket {
@Nullable @Nullable
@Override @Override
public IPacket<?> toPacket(NetworkDirection direction) { public IPacket<?> toPacket(NetworkDirection direction) {
try { this.configureWrite(this.data);
this.compressFrame.close(); return super.toPacket(direction);
this.configureWrite(this.data);
return super.toPacket(direction);
} catch (final IOException e) {
AELog.debug(e);
}
return null;
} }
public void appendItem(final IAEItemStack is) throws IOException, BufferOverflowException { public void appendItem(final IAEItemStack is) throws IOException, BufferOverflowException {
final PacketBuffer tmp = new PacketBuffer(Unpooled.buffer(OPERATION_BYTE_LIMIT)); final PacketBuffer tmp = new PacketBuffer(Unpooled.buffer(OPERATION_BYTE_LIMIT));
is.writeToPacket(tmp); is.writeToPacket(tmp);
this.compressFrame.flush();
if (this.writtenBytes + tmp.readableBytes() > UNCOMPRESSED_PACKET_BYTE_LIMIT) { if (this.writtenBytes + tmp.readableBytes() > UNCOMPRESSED_PACKET_BYTE_LIMIT) {
throw new BufferOverflowException(); throw new BufferOverflowException();
} else { } else {
this.writtenBytes += tmp.readableBytes(); this.writtenBytes += tmp.readableBytes();
this.compressFrame.write(tmp.array(), 0, tmp.readableBytes()); this.data.writeBytes(tmp.array(), 0, tmp.readableBytes());
this.empty = false; this.empty = false;
} }
} }