use of com.viaversion.viaversion.api.type.types.version.Types1_14 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.viaversion.api.type.types.version.Types1_14 in project ViaBackwards by ViaVersion.
the class EntityPackets1_15 method registerPackets.
@Override
protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_15.UPDATE_HEALTH, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
float health = wrapper.passthrough(Type.FLOAT);
if (health > 0)
return;
if (!wrapper.user().get(ImmediateRespawn.class).isImmediateRespawn())
return;
// Instantly request respawn when 1.15 gamerule is set
PacketWrapper statusPacket = wrapper.create(ServerboundPackets1_14.CLIENT_STATUS);
statusPacket.write(Type.VAR_INT, 0);
statusPacket.sendToServer(Protocol1_14_4To1_15.class);
});
}
});
protocol.registerClientbound(ClientboundPackets1_15.GAME_EVENT, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE);
map(Type.FLOAT);
handler(wrapper -> {
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 11) {
wrapper.user().get(ImmediateRespawn.class).setImmediateRespawn(wrapper.get(Type.FLOAT, 0) == 1);
}
});
}
});
registerTrackerWithData(ClientboundPackets1_15.SPAWN_ENTITY, Entity1_15Types.FALLING_BLOCK);
protocol.registerClientbound(ClientboundPackets1_15.SPAWN_MOB, 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 - Yaw
map(Type.BYTE);
// 7 - Pitch
map(Type.BYTE);
// 8 - Head Pitch
map(Type.BYTE);
// 9 - Velocity X
map(Type.SHORT);
// 10 - Velocity Y
map(Type.SHORT);
// 11 - Velocity Z
map(Type.SHORT);
// Metadata is no longer sent in 1.15, so we have to send an empty one
handler(wrapper -> wrapper.write(Types1_14.METADATA_LIST, new ArrayList<>()));
handler(wrapper -> {
int type = wrapper.get(Type.VAR_INT, 1);
EntityType entityType = Entity1_15Types.getTypeFromId(type);
tracker(wrapper.user()).addEntity(wrapper.get(Type.VAR_INT, 0), entityType);
wrapper.set(Type.VAR_INT, 1, EntityTypeMapping.getOldEntityId(type));
});
}
});
protocol.registerClientbound(ClientboundPackets1_15.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT);
// Seed
map(Type.LONG, Type.NOTHING);
}
});
protocol.registerClientbound(ClientboundPackets1_15.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.INT);
// 1 - Gamemode
map(Type.UNSIGNED_BYTE);
// 2 - Dimension
map(Type.INT);
// Seed
map(Type.LONG, Type.NOTHING);
// 3 - Max Players
map(Type.UNSIGNED_BYTE);
// 4 - Level Type
map(Type.STRING);
// 5 - View Distance
map(Type.VAR_INT);
// 6 - Reduce Debug Info
map(Type.BOOLEAN);
handler(getTrackerHandler(Entity1_15Types.PLAYER, Type.INT));
handler(wrapper -> {
// Inverted
boolean immediateRespawn = !wrapper.read(Type.BOOLEAN);
wrapper.user().get(ImmediateRespawn.class).setImmediateRespawn(immediateRespawn);
});
}
});
registerTracker(ClientboundPackets1_15.SPAWN_EXPERIENCE_ORB, Entity1_15Types.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_15.SPAWN_GLOBAL_ENTITY, Entity1_15Types.LIGHTNING_BOLT);
registerTracker(ClientboundPackets1_15.SPAWN_PAINTING, Entity1_15Types.PAINTING);
protocol.registerClientbound(ClientboundPackets1_15.SPAWN_PLAYER, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.VAR_INT);
// 1 - Player UUID
map(Type.UUID);
// 2 - X
map(Type.DOUBLE);
// 3 - Y
map(Type.DOUBLE);
// 4 - Z
map(Type.DOUBLE);
// 5 - Yaw
map(Type.BYTE);
// 6 - Pitch
map(Type.BYTE);
// Metadata is no longer sent in 1.15, so we have to send an empty one
handler(wrapper -> wrapper.write(Types1_14.METADATA_LIST, new ArrayList<>()));
handler(getTrackerHandler(Entity1_15Types.PLAYER, Type.VAR_INT));
}
});
registerRemoveEntities(ClientboundPackets1_15.DESTROY_ENTITIES);
registerMetadataRewriter(ClientboundPackets1_15.ENTITY_METADATA, Types1_14.METADATA_LIST);
// Attributes (get rid of generic.flyingSpeed for the Bee remap)
protocol.registerClientbound(ClientboundPackets1_15.ENTITY_PROPERTIES, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.INT);
handler(wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
EntityType entityType = tracker(wrapper.user()).entityType(entityId);
if (entityType != Entity1_15Types.BEE)
return;
int size = wrapper.get(Type.INT, 0);
int newSize = size;
for (int i = 0; i < size; i++) {
String key = wrapper.read(Type.STRING);
if (key.equals("generic.flyingSpeed")) {
newSize--;
wrapper.read(Type.DOUBLE);
int modSize = wrapper.read(Type.VAR_INT);
for (int j = 0; j < modSize; j++) {
wrapper.read(Type.UUID);
wrapper.read(Type.DOUBLE);
wrapper.read(Type.BYTE);
}
} else {
wrapper.write(Type.STRING, key);
wrapper.passthrough(Type.DOUBLE);
int modSize = wrapper.passthrough(Type.VAR_INT);
for (int j = 0; j < modSize; j++) {
wrapper.passthrough(Type.UUID);
wrapper.passthrough(Type.DOUBLE);
wrapper.passthrough(Type.BYTE);
}
}
}
if (newSize != size) {
wrapper.set(Type.INT, 0, newSize);
}
});
}
});
}
use of com.viaversion.viaversion.api.type.types.version.Types1_14 in project ViaVersion by ViaVersion.
the class EntityPackets method register.
public static void register(Protocol1_15To1_14_4 protocol) {
MetadataRewriter1_15To1_14_4 metadataRewriter = protocol.get(MetadataRewriter1_15To1_14_4.class);
metadataRewriter.registerTrackerWithData(ClientboundPackets1_14.SPAWN_ENTITY, Entity1_15Types.FALLING_BLOCK);
protocol.registerClientbound(ClientboundPackets1_14.SPAWN_MOB, 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 - Yaw
map(Type.BYTE);
// 7 - Pitch
map(Type.BYTE);
// 8 - Head Pitch
map(Type.BYTE);
// 9 - Velocity X
map(Type.SHORT);
// 10 - Velocity Y
map(Type.SHORT);
// 11 - Velocity Z
map(Type.SHORT);
handler(metadataRewriter.trackerHandler());
handler(wrapper -> sendMetadataPacket(wrapper, wrapper.get(Type.VAR_INT, 0), metadataRewriter));
}
});
protocol.registerClientbound(ClientboundPackets1_14.SPAWN_PLAYER, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.VAR_INT);
// 1 - Player UUID
map(Type.UUID);
// 2 - X
map(Type.DOUBLE);
// 3 - Y
map(Type.DOUBLE);
// 4 - Z
map(Type.DOUBLE);
// 5 - Yaw
map(Type.BYTE);
// 6 - Pitch
map(Type.BYTE);
handler(wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
wrapper.user().getEntityTracker(Protocol1_15To1_14_4.class).addEntity(entityId, Entity1_15Types.PLAYER);
sendMetadataPacket(wrapper, entityId, metadataRewriter);
});
}
});
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_14.ENTITY_METADATA, Types1_14.METADATA_LIST);
metadataRewriter.registerRemoveEntities(ClientboundPackets1_14.DESTROY_ENTITIES);
}
use of com.viaversion.viaversion.api.type.types.version.Types1_14 in project ViaBackwards by ViaVersion.
the class EntityPackets1_14 method registerPackets.
@Override
protected void registerPackets() {
positionHandler = new EntityPositionHandler(this, EntityPositionStorage1_14.class, EntityPositionStorage1_14::new);
protocol.registerClientbound(ClientboundPackets1_14.ENTITY_STATUS, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int entityId = wrapper.passthrough(Type.INT);
byte status = wrapper.passthrough(Type.BYTE);
// Check for death status
if (status != 3)
return;
EntityTracker tracker = tracker(wrapper.user());
EntityType entityType = tracker.entityType(entityId);
if (entityType != Entity1_14Types.PLAYER)
return;
// Remove equipment, else the client will see ghost items
for (int i = 0; i <= 5; i++) {
PacketWrapper equipmentPacket = wrapper.create(ClientboundPackets1_13.ENTITY_EQUIPMENT);
equipmentPacket.write(Type.VAR_INT, entityId);
equipmentPacket.write(Type.VAR_INT, i);
equipmentPacket.write(Type.FLAT_VAR_INT_ITEM, null);
equipmentPacket.send(Protocol1_13_2To1_14.class);
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_14.ENTITY_TELEPORT, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.DOUBLE);
map(Type.DOUBLE);
map(Type.DOUBLE);
handler(wrapper -> positionHandler.cacheEntityPosition(wrapper, false, false));
}
});
PacketRemapper relativeMoveHandler = new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.SHORT);
map(Type.SHORT);
map(Type.SHORT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
double x = wrapper.get(Type.SHORT, 0) / EntityPositionHandler.RELATIVE_MOVE_FACTOR;
double y = wrapper.get(Type.SHORT, 1) / EntityPositionHandler.RELATIVE_MOVE_FACTOR;
double z = wrapper.get(Type.SHORT, 2) / EntityPositionHandler.RELATIVE_MOVE_FACTOR;
positionHandler.cacheEntityPosition(wrapper, x, y, z, false, true);
}
});
}
};
protocol.registerClientbound(ClientboundPackets1_14.ENTITY_POSITION, relativeMoveHandler);
protocol.registerClientbound(ClientboundPackets1_14.ENTITY_POSITION_AND_ROTATION, relativeMoveHandler);
protocol.registerClientbound(ClientboundPackets1_14.SPAWN_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity id
map(Type.VAR_INT);
// 1 - UUID
map(Type.UUID);
// 2 - Type
map(Type.VAR_INT, Type.BYTE);
// 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);
// 9 - Velocity X
map(Type.SHORT);
// 10 - Velocity Y
map(Type.SHORT);
// 11 - Velocity Z
map(Type.SHORT);
handler(getObjectTrackerHandler());
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.BYTE, 0);
int mappedId = newEntityId(id);
Entity1_13Types.EntityType entityType = Entity1_13Types.getTypeFromId(mappedId, false);
Entity1_13Types.ObjectType objectType;
if (entityType.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT)) {
objectType = Entity1_13Types.ObjectType.MINECART;
int data = 0;
switch(entityType) {
case CHEST_MINECART:
data = 1;
break;
case FURNACE_MINECART:
data = 2;
break;
case TNT_MINECART:
data = 3;
break;
case SPAWNER_MINECART:
data = 4;
break;
case HOPPER_MINECART:
data = 5;
break;
case COMMAND_BLOCK_MINECART:
data = 6;
break;
}
if (data != 0)
wrapper.set(Type.INT, 0, data);
} else {
objectType = Entity1_13Types.ObjectType.fromEntityType(entityType).orElse(null);
}
if (objectType == null)
return;
wrapper.set(Type.BYTE, 0, (byte) objectType.getId());
int data = wrapper.get(Type.INT, 0);
if (objectType == Entity1_13Types.ObjectType.FALLING_BLOCK) {
int blockState = wrapper.get(Type.INT, 0);
int combined = protocol.getMappingData().getNewBlockStateId(blockState);
wrapper.set(Type.INT, 0, combined);
} else if (entityType.isOrHasParent(Entity1_13Types.EntityType.ABSTRACT_ARROW)) {
wrapper.set(Type.INT, 0, data + 1);
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_14.SPAWN_MOB, 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 - Yaw
map(Type.BYTE);
// 7 - Pitch
map(Type.BYTE);
// 8 - Head Pitch
map(Type.BYTE);
// 9 - Velocity X
map(Type.SHORT);
// 10 - Velocity Y
map(Type.SHORT);
// 11 - Velocity Z
map(Type.SHORT);
// 12 - Metadata
map(Types1_14.METADATA_LIST, Types1_13_2.METADATA_LIST);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int type = wrapper.get(Type.VAR_INT, 1);
EntityType entityType = Entity1_14Types.getTypeFromId(type);
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType);
int oldId = newEntityId(type);
if (oldId == -1) {
EntityData entityData = entityDataForType(entityType);
if (entityData == null) {
ViaBackwards.getPlatform().getLogger().warning("Could not find 1.13.2 entity type for 1.14 entity type " + type + "/" + entityType);
wrapper.cancel();
} else {
wrapper.set(Type.VAR_INT, 1, entityData.replacementId());
}
} else {
wrapper.set(Type.VAR_INT, 1, oldId);
}
}
});
// Handle entity type & metadata
handler(getMobSpawnRewriter(Types1_13_2.METADATA_LIST));
}
});
protocol.registerClientbound(ClientboundPackets1_14.SPAWN_EXPERIENCE_ORB, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity id
map(Type.VAR_INT);
// Needs to be mapped for the position cache
map(Type.DOUBLE);
map(Type.DOUBLE);
map(Type.DOUBLE);
handler(wrapper -> addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), Entity1_14Types.EXPERIENCE_ORB));
}
});
protocol.registerClientbound(ClientboundPackets1_14.SPAWN_GLOBAL_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity id
map(Type.VAR_INT);
map(Type.BYTE);
// Needs to be mapped for the position cache
map(Type.DOUBLE);
map(Type.DOUBLE);
map(Type.DOUBLE);
handler(wrapper -> addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), Entity1_14Types.LIGHTNING_BOLT));
}
});
protocol.registerClientbound(ClientboundPackets1_14.SPAWN_PAINTING, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.UUID);
map(Type.VAR_INT);
map(Type.POSITION1_14, Type.POSITION);
map(Type.BYTE);
// Track entity
handler(wrapper -> addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), Entity1_14Types.PAINTING));
}
});
protocol.registerClientbound(ClientboundPackets1_14.SPAWN_PLAYER, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.VAR_INT);
// 1 - Player UUID
map(Type.UUID);
// 2 - X
map(Type.DOUBLE);
// 3 - Y
map(Type.DOUBLE);
// 4 - Z
map(Type.DOUBLE);
// 5 - Yaw
map(Type.BYTE);
// 6 - Pitch
map(Type.BYTE);
// 7 - Metadata
map(Types1_14.METADATA_LIST, Types1_13_2.METADATA_LIST);
handler(getTrackerAndMetaHandler(Types1_13_2.METADATA_LIST, Entity1_14Types.PLAYER));
handler(wrapper -> positionHandler.cacheEntityPosition(wrapper, true, false));
}
});
registerRemoveEntities(ClientboundPackets1_14.DESTROY_ENTITIES);
registerMetadataRewriter(ClientboundPackets1_14.ENTITY_METADATA, Types1_14.METADATA_LIST, Types1_13_2.METADATA_LIST);
protocol.registerClientbound(ClientboundPackets1_14.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.INT);
// 1 - Gamemode
map(Type.UNSIGNED_BYTE);
// 2 - Dimension
map(Type.INT);
handler(getTrackerHandler(Entity1_14Types.PLAYER, Type.INT));
handler(getDimensionHandler(1));
handler(wrapper -> {
short difficulty = wrapper.user().get(DifficultyStorage.class).getDifficulty();
wrapper.write(Type.UNSIGNED_BYTE, difficulty);
// Max Players
wrapper.passthrough(Type.UNSIGNED_BYTE);
// Level Type
wrapper.passthrough(Type.STRING);
// Read View Distance
wrapper.read(Type.VAR_INT);
// TODO Track client position
// Manually add position storage
/*int entitiyId = wrapper.get(Type.INT, 0);
StoredEntityData storedEntity = protocol.getEntityRewriter().tracker(wrapper.user()).entityData(entitiyId);
storedEntity.put(new EntityPositionStorage1_14());*/
});
}
});
protocol.registerClientbound(ClientboundPackets1_14.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Dimension ID
map(Type.INT);
handler(wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 0);
clientWorld.setEnvironment(dimensionId);
short difficulty = wrapper.user().get(DifficultyStorage.class).getDifficulty();
wrapper.write(Type.UNSIGNED_BYTE, difficulty);
wrapper.user().get(ChunkLightStorage.class).clear();
});
}
});
}
use of com.viaversion.viaversion.api.type.types.version.Types1_14 in project ViaVersion by ViaVersion.
the class EntityPackets method register.
public static void register(Protocol1_16To1_15_2 protocol) {
MetadataRewriter1_16To1_15_2 metadataRewriter = protocol.get(MetadataRewriter1_16To1_15_2.class);
// Spawn lightning -> Spawn entity
protocol.registerClientbound(ClientboundPackets1_15.SPAWN_GLOBAL_ENTITY, ClientboundPackets1_16.SPAWN_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int entityId = wrapper.passthrough(Type.VAR_INT);
byte type = wrapper.read(Type.BYTE);
if (type != 1) {
// Cancel if not lightning/invalid id
wrapper.cancel();
return;
}
wrapper.user().getEntityTracker(Protocol1_16To1_15_2.class).addEntity(entityId, Entity1_16Types.LIGHTNING_BOLT);
// uuid
wrapper.write(Type.UUID, UUID.randomUUID());
// entity type
wrapper.write(Type.VAR_INT, Entity1_16Types.LIGHTNING_BOLT.getId());
// x
wrapper.passthrough(Type.DOUBLE);
// y
wrapper.passthrough(Type.DOUBLE);
// z
wrapper.passthrough(Type.DOUBLE);
// yaw
wrapper.write(Type.BYTE, (byte) 0);
// pitch
wrapper.write(Type.BYTE, (byte) 0);
// data
wrapper.write(Type.INT, 0);
// velocity
wrapper.write(Type.SHORT, (short) 0);
// velocity
wrapper.write(Type.SHORT, (short) 0);
// velocity
wrapper.write(Type.SHORT, (short) 0);
});
}
});
metadataRewriter.registerTrackerWithData(ClientboundPackets1_15.SPAWN_ENTITY, Entity1_16Types.FALLING_BLOCK);
metadataRewriter.registerTracker(ClientboundPackets1_15.SPAWN_MOB);
metadataRewriter.registerTracker(ClientboundPackets1_15.SPAWN_PLAYER, Entity1_16Types.PLAYER);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_15.ENTITY_METADATA, Types1_14.METADATA_LIST, Types1_16.METADATA_LIST);
metadataRewriter.registerRemoveEntities(ClientboundPackets1_15.DESTROY_ENTITIES);
protocol.registerClientbound(ClientboundPackets1_15.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
handler(DIMENSION_HANDLER);
// Seed
map(Type.LONG);
// Gamemode
map(Type.UNSIGNED_BYTE);
handler(wrapper -> {
// Previous gamemode, set to none
wrapper.write(Type.BYTE, (byte) -1);
String levelType = wrapper.read(Type.STRING);
// debug
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.BOOLEAN, levelType.equals("flat"));
// keep all playerdata
wrapper.write(Type.BOOLEAN, true);
});
}
});
protocol.registerClientbound(ClientboundPackets1_15.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// Entity ID
map(Type.INT);
// Gamemode
map(Type.UNSIGNED_BYTE);
handler(wrapper -> {
// Previous gamemode, set to none
wrapper.write(Type.BYTE, (byte) -1);
// World list - only used for command completion
wrapper.write(Type.STRING_ARRAY, Arrays.copyOf(WORLD_NAMES, WORLD_NAMES.length));
// Dimension registry
wrapper.write(Type.NBT, DIMENSIONS_TAG.clone());
});
// Dimension
handler(DIMENSION_HANDLER);
// Seed
map(Type.LONG);
// Max players
map(Type.UNSIGNED_BYTE);
handler(wrapper -> {
wrapper.user().getEntityTracker(Protocol1_16To1_15_2.class).addEntity(wrapper.get(Type.INT, 0), Entity1_16Types.PLAYER);
// level type
final String type = wrapper.read(Type.STRING);
// View distance
wrapper.passthrough(Type.VAR_INT);
// Reduced debug info
wrapper.passthrough(Type.BOOLEAN);
// Show death screen
wrapper.passthrough(Type.BOOLEAN);
// Debug
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.BOOLEAN, type.equals("flat"));
});
}
});
protocol.registerClientbound(ClientboundPackets1_15.ENTITY_PROPERTIES, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.passthrough(Type.VAR_INT);
int size = wrapper.passthrough(Type.INT);
int actualSize = size;
for (int i = 0; i < size; i++) {
// Attributes have been renamed and are now namespaced identifiers
String key = wrapper.read(Type.STRING);
String attributeIdentifier = protocol.getMappingData().getAttributeMappings().get(key);
if (attributeIdentifier == null) {
attributeIdentifier = "minecraft:" + key;
if (!com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.MappingData.isValid1_13Channel(attributeIdentifier)) {
if (!Via.getConfig().isSuppressConversionWarnings()) {
Via.getPlatform().getLogger().warning("Invalid attribute: " + key);
}
actualSize--;
wrapper.read(Type.DOUBLE);
int modifierSize = wrapper.read(Type.VAR_INT);
for (int j = 0; j < modifierSize; j++) {
wrapper.read(Type.UUID);
wrapper.read(Type.DOUBLE);
wrapper.read(Type.BYTE);
}
continue;
}
}
wrapper.write(Type.STRING, attributeIdentifier);
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);
}
}
if (size != actualSize) {
wrapper.set(Type.INT, 0, actualSize);
}
});
}
});
protocol.registerServerbound(ServerboundPackets1_16.ANIMATION, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
// Don't send an arm swing if the player has an inventory opened.
if (inventoryTracker.getInventory() != -1) {
wrapper.cancel();
}
});
}
});
}
Aggregations