Minecraft 1.16 support + RGB ChatColor preview

This commit is contained in:
md_5
2020-06-24 07:00:00 +10:00
parent 2f54c94372
commit d0fd673b60
36 changed files with 760 additions and 227 deletions

View File

@@ -6,13 +6,13 @@
<parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-proxy</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>BungeeCord-Proxy</name>
@@ -85,12 +85,6 @@
<version>5.0.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>se.llbit</groupId>
<artifactId>jo-nbt</artifactId>
<version>1.3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>

View File

@@ -1,17 +0,0 @@
package net.md_5.bungee;
import net.md_5.bungee.protocol.packet.ClientStatus;
import net.md_5.bungee.protocol.packet.PluginMessage;
import net.md_5.bungee.protocol.packet.Respawn;
public class PacketConstants
{
public static final Respawn DIM1_SWITCH = new Respawn( (byte) 1, 0, (byte) 0, (byte) 0, "default" );
public static final Respawn DIM2_SWITCH = new Respawn( (byte) -1, 0, (byte) 0, (byte) 0, "default" );
public static final ClientStatus CLIENT_LOGIN = new ClientStatus( (byte) 0 );
public static final PluginMessage FORGE_MOD_REQUEST = new PluginMessage( "FML", new byte[]
{
0, 0, 0, 0, 0, 2
}, false );
}

View File

@@ -212,8 +212,8 @@ public class ServerConnector extends PacketHandler
user.setServerEntityId( login.getEntityId() );
// Set tab list size, TODO: what shall we do about packet mutability
Login modLogin = new Login( login.getEntityId(), login.getGameMode(), (byte) login.getDimension(), login.getSeed(), login.getDifficulty(),
(byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType(), login.getViewDistance(), login.isReducedDebugInfo(), login.isNormalRespawn() );
Login modLogin = new Login( login.getEntityId(), login.getGameMode(), login.getPreviousGameMode(), login.getWorldNames(), login.getDimensions(), login.getDimension(), login.getWorldName(), login.getSeed(), login.getDifficulty(),
(byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType(), login.getViewDistance(), login.isReducedDebugInfo(), login.isNormalRespawn(), login.isDebug(), login.isFlat() );
user.unsafe().sendPacket( modLogin );
@@ -259,13 +259,23 @@ public class ServerConnector extends PacketHandler
}
user.setDimensionChange( true );
if ( login.getDimension() == user.getDimension() )
if ( login.getDimension().equals( user.getDimension() ) )
{
user.unsafe().sendPacket( new Respawn( ( login.getDimension() >= 0 ? -1 : 0 ), login.getSeed(), login.getDifficulty(), login.getGameMode(), login.getLevelType() ) );
Object newDim;
String worldName = login.getWorldName();
if ( login.getDimension() instanceof Number )
{
newDim = ( ( (Number) login.getDimension() ).intValue() >= 0 ? -1 : 0 );
} else
{
newDim = worldName = ( "minecraft:overworld".equals( login.getDimension() ) ) ? "minecraft:the_nether" : "minecraft:overworld";
}
user.unsafe().sendPacket( new Respawn( newDim, worldName, login.getSeed(), login.getDifficulty(), login.getGameMode(), login.getPreviousGameMode(), login.getLevelType(), login.isDebug(), login.isFlat(), false ) );
}
user.setServerEntityId( login.getEntityId() );
user.unsafe().sendPacket( new Respawn( login.getDimension(), login.getSeed(), login.getDifficulty(), login.getGameMode(), login.getLevelType() ) );
user.unsafe().sendPacket( new Respawn( login.getDimension(), login.getWorldName(), login.getSeed(), login.getDifficulty(), login.getGameMode(), login.getPreviousGameMode(), login.getLevelType(), login.isDebug(), login.isFlat(), false ) );
if ( user.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_14 )
{
user.unsafe().sendPacket( new ViewDistance( login.getViewDistance() ) );

View File

@@ -84,7 +84,7 @@ public final class UserConnection implements ProxiedPlayer
private ServerConnection server;
@Getter
@Setter
private int dimension;
private Object dimension;
@Getter
@Setter
private boolean dimensionChange = true;

View File

@@ -529,7 +529,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
userCon.setCompressionThreshold( BungeeCord.getInstance().config.getCompressionThreshold() );
userCon.init();
unsafe.sendPacket( new LoginSuccess( getUniqueId().toString(), getName() ) ); // With dashes in between
unsafe.sendPacket( new LoginSuccess( getUniqueId(), getName() ) );
ch.setProtocol( Protocol.GAME );
ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new UpstreamBridge( bungee, userCon ) );

View File

@@ -61,6 +61,8 @@ public abstract class EntityMap
case ProtocolConstants.MINECRAFT_1_15_1:
case ProtocolConstants.MINECRAFT_1_15_2:
return EntityMap_1_15.INSTANCE;
case ProtocolConstants.MINECRAFT_1_16:
return EntityMap_1_16.INSTANCE;
}
throw new RuntimeException( "Version " + version + " has no entity map" );
}

View File

@@ -0,0 +1,187 @@
package net.md_5.bungee.entitymap;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.netty.buffer.ByteBuf;
import java.util.UUID;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.ProtocolConstants;
class EntityMap_1_16 extends EntityMap
{
static final EntityMap_1_16 INSTANCE = new EntityMap_1_16();
EntityMap_1_16()
{
addRewrite( 0x00, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Object : PacketPlayOutSpawnEntity
addRewrite( 0x01, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Experience Orb : PacketPlayOutSpawnEntityExperienceOrb
addRewrite( 0x02, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Mob : PacketPlayOutSpawnEntityLiving
addRewrite( 0x03, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Painting : PacketPlayOutSpawnEntityPainting
addRewrite( 0x04, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Player : PacketPlayOutNamedEntitySpawn
addRewrite( 0x05, ProtocolConstants.Direction.TO_CLIENT, true ); // Animation : PacketPlayOutAnimation
addRewrite( 0x08, ProtocolConstants.Direction.TO_CLIENT, true ); // Block Break Animation : PacketPlayOutBlockBreakAnimation
addRewrite( 0x1B, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Status : PacketPlayOutEntityStatus
addRewrite( 0x28, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Relative Move : PacketPlayOutRelEntityMove
addRewrite( 0x29, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Look and Relative Move : PacketPlayOutRelEntityMoveLook
addRewrite( 0x2A, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Look : PacketPlayOutEntityLook
addRewrite( 0x2B, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity : PacketPlayOutEntity
addRewrite( 0x38, ProtocolConstants.Direction.TO_CLIENT, true ); // Remove Entity Effect : PacketPlayOutRemoveEntityEffect
addRewrite( 0x3B, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Head Look : PacketPlayOutEntityHeadRotation
addRewrite( 0x3E, ProtocolConstants.Direction.TO_CLIENT, true ); // Camera : PacketPlayOutCamera
addRewrite( 0x44, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Metadata : PacketPlayOutEntityMetadata
addRewrite( 0x45, ProtocolConstants.Direction.TO_CLIENT, false ); // Attach Entity : PacketPlayOutAttachEntity
addRewrite( 0x46, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Velocity : PacketPlayOutEntityVelocity
addRewrite( 0x47, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Equipment : PacketPlayOutEntityEquipment
addRewrite( 0x4B, ProtocolConstants.Direction.TO_CLIENT, true ); // Set Passengers : PacketPlayOutMount
addRewrite( 0x55, ProtocolConstants.Direction.TO_CLIENT, true ); // Collect Item : PacketPlayOutCollect
addRewrite( 0x56, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Teleport : PacketPlayOutEntityTeleport
addRewrite( 0x58, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Properties : PacketPlayOutUpdateAttributes
addRewrite( 0x59, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Effect : PacketPlayOutEntityEffect
addRewrite( 0x0E, ProtocolConstants.Direction.TO_SERVER, true ); // Use Entity : PacketPlayInUseEntity
addRewrite( 0x1C, ProtocolConstants.Direction.TO_SERVER, true ); // Entity Action : PacketPlayInEntityAction
}
@Override
@SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
public void rewriteClientbound(ByteBuf packet, int oldId, int newId, int protocolVersion)
{
super.rewriteClientbound( packet, oldId, newId );
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
int jumpIndex = packet.readerIndex();
switch ( packetId )
{
case 0x45 /* Attach Entity : PacketPlayOutAttachEntity */:
rewriteInt( packet, oldId, newId, readerIndex + packetIdLength + 4 );
break;
case 0x55 /* Collect Item : PacketPlayOutCollect */:
DefinedPacket.readVarInt( packet );
rewriteVarInt( packet, oldId, newId, packet.readerIndex() );
break;
case 0x4B /* Set Passengers : PacketPlayOutMount */:
DefinedPacket.readVarInt( packet );
jumpIndex = packet.readerIndex();
// Fall through on purpose to int array of IDs
case 0x37 /* Destroy Entities : PacketPlayOutEntityDestroy */:
int count = DefinedPacket.readVarInt( packet );
int[] ids = new int[ count ];
for ( int i = 0; i < count; i++ )
{
ids[i] = DefinedPacket.readVarInt( packet );
}
packet.readerIndex( jumpIndex );
packet.writerIndex( jumpIndex );
DefinedPacket.writeVarInt( count, packet );
for ( int id : ids )
{
if ( id == oldId )
{
id = newId;
} else if ( id == newId )
{
id = oldId;
}
DefinedPacket.writeVarInt( id, packet );
}
break;
case 0x00 /* Spawn Object : PacketPlayOutSpawnEntity */:
DefinedPacket.readVarInt( packet );
DefinedPacket.readUUID( packet );
int type = DefinedPacket.readVarInt( packet );
if ( type == 2 || type == 102 || type == 72 ) // arrow, fishing_bobber or spectral_arrow
{
if ( type == 2 || type == 72 ) // arrow or spectral_arrow
{
oldId = oldId + 1;
newId = newId + 1;
}
packet.skipBytes( 26 ); // double, double, double, byte, byte
int position = packet.readerIndex();
int readId = packet.readInt();
if ( readId == oldId )
{
packet.setInt( position, newId );
} else if ( readId == newId )
{
packet.setInt( position, oldId );
}
}
break;
case 0x04 /* Spawn Player : PacketPlayOutNamedEntitySpawn */:
DefinedPacket.readVarInt( packet ); // Entity ID
int idLength = packet.readerIndex() - readerIndex - packetIdLength;
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
if ( ( player = BungeeCord.getInstance().getPlayerByOfflineUUID( uuid ) ) != null )
{
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength + idLength );
DefinedPacket.writeUUID( player.getUniqueId(), packet );
packet.writerIndex( previous );
}
break;
case 0x32 /* Combat Event : PacketPlayOutCombatEvent */:
int event = packet.readUnsignedByte();
if ( event == 1 /* End Combat*/ )
{
DefinedPacket.readVarInt( packet );
rewriteInt( packet, oldId, newId, packet.readerIndex() );
} else if ( event == 2 /* Entity Dead */ )
{
int position = packet.readerIndex();
rewriteVarInt( packet, oldId, newId, packet.readerIndex() );
packet.readerIndex( position );
DefinedPacket.readVarInt( packet );
rewriteInt( packet, oldId, newId, packet.readerIndex() );
}
break;
case 0x44 /* EntityMetadata : PacketPlayOutEntityMetadata */:
DefinedPacket.readVarInt( packet ); // Entity ID
rewriteMetaVarInt( packet, oldId + 1, newId + 1, 7, protocolVersion ); // fishing hook
rewriteMetaVarInt( packet, oldId, newId, 8, protocolVersion ); // fireworks (et al)
rewriteMetaVarInt( packet, oldId, newId, 16, protocolVersion ); // guardian beam
break;
case 0x50 /* Entity Sound Effect : PacketPlayOutEntitySound */:
DefinedPacket.readVarInt( packet );
DefinedPacket.readVarInt( packet );
rewriteVarInt( packet, oldId, newId, packet.readerIndex() );
break;
}
packet.readerIndex( readerIndex );
}
@Override
public void rewriteServerbound(ByteBuf packet, int oldId, int newId)
{
super.rewriteServerbound( packet, oldId, newId );
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
if ( packetId == 0x2C /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
{
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
if ( ( player = BungeeCord.getInstance().getPlayer( uuid ) ) != null )
{
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength );
DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet );
packet.writerIndex( previous );
}
}
packet.readerIndex( readerIndex );
}
}