Temporary fix for serverside JEI and valueconfig packets.

It's not pretty but should do until we rewrite the packet/network handler.
This commit is contained in:
Gunther De Wachter
2017-07-19 13:50:21 +02:00
parent 6648d18f00
commit 4c272de77f
3 changed files with 26 additions and 3 deletions
@@ -19,6 +19,7 @@
package appeng.core.sync;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import io.netty.buffer.ByteBuf;
@@ -93,6 +94,29 @@ public abstract class AppEngPacket implements Packet
throw new RuntimeException( "Not Implemented" );
}
// TODO: Figure out why Forge/Minecraft on the server sets the stream data buffer to PooledUnsafeDirectByteBuf
public ByteArrayInputStream getPacketByteArray ( ByteBuf stream, int readerIndex, int readableBytes )
{
final ByteArrayInputStream bytes;
if( stream.hasArray() )
{
bytes = new ByteArrayInputStream( stream.array(), readerIndex, readableBytes );
}
else
{
byte[] data = new byte[stream.capacity()];
stream.getBytes( readerIndex, data, 0, readableBytes );
bytes = new ByteArrayInputStream( data );
}
return bytes;
}
public ByteArrayInputStream getPacketByteArray ( ByteBuf stream )
{
return getPacketByteArray( stream, 0, stream.readableBytes() );
}
public void setCallParam( final PacketCallState call )
{
this.caller = call;
@@ -70,7 +70,7 @@ public class PacketJEIRecipe extends AppEngPacket
// automatic.
public PacketJEIRecipe( final ByteBuf stream ) throws IOException
{
final ByteArrayInputStream bytes = new ByteArrayInputStream( stream.array() );
final ByteArrayInputStream bytes = this.getPacketByteArray( stream );
bytes.skip( stream.readerIndex() );
final NBTTagCompound comp = CompressedStreamTools.readCompressed( bytes );
if( comp != null )
@@ -19,7 +19,6 @@
package appeng.core.sync.packets;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -66,7 +65,7 @@ public class PacketValueConfig extends AppEngPacket
// automatic.
public PacketValueConfig( final ByteBuf stream ) throws IOException
{
final DataInputStream dis = new DataInputStream( new ByteArrayInputStream( stream.array(), stream.readerIndex(), stream.readableBytes() ) );
final DataInputStream dis = new DataInputStream( this.getPacketByteArray( stream, stream.readerIndex(), stream.readableBytes() ) );
this.Name = dis.readUTF();
this.Value = dis.readUTF();
// dis.close();