3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-27 08:30:10 +01:00

Cleanup 1.20.2->1.20 item and recipe rewriter (#840)

Dieser Commit ist enthalten in:
EnZaXD 2024-07-27 19:58:29 +02:00 committet von GitHub
Ursprung 0ed3efc643
Commit d3721307b1
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194

Datei anzeigen

@ -54,7 +54,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<ClientboundPackets1_20_2, ServerboundPackets1_19_4, Protocol1_20_2To1_20> { public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<ClientboundPackets1_20_2, ServerboundPackets1_19_4, Protocol1_20_2To1_20> {
public BlockItemPacketRewriter1_20_2(final Protocol1_20_2To1_20 protocol) { public BlockItemPacketRewriter1_20_2(final Protocol1_20_2To1_20 protocol) {
super(protocol, Types.ITEM1_20_2, Types.ITEM1_20_2_ARRAY); super(protocol, Types.ITEM1_20_2, Types.ITEM1_20_2_ARRAY, Types.ITEM1_13_2, Types.ITEM1_13_2_ARRAY);
} }
@Override @Override
@ -65,6 +65,13 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
blockRewriter.registerSectionBlocksUpdate1_20(ClientboundPackets1_20_2.SECTION_BLOCKS_UPDATE); blockRewriter.registerSectionBlocksUpdate1_20(ClientboundPackets1_20_2.SECTION_BLOCKS_UPDATE);
blockRewriter.registerLevelEvent(ClientboundPackets1_20_2.LEVEL_EVENT, 1010, 2001); blockRewriter.registerLevelEvent(ClientboundPackets1_20_2.LEVEL_EVENT, 1010, 2001);
registerSetContent1_17_1(ClientboundPackets1_20_2.CONTAINER_SET_CONTENT);
registerSetSlot1_17_1(ClientboundPackets1_20_2.CONTAINER_SET_SLOT);
registerContainerClick1_17_1(ServerboundPackets1_19_4.CONTAINER_CLICK);
registerMerchantOffers1_19(ClientboundPackets1_20_2.MERCHANT_OFFERS);
registerSetCreativeModeSlot(ServerboundPackets1_19_4.SET_CREATIVE_MODE_SLOT);
registerLevelParticles1_19(ClientboundPackets1_20_2.LEVEL_PARTICLES);
protocol.cancelClientbound(ClientboundPackets1_20_2.CHUNK_BATCH_START); protocol.cancelClientbound(ClientboundPackets1_20_2.CHUNK_BATCH_START);
protocol.registerClientbound(ClientboundPackets1_20_2.CHUNK_BATCH_FINISHED, null, wrapper -> { protocol.registerClientbound(ClientboundPackets1_20_2.CHUNK_BATCH_FINISHED, null, wrapper -> {
wrapper.cancel(); wrapper.cancel();
@ -145,32 +152,6 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
} }
}); });
// Replace the NBT type everywhere
protocol.registerClientbound(ClientboundPackets1_20_2.CONTAINER_SET_CONTENT, new PacketHandlers() {
@Override
public void register() {
map(Types.UNSIGNED_BYTE); // Window id
map(Types.VAR_INT); // State id
handler(wrapper -> {
final Item[] items = wrapper.read(Types.ITEM1_20_2_ARRAY);
for (final Item item : items) {
handleItemToClient(wrapper.user(), item);
}
wrapper.write(Types.ITEM1_13_2_ARRAY, items);
wrapper.write(Types.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_20_2))); // Carried item
});
}
});
protocol.registerClientbound(ClientboundPackets1_20_2.CONTAINER_SET_SLOT, new PacketHandlers() {
@Override
public void register() {
map(Types.UNSIGNED_BYTE); // Window id
map(Types.VAR_INT); // State id
map(Types.SHORT); // Slot id
handler(wrapper -> wrapper.write(Types.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_20_2))));
}
});
protocol.registerClientbound(ClientboundPackets1_20_2.UPDATE_ADVANCEMENTS, wrapper -> { protocol.registerClientbound(ClientboundPackets1_20_2.UPDATE_ADVANCEMENTS, wrapper -> {
wrapper.passthrough(Types.BOOLEAN); // Reset/clear wrapper.passthrough(Types.BOOLEAN); // Reset/clear
final int size = wrapper.passthrough(Types.VAR_INT); final int size = wrapper.passthrough(Types.VAR_INT);
@ -216,159 +197,18 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
}); });
} }
}); });
protocol.registerServerbound(ServerboundPackets1_19_4.CONTAINER_CLICK, new PacketHandlers() {
@Override
public void register() {
map(Types.UNSIGNED_BYTE); // Window Id
map(Types.VAR_INT); // State id
map(Types.SHORT); // Slot
map(Types.BYTE); // Button
map(Types.VAR_INT); // Mode
handler(wrapper -> {
// Affected items
final int length = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < length; i++) {
wrapper.passthrough(Types.SHORT); // Slot
wrapper.write(Types.ITEM1_20_2, handleItemToServer(wrapper.user(), wrapper.read(Types.ITEM1_13_2)));
}
// Carried item
wrapper.write(Types.ITEM1_20_2, handleItemToServer(wrapper.user(), wrapper.read(Types.ITEM1_13_2)));
});
}
});
protocol.registerClientbound(ClientboundPackets1_20_2.MERCHANT_OFFERS, wrapper -> {
wrapper.passthrough(Types.VAR_INT); // Container id
final int size = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < size; i++) {
wrapper.write(Types.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_20_2))); // Input
wrapper.write(Types.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_20_2))); // Output
wrapper.write(Types.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_20_2))); // Second Item
wrapper.passthrough(Types.BOOLEAN); // Trade disabled
wrapper.passthrough(Types.INT); // Number of tools uses
wrapper.passthrough(Types.INT); // Maximum number of trade uses
wrapper.passthrough(Types.INT); // XP
wrapper.passthrough(Types.INT); // Special price
wrapper.passthrough(Types.FLOAT); // Price multiplier
wrapper.passthrough(Types.INT); // Demand
}
});
protocol.registerServerbound(ServerboundPackets1_19_4.SET_CREATIVE_MODE_SLOT, new PacketHandlers() {
@Override
public void register() {
map(Types.SHORT); // 0 - Slot
handler(wrapper -> wrapper.write(Types.ITEM1_20_2, handleItemToServer(wrapper.user(), wrapper.read(Types.ITEM1_13_2)))); // 1 - Clicked Item
}
});
protocol.registerClientbound(ClientboundPackets1_20_2.LEVEL_PARTICLES, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Particle ID
map(Types.BOOLEAN); // 1 - Long Distance
map(Types.DOUBLE); // 2 - X
map(Types.DOUBLE); // 3 - Y
map(Types.DOUBLE); // 4 - Z
map(Types.FLOAT); // 5 - Offset X
map(Types.FLOAT); // 6 - Offset Y
map(Types.FLOAT); // 7 - Offset Z
map(Types.FLOAT); // 8 - Particle Data
map(Types.INT); // 9 - Particle Count
handler(wrapper -> {
final int id = wrapper.get(Types.VAR_INT, 0);
final ParticleMappings mappings = Protocol1_20_2To1_20.MAPPINGS.getParticleMappings();
if (mappings.isBlockParticle(id)) {
final int data = wrapper.read(Types.VAR_INT);
wrapper.write(Types.VAR_INT, protocol.getMappingData().getNewBlockStateId(data));
} else if (mappings.isItemParticle(id)) {
wrapper.write(Types.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_20_2)));
}
});
}
});
new RecipeRewriter1_20_2<>(protocol) { new RecipeRewriter1_20_2<>(protocol) {
@Override @Override
public void handleCraftingShapeless(final PacketWrapper wrapper) { protected Type<Item> mappedItemType() {
wrapper.passthrough(Types.STRING); // Group return BlockItemPacketRewriter1_20_2.this.mappedItemType();
wrapper.passthrough(Types.VAR_INT); // Crafting book category
handleIngredients(wrapper);
final Item result = wrapper.read(itemType());
rewrite(wrapper.user(), result);
wrapper.write(Types.ITEM1_13_2, result);
} }
@Override @Override
public void handleSmelting(final PacketWrapper wrapper) { protected Type<Item[]> mappedItemArrayType() {
wrapper.passthrough(Types.STRING); // Group return BlockItemPacketRewriter1_20_2.this.mappedItemArrayType();
wrapper.passthrough(Types.VAR_INT); // Crafting book category
handleIngredient(wrapper);
final Item result = wrapper.read(itemType());
rewrite(wrapper.user(), result);
wrapper.write(Types.ITEM1_13_2, result);
wrapper.passthrough(Types.FLOAT); // EXP
wrapper.passthrough(Types.VAR_INT); // Cooking time
} }
@Override
public void handleCraftingShaped(final PacketWrapper wrapper) {
final int ingredients = wrapper.passthrough(Types.VAR_INT) * wrapper.passthrough(Types.VAR_INT);
wrapper.passthrough(Types.STRING); // Group
wrapper.passthrough(Types.VAR_INT); // Crafting book category
for (int i = 0; i < ingredients; i++) {
handleIngredient(wrapper);
}
final Item result = wrapper.read(itemType());
rewrite(wrapper.user(), result);
wrapper.write(Types.ITEM1_13_2, result);
wrapper.passthrough(Types.BOOLEAN); // Show notification
}
@Override
public void handleStonecutting(final PacketWrapper wrapper) {
wrapper.passthrough(Types.STRING); // Group
handleIngredient(wrapper);
final Item result = wrapper.read(itemType());
rewrite(wrapper.user(), result);
wrapper.write(Types.ITEM1_13_2, result);
}
@Override
public void handleSmithing(final PacketWrapper wrapper) {
handleIngredient(wrapper); // Base
handleIngredient(wrapper); // Addition
final Item result = wrapper.read(itemType());
rewrite(wrapper.user(), result);
wrapper.write(Types.ITEM1_13_2, result);
}
@Override
public void handleSmithingTransform(final PacketWrapper wrapper) {
handleIngredient(wrapper); // Template
handleIngredient(wrapper); // Base
handleIngredient(wrapper); // Additions
final Item result = wrapper.read(itemType());
rewrite(wrapper.user(), result);
wrapper.write(Types.ITEM1_13_2, result);
}
@Override
protected void handleIngredient(final PacketWrapper wrapper) {
final Item[] items = wrapper.read(itemArrayType());
wrapper.write(Types.ITEM1_13_2_ARRAY, items);
for (final Item item : items) {
rewrite(wrapper.user(), item);
}
}
}.register(ClientboundPackets1_20_2.UPDATE_RECIPES); }.register(ClientboundPackets1_20_2.UPDATE_RECIPES);
} }