#3810: Use retainedSlice if possible in MinecraftDecoder
This commit is contained in:
parent
26433bf021
commit
1279cca971
@ -12,12 +12,17 @@ import lombok.Setter;
|
|||||||
public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
|
public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public MinecraftDecoder(Protocol protocol, boolean server, int protocolVersion)
|
||||||
|
{
|
||||||
|
this( protocol, server, protocolVersion, shouldCopyBuffer( protocol, protocolVersion ) );
|
||||||
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
|
||||||
private Protocol protocol;
|
private Protocol protocol;
|
||||||
private final boolean server;
|
private final boolean server;
|
||||||
@Setter
|
@Setter
|
||||||
private int protocolVersion;
|
private int protocolVersion;
|
||||||
|
private boolean copyBuffer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
|
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
|
||||||
@ -30,8 +35,7 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
|
|||||||
}
|
}
|
||||||
|
|
||||||
Protocol.DirectionData prot = ( server ) ? protocol.TO_SERVER : protocol.TO_CLIENT;
|
Protocol.DirectionData prot = ( server ) ? protocol.TO_SERVER : protocol.TO_CLIENT;
|
||||||
ByteBuf slice = in.copy(); // Can't slice this one due to EntityMap :(
|
ByteBuf slice = ( copyBuffer ) ? in.copy() : in.retainedSlice();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int packetId = DefinedPacket.readVarInt( in );
|
int packetId = DefinedPacket.readVarInt( in );
|
||||||
@ -60,4 +64,17 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setProtocol(Protocol protocol)
|
||||||
|
{
|
||||||
|
this.protocol = protocol;
|
||||||
|
this.copyBuffer = shouldCopyBuffer( protocol, protocolVersion );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean shouldCopyBuffer(Protocol protocol, int protocolVersion)
|
||||||
|
{
|
||||||
|
// We only use the entity map in game state, we can avoid many buffer copies by checking this
|
||||||
|
// EntityMap is removed for 1.20.2 and up
|
||||||
|
return protocol == Protocol.GAME && protocolVersion < ProtocolConstants.MINECRAFT_1_20_2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,21 +82,9 @@ public abstract class EntityMap
|
|||||||
case ProtocolConstants.MINECRAFT_1_19_4:
|
case ProtocolConstants.MINECRAFT_1_19_4:
|
||||||
case ProtocolConstants.MINECRAFT_1_20:
|
case ProtocolConstants.MINECRAFT_1_20:
|
||||||
return EntityMap_1_16_2.INSTANCE_1_19_4;
|
return EntityMap_1_16_2.INSTANCE_1_19_4;
|
||||||
case ProtocolConstants.MINECRAFT_1_20_2:
|
default:
|
||||||
return EntityMap_1_16_2.INSTANCE_1_20_2;
|
return null;
|
||||||
case ProtocolConstants.MINECRAFT_1_20_3:
|
|
||||||
return EntityMap_1_16_2.INSTANCE_1_20_3;
|
|
||||||
case ProtocolConstants.MINECRAFT_1_20_5:
|
|
||||||
case ProtocolConstants.MINECRAFT_1_21:
|
|
||||||
return EntityMap_1_16_2.INSTANCE_1_20_5;
|
|
||||||
case ProtocolConstants.MINECRAFT_1_21_2:
|
|
||||||
return EntityMap_1_16_2.INSTANCE_1_21_2;
|
|
||||||
case ProtocolConstants.MINECRAFT_1_21_4:
|
|
||||||
return EntityMap_1_16_2.INSTANCE_1_21_4;
|
|
||||||
case ProtocolConstants.MINECRAFT_1_21_5:
|
|
||||||
return EntityMap_1_16_2.INSTANCE_1_21_5;
|
|
||||||
}
|
}
|
||||||
throw new RuntimeException( "Version " + version + " has no entity map" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addRewrite(int id, ProtocolConstants.Direction direction, boolean varint)
|
protected void addRewrite(int id, ProtocolConstants.Direction direction, boolean varint)
|
||||||
|
@ -20,12 +20,6 @@ class EntityMap_1_16_2 extends EntityMap
|
|||||||
static final EntityMap_1_16_2 INSTANCE_1_19 = new EntityMap_1_16_2( 0x02, 0x2F );
|
static final EntityMap_1_16_2 INSTANCE_1_19 = new EntityMap_1_16_2( 0x02, 0x2F );
|
||||||
static final EntityMap_1_16_2 INSTANCE_1_19_1 = new EntityMap_1_16_2( 0x02, 0x30 );
|
static final EntityMap_1_16_2 INSTANCE_1_19_1 = new EntityMap_1_16_2( 0x02, 0x30 );
|
||||||
static final EntityMap_1_16_2 INSTANCE_1_19_4 = new EntityMap_1_16_2( 0x03, 0x30 );
|
static final EntityMap_1_16_2 INSTANCE_1_19_4 = new EntityMap_1_16_2( 0x03, 0x30 );
|
||||||
static final EntityMap_1_16_2 INSTANCE_1_20_2 = new EntityMap_1_16_2( -1, 0x33 );
|
|
||||||
static final EntityMap_1_16_2 INSTANCE_1_20_3 = new EntityMap_1_16_2( -1, 0x34 );
|
|
||||||
static final EntityMap_1_16_2 INSTANCE_1_20_5 = new EntityMap_1_16_2( -1, 0x37 );
|
|
||||||
static final EntityMap_1_16_2 INSTANCE_1_21_2 = new EntityMap_1_16_2( -1, 0x39 );
|
|
||||||
static final EntityMap_1_16_2 INSTANCE_1_21_4 = new EntityMap_1_16_2( -1, 0x3B );
|
|
||||||
static final EntityMap_1_16_2 INSTANCE_1_21_5 = new EntityMap_1_16_2( -1, 0x3C );
|
|
||||||
//
|
//
|
||||||
private final int spawnPlayerId;
|
private final int spawnPlayerId;
|
||||||
private final int spectateId;
|
private final int spectateId;
|
||||||
|
Loading…
Reference in New Issue
Block a user