use of com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14 in project ViaBackwards by ViaVersion.
the class BlockItemPackets1_16 method registerPackets.
@Override
protected void registerPackets() {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
RecipeRewriter1_14 recipeRewriter = new RecipeRewriter1_14(protocol);
// Remove new smithing type, only in this handler
protocol.registerClientbound(ClientboundPackets1_16.DECLARE_RECIPES, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int size = wrapper.passthrough(Type.VAR_INT);
int newSize = size;
for (int i = 0; i < size; i++) {
String originalType = wrapper.read(Type.STRING);
String type = originalType.replace("minecraft:", "");
if (type.equals("smithing")) {
newSize--;
wrapper.read(Type.STRING);
wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
wrapper.read(Type.FLAT_VAR_INT_ITEM);
continue;
}
wrapper.write(Type.STRING, originalType);
// Recipe Identifier
String id = wrapper.passthrough(Type.STRING);
recipeRewriter.handle(wrapper, type);
}
wrapper.set(Type.VAR_INT, 0, newSize);
});
}
});
registerSetCooldown(ClientboundPackets1_16.COOLDOWN);
registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
registerSetSlot(ClientboundPackets1_16.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
registerTradeList(ClientboundPackets1_16.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
registerAdvancements(ClientboundPackets1_16.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16.ACKNOWLEDGE_PLAYER_DIGGING);
blockRewriter.registerBlockAction(ClientboundPackets1_16.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_16.BLOCK_CHANGE);
blockRewriter.registerMultiBlockChange(ClientboundPackets1_16.MULTI_BLOCK_CHANGE);
protocol.registerClientbound(ClientboundPackets1_16.ENTITY_EQUIPMENT, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int entityId = wrapper.passthrough(Type.VAR_INT);
List<EquipmentData> equipmentData = new ArrayList<>();
byte slot;
do {
slot = wrapper.read(Type.BYTE);
Item item = handleItemToClient(wrapper.read(Type.FLAT_VAR_INT_ITEM));
int rawSlot = slot & 0x7F;
equipmentData.add(new EquipmentData(rawSlot, item));
} while ((slot & 0xFFFFFF80) != 0);
// Send first data in the current packet
EquipmentData firstData = equipmentData.get(0);
wrapper.write(Type.VAR_INT, firstData.slot);
wrapper.write(Type.FLAT_VAR_INT_ITEM, firstData.item);
// If there are more items, send new packets for them
for (int i = 1; i < equipmentData.size(); i++) {
PacketWrapper equipmentPacket = wrapper.create(ClientboundPackets1_15.ENTITY_EQUIPMENT);
EquipmentData data = equipmentData.get(i);
equipmentPacket.write(Type.VAR_INT, entityId);
equipmentPacket.write(Type.VAR_INT, data.slot);
equipmentPacket.write(Type.FLAT_VAR_INT_ITEM, data.item);
equipmentPacket.send(Protocol1_15_2To1_16.class);
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_16.UPDATE_LIGHT, new PacketRemapper() {
@Override
public void registerMap() {
// x
map(Type.VAR_INT);
// y
map(Type.VAR_INT);
map(Type.BOOLEAN, Type.NOTHING);
}
});
protocol.registerClientbound(ClientboundPackets1_16.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
Chunk chunk = wrapper.read(new Chunk1_16Type());
wrapper.write(new Chunk1_15Type(), chunk);
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null)
continue;
for (int j = 0; j < section.getPaletteSize(); j++) {
int old = section.getPaletteEntry(j);
section.setPaletteEntry(j, protocol.getMappingData().getNewBlockStateId(old));
}
}
CompoundTag heightMaps = chunk.getHeightMap();
for (Tag heightMapTag : heightMaps.values()) {
LongArrayTag heightMap = (LongArrayTag) heightMapTag;
int[] heightMapData = new int[256];
CompactArrayUtil.iterateCompactArrayWithPadding(9, heightMapData.length, heightMap.getValue(), (i, v) -> heightMapData[i] = v);
heightMap.setValue(CompactArrayUtil.createCompactArray(9, heightMapData.length, i -> heightMapData[i]));
}
if (chunk.isBiomeData()) {
for (int i = 0; i < 1024; i++) {
int biome = chunk.getBiomeData()[i];
switch(biome) {
// new nether biomes
case 170:
case 171:
case 172:
case 173:
chunk.getBiomeData()[i] = 8;
break;
}
}
}
if (chunk.getBlockEntities() == null)
return;
for (CompoundTag blockEntity : chunk.getBlockEntities()) {
handleBlockEntity(blockEntity);
}
});
}
});
blockRewriter.registerEffect(ClientboundPackets1_16.EFFECT, 1010, 2001);
registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
protocol.registerClientbound(ClientboundPackets1_16.WINDOW_PROPERTY, new PacketRemapper() {
@Override
public void registerMap() {
// Window id
map(Type.UNSIGNED_BYTE);
// Property
map(Type.SHORT);
// Value
map(Type.SHORT);
handler(wrapper -> {
short property = wrapper.get(Type.SHORT, 0);
if (property >= 4 && property <= 6) {
// Enchantment id
short enchantmentId = wrapper.get(Type.SHORT, 1);
if (enchantmentId > 11) {
// soul_speed
wrapper.set(Type.SHORT, 1, --enchantmentId);
} else if (enchantmentId == 11) {
wrapper.set(Type.SHORT, 1, (short) 9);
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_16.MAP_DATA, new PacketRemapper() {
@Override
public void registerMap() {
// Map ID
map(Type.VAR_INT);
// Scale
map(Type.BYTE);
// Tracking Position
map(Type.BOOLEAN);
// Locked
map(Type.BOOLEAN);
handler(MapColorRewriter.getRewriteHandler(MapColorRewrites::getMappedColor));
}
});
protocol.registerClientbound(ClientboundPackets1_16.BLOCK_ENTITY_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
Position position = wrapper.passthrough(Type.POSITION1_14);
short action = wrapper.passthrough(Type.UNSIGNED_BYTE);
CompoundTag tag = wrapper.passthrough(Type.NBT);
handleBlockEntity(tag);
});
}
});
registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
}
});
}
use of com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14 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.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14 in project ViaVersion by ViaVersion.
the class InventoryPackets method registerPackets.
@Override
public void registerPackets() {
registerSetCooldown(ClientboundPackets1_14.COOLDOWN);
registerWindowItems(ClientboundPackets1_14.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
registerTradeList(ClientboundPackets1_14.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
registerSetSlot(ClientboundPackets1_14.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
registerEntityEquipment(ClientboundPackets1_14.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
registerAdvancements(ClientboundPackets1_14.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
new RecipeRewriter1_14(protocol).registerDefaultHandler(ClientboundPackets1_14.DECLARE_RECIPES);
registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
}
use of com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14 in project ViaBackwards by ViaVersion.
the class BlockItemPackets1_15 method registerPackets.
@Override
protected void registerPackets() {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
new RecipeRewriter1_14(protocol).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES);
protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
}
});
registerSetCooldown(ClientboundPackets1_15.COOLDOWN);
registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
registerTradeList(ClientboundPackets1_15.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
registerEntityEquipment(ClientboundPackets1_15.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
registerAdvancements(ClientboundPackets1_15.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_15.ACKNOWLEDGE_PLAYER_DIGGING);
blockRewriter.registerBlockAction(ClientboundPackets1_15.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_15.BLOCK_CHANGE);
blockRewriter.registerMultiBlockChange(ClientboundPackets1_15.MULTI_BLOCK_CHANGE);
protocol.registerClientbound(ClientboundPackets1_15.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Chunk chunk = wrapper.read(new Chunk1_15Type());
wrapper.write(new Chunk1_14Type(), chunk);
if (chunk.isFullChunk()) {
int[] biomeData = chunk.getBiomeData();
int[] newBiomeData = new int[256];
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
int x = j << 2;
int z = i << 2;
int newIndex = z << 4 | x;
int oldIndex = i << 2 | j;
int biome = biomeData[oldIndex];
for (int k = 0; k < 4; k++) {
int offX = newIndex + (k << 4);
for (int l = 0; l < 4; l++) {
newBiomeData[offX + l] = biome;
}
}
}
}
chunk.setBiomeData(newBiomeData);
}
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null)
continue;
for (int j = 0; j < section.getPaletteSize(); j++) {
int old = section.getPaletteEntry(j);
int newId = protocol.getMappingData().getNewBlockStateId(old);
section.setPaletteEntry(j, newId);
}
}
}
});
}
});
blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001);
protocol.registerClientbound(ClientboundPackets1_15.SPAWN_PARTICLE, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Particle ID
map(Type.INT);
// 1 - Long Distance
map(Type.BOOLEAN);
// 2 - X
map(Type.DOUBLE, Type.FLOAT);
// 3 - Y
map(Type.DOUBLE, Type.FLOAT);
// 4 - Z
map(Type.DOUBLE, Type.FLOAT);
// 5 - Offset X
map(Type.FLOAT);
// 6 - Offset Y
map(Type.FLOAT);
// 7 - Offset Z
map(Type.FLOAT);
// 8 - Particle Data
map(Type.FLOAT);
// 9 - Particle Count
map(Type.INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.INT, 0);
if (id == 3 || id == 23) {
int data = wrapper.passthrough(Type.VAR_INT);
wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
} else if (id == 32) {
Item item = handleItemToClient(wrapper.read(Type.FLAT_VAR_INT_ITEM));
wrapper.write(Type.FLAT_VAR_INT_ITEM, item);
}
int mappedId = protocol.getMappingData().getNewParticleId(id);
if (id != mappedId) {
wrapper.set(Type.INT, 0, mappedId);
}
}
});
}
});
}
use of com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14 in project ViaVersion by ViaVersion.
the class InventoryPackets method registerPackets.
@Override
public void registerPackets() {
// clear cursor item to prevent client to try dropping it during navigation between multiple inventories causing arm swing
PacketHandler cursorRemapper = wrapper -> {
PacketWrapper clearPacket = wrapper.create(ClientboundPackets1_16.SET_SLOT);
clearPacket.write(Type.UNSIGNED_BYTE, (short) -1);
clearPacket.write(Type.SHORT, (short) -1);
clearPacket.write(Type.FLAT_VAR_INT_ITEM, null);
clearPacket.send(Protocol1_16To1_15_2.class);
};
protocol.registerClientbound(ClientboundPackets1_15.OPEN_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
// Window Id
map(Type.VAR_INT);
// Window Type
map(Type.VAR_INT);
// Window Title
map(Type.COMPONENT);
handler(cursorRemapper);
handler(wrapper -> {
InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
int windowId = wrapper.get(Type.VAR_INT, 0);
int windowType = wrapper.get(Type.VAR_INT, 1);
if (windowType >= 20) {
// smithing added with id 20
wrapper.set(Type.VAR_INT, 1, ++windowType);
}
inventoryTracker.setInventory((short) windowId);
});
}
});
protocol.registerClientbound(ClientboundPackets1_15.CLOSE_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
handler(cursorRemapper);
handler(wrapper -> {
InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
inventoryTracker.setInventory((short) -1);
});
}
});
protocol.registerClientbound(ClientboundPackets1_15.WINDOW_PROPERTY, new PacketRemapper() {
@Override
public void registerMap() {
// Window Id
map(Type.UNSIGNED_BYTE);
// Property
map(Type.SHORT);
// Value
map(Type.SHORT);
handler(wrapper -> {
short property = wrapper.get(Type.SHORT, 0);
if (property >= 4 && property <= 6) {
// Enchantment id
short enchantmentId = wrapper.get(Type.SHORT, 1);
if (enchantmentId >= 11) {
// soul_speed added with id 11
wrapper.set(Type.SHORT, 1, ++enchantmentId);
}
}
});
}
});
registerSetCooldown(ClientboundPackets1_15.COOLDOWN);
registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
registerTradeList(ClientboundPackets1_15.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
registerAdvancements(ClientboundPackets1_15.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
protocol.registerClientbound(ClientboundPackets1_15.ENTITY_EQUIPMENT, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.VAR_INT);
handler(wrapper -> {
int slot = wrapper.read(Type.VAR_INT);
wrapper.write(Type.BYTE, (byte) slot);
handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
});
}
});
new RecipeRewriter1_14(protocol).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES);
registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
protocol.registerServerbound(ServerboundPackets1_16.CLOSE_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
inventoryTracker.setInventory((short) -1);
});
}
});
protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
}
});
registerSpawnParticle(ClientboundPackets1_15.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
}
Aggregations