Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/rewriter/BlockItemPacketRewriter1_20_3.java
  • Loading branch information
kennytv committed Jan 29, 2024
2 parents 9abfdfb + 8fc82cd commit b3b4d0f
Show file tree
Hide file tree
Showing 21 changed files with 128 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
public class ItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
T extends BackwardsProtocol<C, ?, ?, S>> extends ItemRewriterBase<C, S, T> {

public ItemRewriter(T protocol) {
super(protocol, true);
}

public ItemRewriter(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType) {
super(protocol, itemType, itemArrayType, true);
}
Expand Down Expand Up @@ -131,7 +127,7 @@ public ItemRewriter(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType)
}

@Override
public void registerAdvancements(C packetType, Type<Item> type) {
public void registerAdvancements(C packetType) {
protocol.registerClientbound(packetType, new PacketHandlers() {
@Override
public void register() {
Expand All @@ -156,7 +152,7 @@ public void register() {
translatableRewriter.processText(description);
}

handleItemToClient(wrapper.passthrough(type)); // Icon
handleItemToClient(wrapper.passthrough(getItemType())); // Icon
wrapper.passthrough(Type.VAR_INT); // Frame type
int flags = wrapper.passthrough(Type.INT); // Flags
if ((flags & 1) != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
protected final String nbtTagName;
protected final boolean jsonNameFormat;

protected ItemRewriterBase(T protocol, boolean jsonNameFormat) {
this(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY, jsonNameFormat);
}

public ItemRewriterBase(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, boolean jsonNameFormat) {
super(protocol, itemType, itemArrayType);
this.jsonNameFormat = jsonNameFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
import com.viaversion.viaversion.libs.gson.JsonElement;
Expand Down Expand Up @@ -106,7 +107,7 @@ private static void addMapping(String key, JsonObject object, Int2ObjectMap<Mapp
}

protected LegacyBlockItemRewriter(T protocol) {
super(protocol, false);
super(protocol, Type.ITEM1_8, Type.ITEM1_8_SHORT_ARRAY, false);
replacementData = LEGACY_MAPPINGS.get(protocol.getClass().getSimpleName().split("To")[1].replace("_", "."));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,15 @@ public void register() {
handler(itemToClientHandler(Type.ITEM1_8));

// Handle Llama
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
if (isLlama(wrapper.user())) {
Optional<ChestedHorseStorage> horse = getChestedHorse(wrapper.user());
if (!horse.isPresent())
return;
ChestedHorseStorage storage = horse.get();
int currentSlot = wrapper.get(Type.SHORT, 0);
wrapper.set(Type.SHORT, 0, ((Integer) (currentSlot = getNewSlotId(storage, currentSlot))).shortValue());
wrapper.set(Type.ITEM1_8, 0, getNewItem(storage, currentSlot, wrapper.get(Type.ITEM1_8, 0)));
}
handler(wrapper -> {
if (isLlama(wrapper.user())) {
Optional<ChestedHorseStorage> horse = getChestedHorse(wrapper.user());
if (!horse.isPresent())
return;
ChestedHorseStorage storage = horse.get();
int currentSlot = wrapper.get(Type.SHORT, 0);
wrapper.set(Type.SHORT, 0, ((Integer) (currentSlot = getNewSlotId(storage, currentSlot))).shortValue());
wrapper.set(Type.ITEM1_8, 0, getNewItem(storage, currentSlot, wrapper.get(Type.ITEM1_8, 0)));
}
});
}
Expand Down Expand Up @@ -113,9 +110,9 @@ public void register() {
}
});

registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM1_8);
registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT);

// Plugin message Packet -> Trading
// Plugin message -> Trading
protocol.registerClientbound(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketHandlers() {
@Override
public void register() {
Expand Down Expand Up @@ -172,7 +169,7 @@ public void register() {
}
});

registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM1_8);
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION);

protocol.registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public void register() {
}
});

registerSetSlot(ClientboundPackets1_12.SET_SLOT, Type.ITEM1_8);
registerWindowItems(ClientboundPackets1_12.WINDOW_ITEMS, Type.ITEM1_8_SHORT_ARRAY);
registerEntityEquipment(ClientboundPackets1_12.ENTITY_EQUIPMENT, Type.ITEM1_8);
registerSetSlot(ClientboundPackets1_12.SET_SLOT);
registerWindowItems(ClientboundPackets1_12.WINDOW_ITEMS);
registerEntityEquipment(ClientboundPackets1_12.ENTITY_EQUIPMENT);

// Plugin message Packet -> Trading
protocol.registerClientbound(ClientboundPackets1_12.PLUGIN_MESSAGE, new PacketHandlers() {
Expand Down Expand Up @@ -148,7 +148,7 @@ public void register() {
}
});

registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM1_8);
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION);

protocol.registerClientbound(ClientboundPackets1_12.CHUNK_DATA, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public ItemPackets1_11_1(Protocol1_11To1_11_1 protocol) {

@Override
protected void registerPackets() {
registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM1_8);
registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM1_8_SHORT_ARRAY);
registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM1_8);
registerSetSlot(ClientboundPackets1_9_3.SET_SLOT);
registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS);
registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT);

// Plugin message Packet -> Trading
protocol.registerClientbound(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketHandlers() {
Expand Down Expand Up @@ -72,8 +72,8 @@ public void register() {
}
});

registerClickWindow(ServerboundPackets1_9_3.CLICK_WINDOW, Type.ITEM1_8);
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM1_8);
registerClickWindow(ServerboundPackets1_9_3.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION);

// Handle item metadata
protocol.getEntityRewriter().filter().handler((event, meta) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
private final String extraNbtTag;

public BlockItemPackets1_13(Protocol1_12_2To1_13 protocol) {
super(protocol);
super(protocol, null, null);
extraNbtTag = "VB|" + protocol.getClass().getSimpleName() + "|2";
}

Expand Down Expand Up @@ -237,7 +237,7 @@ public void register() {
@Override
public void register() {
map(Type.UNSIGNED_BYTE);
map(Type.ITEM1_13_ARRAY, Type.ITEM1_8_SHORT_ARRAY);
map(Type.ITEM1_13_SHORT_ARRAY, Type.ITEM1_8_SHORT_ARRAY);

handler(itemArrayToClientHandler(Type.ITEM1_8_SHORT_ARRAY));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void register() {
@Override
public void register() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.ITEM1_13_2_SHORT_ARRAY, Type.ITEM1_13_ARRAY); // 1 - Window Values
map(Type.ITEM1_13_2_SHORT_ARRAY, Type.ITEM1_13_SHORT_ARRAY); // 1 - Window Values
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
private EnchantmentRewriter enchantmentRewriter;

public BlockItemPackets1_14(Protocol1_13_2To1_14 protocol) {
super(protocol);
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_SHORT_ARRAY);
}

@Override
Expand Down Expand Up @@ -170,9 +170,9 @@ protected void registerPackets() {
BlockRewriter<ClientboundPackets1_14> blockRewriter = BlockRewriter.legacy(protocol);

registerSetCooldown(ClientboundPackets1_14.COOLDOWN);
registerWindowItems(ClientboundPackets1_14.WINDOW_ITEMS, Type.ITEM1_13_2_SHORT_ARRAY);
registerSetSlot(ClientboundPackets1_14.SET_SLOT, Type.ITEM1_13_2);
registerAdvancements(ClientboundPackets1_14.ADVANCEMENTS, Type.ITEM1_13_2);
registerWindowItems(ClientboundPackets1_14.WINDOW_ITEMS);
registerSetSlot(ClientboundPackets1_14.SET_SLOT);
registerAdvancements(ClientboundPackets1_14.ADVANCEMENTS);

// Trade List -> Plugin Message
protocol.registerClientbound(ClientboundPackets1_14.TRADE_LIST, ClientboundPackets1_13.PLUGIN_MESSAGE, wrapper -> {
Expand Down Expand Up @@ -293,8 +293,8 @@ public void register() {
});


registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW, Type.ITEM1_13_2);
registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2);
registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION);

protocol.registerClientbound(ClientboundPackets1_14.BLOCK_BREAK_ANIMATION, new PacketHandlers() {
@Override
Expand Down Expand Up @@ -436,7 +436,7 @@ public void register() {
}
});

registerSpawnParticle(ClientboundPackets1_14.SPAWN_PARTICLE, Type.ITEM1_13_2, Type.FLOAT);
registerSpawnParticle(ClientboundPackets1_14.SPAWN_PARTICLE, Type.FLOAT);

protocol.registerClientbound(ClientboundPackets1_14.MAP_DATA, new PacketHandlers() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
public class InventoryPackets1_13_1 extends ItemRewriter<ClientboundPackets1_13, ServerboundPackets1_13, Protocol1_13To1_13_1> {

public InventoryPackets1_13_1(Protocol1_13To1_13_1 protocol) {
super(protocol, Type.ITEM1_13, Type.ITEM1_13_ARRAY);
super(protocol, Type.ITEM1_13, Type.ITEM1_13_SHORT_ARRAY);
}

@Override
public void registerPackets() {
registerSetCooldown(ClientboundPackets1_13.COOLDOWN);
registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS, Type.ITEM1_13_ARRAY);
registerSetSlot(ClientboundPackets1_13.SET_SLOT, Type.ITEM1_13);
registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS);
registerSetSlot(ClientboundPackets1_13.SET_SLOT);

protocol.registerClientbound(ClientboundPackets1_13.PLUGIN_MESSAGE, wrapper -> {
String channel = wrapper.passthrough(Type.STRING);
Expand Down Expand Up @@ -64,10 +64,10 @@ public void registerPackets() {
}
});

registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT, Type.ITEM1_13);
registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW, Type.ITEM1_13);
registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13);
registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT);
registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION);

registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, Type.ITEM1_13, Type.FLOAT);
registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, Type.FLOAT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
public class BlockItemPackets1_15 extends com.viaversion.viabackwards.api.rewriters.ItemRewriter<ClientboundPackets1_15, ServerboundPackets1_14, Protocol1_14_4To1_15> {

public BlockItemPackets1_15(Protocol1_14_4To1_15 protocol) {
super(protocol);
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_SHORT_ARRAY);
}

@Override
Expand All @@ -47,13 +47,13 @@ protected void registerPackets() {
protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2)));

registerSetCooldown(ClientboundPackets1_15.COOLDOWN);
registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.ITEM1_13_2_SHORT_ARRAY);
registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.ITEM1_13_2);
registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS);
registerSetSlot(ClientboundPackets1_15.SET_SLOT);
registerTradeList(ClientboundPackets1_15.TRADE_LIST);
registerEntityEquipment(ClientboundPackets1_15.ENTITY_EQUIPMENT, Type.ITEM1_13_2);
registerAdvancements(ClientboundPackets1_15.ADVANCEMENTS, Type.ITEM1_13_2);
registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.ITEM1_13_2);
registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2);
registerEntityEquipment(ClientboundPackets1_15.ENTITY_EQUIPMENT);
registerAdvancements(ClientboundPackets1_15.ADVANCEMENTS);
registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION);

blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_15.ACKNOWLEDGE_PLAYER_DIGGING);
blockRewriter.registerBlockAction(ClientboundPackets1_15.BLOCK_ACTION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
private EnchantmentRewriter enchantmentRewriter;

public BlockItemPackets1_16(Protocol1_15_2To1_16 protocol) {
super(protocol);
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_SHORT_ARRAY);
}

@Override
Expand Down Expand Up @@ -94,10 +94,10 @@ protected void registerPackets() {
});

registerSetCooldown(ClientboundPackets1_16.COOLDOWN);
registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS, Type.ITEM1_13_2_SHORT_ARRAY);
registerSetSlot(ClientboundPackets1_16.SET_SLOT, Type.ITEM1_13_2);
registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS);
registerSetSlot(ClientboundPackets1_16.SET_SLOT);
registerTradeList(ClientboundPackets1_16.TRADE_LIST);
registerAdvancements(ClientboundPackets1_16.ADVANCEMENTS, Type.ITEM1_13_2);
registerAdvancements(ClientboundPackets1_16.ADVANCEMENTS);

blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16.ACKNOWLEDGE_PLAYER_DIGGING);
blockRewriter.registerBlockAction(ClientboundPackets1_16.BLOCK_ACTION);
Expand Down Expand Up @@ -205,7 +205,7 @@ public void register() {

blockRewriter.registerEffect(ClientboundPackets1_16.EFFECT, 1010, 2001);

registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, Type.ITEM1_13_2, Type.DOUBLE);
registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, Type.DOUBLE);

protocol.registerClientbound(ClientboundPackets1_16.WINDOW_PROPERTY, new PacketHandlers() {
@Override
Expand Down Expand Up @@ -245,8 +245,8 @@ public void register() {
handleBlockEntity(tag);
});

registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.ITEM1_13_2);
registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2);
registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION);

protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
public class BlockItemPackets1_16_2 extends com.viaversion.viabackwards.api.rewriters.ItemRewriter<ClientboundPackets1_16_2, ServerboundPackets1_16, Protocol1_16_1To1_16_2> {

public BlockItemPackets1_16_2(Protocol1_16_1To1_16_2 protocol) {
super(protocol);
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_SHORT_ARRAY);
}

@Override
Expand All @@ -51,11 +51,11 @@ protected void registerPackets() {
new RecipeRewriter<>(protocol).register(ClientboundPackets1_16_2.DECLARE_RECIPES);

registerSetCooldown(ClientboundPackets1_16_2.COOLDOWN);
registerWindowItems(ClientboundPackets1_16_2.WINDOW_ITEMS, Type.ITEM1_13_2_SHORT_ARRAY);
registerSetSlot(ClientboundPackets1_16_2.SET_SLOT, Type.ITEM1_13_2);
registerWindowItems(ClientboundPackets1_16_2.WINDOW_ITEMS);
registerSetSlot(ClientboundPackets1_16_2.SET_SLOT);
registerEntityEquipmentArray(ClientboundPackets1_16_2.ENTITY_EQUIPMENT);
registerTradeList(ClientboundPackets1_16_2.TRADE_LIST);
registerAdvancements(ClientboundPackets1_16_2.ADVANCEMENTS, Type.ITEM1_13_2);
registerAdvancements(ClientboundPackets1_16_2.ADVANCEMENTS);

protocol.registerClientbound(ClientboundPackets1_16_2.UNLOCK_RECIPES, wrapper -> {
wrapper.passthrough(Type.VAR_INT);
Expand Down Expand Up @@ -132,10 +132,10 @@ public void register() {

blockRewriter.registerEffect(ClientboundPackets1_16_2.EFFECT, 1010, 2001);

registerSpawnParticle(ClientboundPackets1_16_2.SPAWN_PARTICLE, Type.ITEM1_13_2, Type.DOUBLE);
registerSpawnParticle(ClientboundPackets1_16_2.SPAWN_PARTICLE, Type.DOUBLE);

registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW, Type.ITEM1_13_2);
registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2);
registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION);
protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2)));
}

Expand Down
Loading

0 comments on commit b3b4d0f

Please sign in to comment.