use of com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.WorldNameTracker in project ViaBackwards by ViaVersion.
the class EntityPackets1_16 method registerPackets.
@Override
protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_16.SPAWN_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity id
map(Type.VAR_INT);
// 1 - Entity UUID
map(Type.UUID);
// 2 - Entity Type
map(Type.VAR_INT);
// 3 - X
map(Type.DOUBLE);
// 4 - Y
map(Type.DOUBLE);
// 5 - Z
map(Type.DOUBLE);
// 6 - Pitch
map(Type.BYTE);
// 7 - Yaw
map(Type.BYTE);
// 8 - Data
map(Type.INT);
handler(wrapper -> {
EntityType entityType = typeFromId(wrapper.get(Type.VAR_INT, 1));
if (entityType == Entity1_16Types.LIGHTNING_BOLT) {
// Map to old weather entity packet
wrapper.cancel();
PacketWrapper spawnLightningPacket = wrapper.create(ClientboundPackets1_15.SPAWN_GLOBAL_ENTITY);
// Entity id
spawnLightningPacket.write(Type.VAR_INT, wrapper.get(Type.VAR_INT, 0));
// Lightning type
spawnLightningPacket.write(Type.BYTE, (byte) 1);
// X
spawnLightningPacket.write(Type.DOUBLE, wrapper.get(Type.DOUBLE, 0));
// Y
spawnLightningPacket.write(Type.DOUBLE, wrapper.get(Type.DOUBLE, 1));
// Z
spawnLightningPacket.write(Type.DOUBLE, wrapper.get(Type.DOUBLE, 2));
spawnLightningPacket.send(Protocol1_15_2To1_16.class);
}
});
handler(getSpawnTrackerWithDataHandler(Entity1_16Types.FALLING_BLOCK));
}
});
registerSpawnTracker(ClientboundPackets1_16.SPAWN_MOB);
protocol.registerClientbound(ClientboundPackets1_16.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
// Dimension Type
map(dimensionTransformer);
handler(wrapper -> {
// Grab the tracker for world names
WorldNameTracker worldNameTracker = wrapper.user().get(WorldNameTracker.class);
// World Name
String nextWorldName = wrapper.read(Type.STRING);
// Seed
wrapper.passthrough(Type.LONG);
// Gamemode
wrapper.passthrough(Type.UNSIGNED_BYTE);
// Previous gamemode
wrapper.read(Type.BYTE);
// Grab client world
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimension = wrapper.get(Type.INT, 0);
// Send a dummy respawn with a different dimension if the world name was different and the same dimension was used
if (clientWorld.getEnvironment() != null && dimension == clientWorld.getEnvironment().getId() && (wrapper.user().isClientSide() || Via.getPlatform().isProxy() || // Hotfix for https://github.com/ViaVersion/ViaBackwards/issues/381
wrapper.user().getProtocolInfo().getProtocolVersion() <= ProtocolVersion.v1_12_2.getVersion() || !nextWorldName.equals(worldNameTracker.getWorldName()))) {
PacketWrapper packet = wrapper.create(ClientboundPackets1_15.RESPAWN);
packet.write(Type.INT, dimension == 0 ? -1 : 0);
packet.write(Type.LONG, 0L);
packet.write(Type.UNSIGNED_BYTE, (short) 0);
packet.write(Type.STRING, "default");
packet.send(Protocol1_15_2To1_16.class);
}
clientWorld.setEnvironment(dimension);
// Level type
wrapper.write(Type.STRING, "default");
// Debug
wrapper.read(Type.BOOLEAN);
if (wrapper.read(Type.BOOLEAN)) {
wrapper.set(Type.STRING, 0, "flat");
}
// Keep all playerdata
wrapper.read(Type.BOOLEAN);
// Finally update the world name
worldNameTracker.setWorldName(nextWorldName);
});
}
});
protocol.registerClientbound(ClientboundPackets1_16.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// Entity ID
map(Type.INT);
// Gamemode
map(Type.UNSIGNED_BYTE);
// Previous gamemode
map(Type.BYTE, Type.NOTHING);
// World list
map(Type.STRING_ARRAY, Type.NOTHING);
// whatever this is
map(Type.NBT, Type.NOTHING);
// Dimension Type
map(dimensionTransformer);
handler(wrapper -> {
WorldNameTracker worldNameTracker = wrapper.user().get(WorldNameTracker.class);
// Save the world name
worldNameTracker.setWorldName(wrapper.read(Type.STRING));
});
// Seed
map(Type.LONG);
// Max players
map(Type.UNSIGNED_BYTE);
handler(wrapper -> {
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
clientChunks.setEnvironment(wrapper.get(Type.INT, 1));
tracker(wrapper.user()).addEntity(wrapper.get(Type.INT, 0), Entity1_16Types.PLAYER);
// Level type
wrapper.write(Type.STRING, "default");
// View distance
wrapper.passthrough(Type.VAR_INT);
// Reduced debug info
wrapper.passthrough(Type.BOOLEAN);
// Show death screen
wrapper.passthrough(Type.BOOLEAN);
// Debug
wrapper.read(Type.BOOLEAN);
if (wrapper.read(Type.BOOLEAN)) {
wrapper.set(Type.STRING, 0, "flat");
}
});
}
});
registerTracker(ClientboundPackets1_16.SPAWN_EXPERIENCE_ORB, Entity1_16Types.EXPERIENCE_ORB);
// F Spawn Global Object, it is no longer with us :(
registerTracker(ClientboundPackets1_16.SPAWN_PAINTING, Entity1_16Types.PAINTING);
registerTracker(ClientboundPackets1_16.SPAWN_PLAYER, Entity1_16Types.PLAYER);
registerRemoveEntities(ClientboundPackets1_16.DESTROY_ENTITIES);
registerMetadataRewriter(ClientboundPackets1_16.ENTITY_METADATA, Types1_16.METADATA_LIST, Types1_14.METADATA_LIST);
protocol.registerClientbound(ClientboundPackets1_16.ENTITY_PROPERTIES, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.passthrough(Type.VAR_INT);
int size = wrapper.passthrough(Type.INT);
for (int i = 0; i < size; i++) {
String attributeIdentifier = wrapper.read(Type.STRING);
String oldKey = protocol.getMappingData().getAttributeMappings().get(attributeIdentifier);
wrapper.write(Type.STRING, oldKey != null ? oldKey : attributeIdentifier.replace("minecraft:", ""));
wrapper.passthrough(Type.DOUBLE);
int modifierSize = wrapper.passthrough(Type.VAR_INT);
for (int j = 0; j < modifierSize; j++) {
wrapper.passthrough(Type.UUID);
wrapper.passthrough(Type.DOUBLE);
wrapper.passthrough(Type.BYTE);
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_16.PLAYER_INFO, new PacketRemapper() {
@Override
public void registerMap() {
handler(packetWrapper -> {
int action = packetWrapper.passthrough(Type.VAR_INT);
int playerCount = packetWrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < playerCount; i++) {
packetWrapper.passthrough(Type.UUID);
if (action == 0) {
// Add
packetWrapper.passthrough(Type.STRING);
int properties = packetWrapper.passthrough(Type.VAR_INT);
for (int j = 0; j < properties; j++) {
packetWrapper.passthrough(Type.STRING);
packetWrapper.passthrough(Type.STRING);
if (packetWrapper.passthrough(Type.BOOLEAN)) {
packetWrapper.passthrough(Type.STRING);
}
}
packetWrapper.passthrough(Type.VAR_INT);
packetWrapper.passthrough(Type.VAR_INT);
if (packetWrapper.passthrough(Type.BOOLEAN)) {
// Display Name
protocol.getTranslatableRewriter().processText(packetWrapper.passthrough(Type.COMPONENT));
}
} else if (action == 1) {
// Update Game Mode
packetWrapper.passthrough(Type.VAR_INT);
} else if (action == 2) {
// Update Ping
packetWrapper.passthrough(Type.VAR_INT);
} else if (action == 3) {
// Update Display Name
if (packetWrapper.passthrough(Type.BOOLEAN)) {
// Display name
protocol.getTranslatableRewriter().processText(packetWrapper.passthrough(Type.COMPONENT));
}
}
// 4 = Remove Player
}
});
}
});
}
use of com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.WorldNameTracker in project ViaBackwards by ViaVersion.
the class Protocol1_15_2To1_16 method init.
@Override
public void init(UserConnection user) {
if (!user.has(ClientWorld.class)) {
user.put(new ClientWorld(user));
}
user.put(new PlayerSneakStorage());
user.put(new WorldNameTracker());
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_16Types.PLAYER, true));
}
Aggregations