use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaBackwards by ViaVersion.
the class EntityPackets1_10 method registerPackets.
@Override
protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity id
map(Type.VAR_INT);
// 1 - UUID
map(Type.UUID);
// 2 - Type
map(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);
// Track Entity
handler(getObjectTrackerHandler());
handler(getObjectRewriter(id -> Entity1_11Types.ObjectType.findById(id).orElse(null)));
// Handle FallingBlock blocks
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Optional<Entity1_12Types.ObjectType> type = Entity1_12Types.ObjectType.findById(wrapper.get(Type.BYTE, 0));
if (type.isPresent() && type.get() == Entity1_12Types.ObjectType.FALLING_BLOCK) {
int objectData = wrapper.get(Type.INT, 0);
int objType = objectData & 4095;
int data = objectData >> 12 & 15;
Block block = protocol.getItemRewriter().handleBlock(objType, data);
if (block == null)
return;
wrapper.set(Type.INT, 0, block.getId() | block.getData() << 12);
}
}
});
}
});
registerTracker(ClientboundPackets1_9_3.SPAWN_EXPERIENCE_ORB, Entity1_10Types.EntityType.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_9_3.SPAWN_GLOBAL_ENTITY, Entity1_10Types.EntityType.WEATHER);
protocol.registerClientbound(ClientboundPackets1_9_3.SPAWN_MOB, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity id
map(Type.VAR_INT);
// 1 - UUID
map(Type.UUID);
// 2 - Entity Type
map(Type.UNSIGNED_BYTE);
// 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_9.METADATA_LIST);
// Track entity
handler(getTrackerHandler(Type.UNSIGNED_BYTE, 0));
// Rewrite entity type / metadata
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
EntityType type = tracker(wrapper.user()).entityType(entityId);
List<Metadata> metadata = wrapper.get(Types1_9.METADATA_LIST, 0);
handleMetadata(wrapper.get(Type.VAR_INT, 0), metadata, wrapper.user());
EntityData entityData = entityDataForType(type);
if (entityData != null) {
WrappedMetadata storage = new WrappedMetadata(metadata);
wrapper.set(Type.UNSIGNED_BYTE, 0, (short) entityData.replacementId());
if (entityData.hasBaseMeta())
entityData.defaultMeta().createMeta(storage);
}
}
});
}
});
registerTracker(ClientboundPackets1_9_3.SPAWN_PAINTING, Entity1_10Types.EntityType.PAINTING);
registerJoinGame(ClientboundPackets1_9_3.JOIN_GAME, Entity1_10Types.EntityType.PLAYER);
registerRespawn(ClientboundPackets1_9_3.RESPAWN);
protocol.registerClientbound(ClientboundPackets1_9_3.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 list
map(Types1_9.METADATA_LIST);
handler(getTrackerAndMetaHandler(Types1_9.METADATA_LIST, Entity1_11Types.EntityType.PLAYER));
}
});
registerRemoveEntities(ClientboundPackets1_9_3.DESTROY_ENTITIES);
registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_9.METADATA_LIST);
}
use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaBackwards by ViaVersion.
the class InventoryPackets1_13_1 method registerPackets.
@Override
public void registerPackets() {
registerSetCooldown(ClientboundPackets1_13.COOLDOWN);
registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS, Type.FLAT_ITEM_ARRAY);
registerSetSlot(ClientboundPackets1_13.SET_SLOT, Type.FLAT_ITEM);
protocol.registerClientbound(ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
String channel = wrapper.passthrough(Type.STRING);
if (channel.equals("minecraft:trader_list")) {
// Passthrough Window ID
wrapper.passthrough(Type.INT);
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
// Input Item
Item input = wrapper.passthrough(Type.FLAT_ITEM);
handleItemToClient(input);
// Output Item
Item output = wrapper.passthrough(Type.FLAT_ITEM);
handleItemToClient(output);
// Has second item
boolean secondItem = wrapper.passthrough(Type.BOOLEAN);
if (secondItem) {
// Second Item
Item second = wrapper.passthrough(Type.FLAT_ITEM);
handleItemToClient(second);
}
// Trade disabled
wrapper.passthrough(Type.BOOLEAN);
// Number of tools uses
wrapper.passthrough(Type.INT);
// Maximum number of trade uses
wrapper.passthrough(Type.INT);
}
}
}
});
}
});
registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT, Type.FLAT_ITEM);
registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW, Type.FLAT_ITEM);
registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, Type.FLAT_ITEM);
registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, Type.FLAT_ITEM, Type.FLOAT);
}
use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaBackwards by ViaVersion.
the class Protocol1_14_2To1_14_3 method registerPackets.
@Override
protected void registerPackets() {
registerClientbound(ClientboundPackets1_14.TRADE_LIST, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.passthrough(Type.VAR_INT);
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
if (wrapper.passthrough(Type.BOOLEAN)) {
wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
}
wrapper.passthrough(Type.BOOLEAN);
wrapper.passthrough(Type.INT);
wrapper.passthrough(Type.INT);
wrapper.passthrough(Type.INT);
wrapper.passthrough(Type.INT);
wrapper.passthrough(Type.FLOAT);
}
wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.BOOLEAN);
wrapper.read(Type.BOOLEAN);
}
});
}
});
RecipeRewriter recipeHandler = new RecipeRewriter1_14(this);
registerClientbound(ClientboundPackets1_14.DECLARE_RECIPES, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int size = wrapper.passthrough(Type.VAR_INT);
int deleted = 0;
for (int i = 0; i < size; i++) {
String fullType = wrapper.read(Type.STRING);
String type = fullType.replace("minecraft:", "");
// id
String id = wrapper.read(Type.STRING);
if (type.equals("crafting_special_repairitem")) {
deleted++;
continue;
}
wrapper.write(Type.STRING, fullType);
wrapper.write(Type.STRING, id);
recipeHandler.handle(wrapper, type);
}
wrapper.set(Type.VAR_INT, 0, size - deleted);
});
}
});
}
use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper 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.protocol.remapper.PacketRemapper in project ViaBackwards by ViaVersion.
the class EntityPackets1_14_1 method registerPackets.
@Override
protected void registerPackets() {
registerTracker(ClientboundPackets1_14.SPAWN_EXPERIENCE_ORB, Entity1_14Types.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_14.SPAWN_GLOBAL_ENTITY, Entity1_14Types.LIGHTNING_BOLT);
registerTracker(ClientboundPackets1_14.SPAWN_PAINTING, Entity1_14Types.PAINTING);
registerTracker(ClientboundPackets1_14.SPAWN_PLAYER, Entity1_14Types.PLAYER);
registerTracker(ClientboundPackets1_14.JOIN_GAME, Entity1_14Types.PLAYER, Type.INT);
registerRemoveEntities(ClientboundPackets1_14.DESTROY_ENTITIES);
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);
handler(getTrackerHandler());
}
});
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);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
int type = wrapper.get(Type.VAR_INT, 1);
// Register Type ID
tracker(wrapper.user()).addEntity(entityId, Entity1_14Types.getTypeFromId(type));
List<Metadata> metadata = wrapper.get(Types1_14.METADATA_LIST, 0);
handleMetadata(entityId, metadata, wrapper.user());
}
});
}
});
// Entity Metadata
registerMetadataRewriter(ClientboundPackets1_14.ENTITY_METADATA, Types1_14.METADATA_LIST);
}
Aggregations