mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-12-22 16:57:40 +01:00
Update VV usage
This commit is contained in:
parent
cbbc127360
commit
7e2775114b
@ -18,7 +18,6 @@
|
||||
package com.viaversion.viabackwards.api;
|
||||
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappings;
|
||||
import com.viaversion.viabackwards.api.rewriters.ItemRewriterBase;
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
||||
@ -51,16 +50,12 @@ public abstract class BackwardsProtocol<C1 extends ClientboundPacketType, C2 ext
|
||||
return false;
|
||||
}
|
||||
|
||||
public @Nullable ItemRewriterBase getBlockItemPackets() {
|
||||
@Override
|
||||
public @Nullable BackwardsMappings getMappingData() { // Change return type to BackwardsMappings
|
||||
return null;
|
||||
}
|
||||
|
||||
public @Nullable TranslatableRewriter getTranslatableRewriter() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BackwardsMappings getMappingData() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public class EnchantmentRewriter {
|
||||
}
|
||||
|
||||
public void handleToClient(Item item) {
|
||||
CompoundTag tag = item.getTag();
|
||||
CompoundTag tag = item.tag();
|
||||
if (tag == null) return;
|
||||
|
||||
if (tag.get("Enchantments") instanceof ListTag) {
|
||||
@ -67,7 +67,7 @@ public class EnchantmentRewriter {
|
||||
}
|
||||
|
||||
public void handleToServer(Item item) {
|
||||
CompoundTag tag = item.getTag();
|
||||
CompoundTag tag = item.tag();
|
||||
if (tag == null) return;
|
||||
|
||||
if (tag.contains(itemRewriter.getNbtTagName() + "|Enchantments")) {
|
||||
|
@ -164,7 +164,7 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends En
|
||||
filter().handler((event, meta) -> {
|
||||
MetaType type = meta.metaType();
|
||||
if (itemType != null && type == itemType) {
|
||||
protocol.getBlockItemPackets().handleItemToClient(meta.value());
|
||||
protocol.getItemRewriter().handleItemToClient(meta.value());
|
||||
} else if (blockType != null && type == blockType) {
|
||||
int data = meta.value();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
|
@ -38,10 +38,10 @@ public abstract class ItemRewriter<T extends BackwardsProtocol> extends ItemRewr
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToClient(Item item) {
|
||||
public @Nullable Item handleItemToClient(@Nullable Item item) {
|
||||
if (item == null) return null;
|
||||
|
||||
CompoundTag display = item.getTag() != null ? item.getTag().get("display") : null;
|
||||
CompoundTag display = item.tag() != null ? item.tag().get("display") : null;
|
||||
if (translatableRewriter != null && display != null) {
|
||||
// Handle name and lore components
|
||||
StringTag name = display.get("Name");
|
||||
@ -73,23 +73,23 @@ public abstract class ItemRewriter<T extends BackwardsProtocol> extends ItemRewr
|
||||
}
|
||||
}
|
||||
|
||||
MappedItem data = protocol.getMappingData().getMappedItem(item.getIdentifier());
|
||||
MappedItem data = protocol.getMappingData().getMappedItem(item.identifier());
|
||||
if (data == null) {
|
||||
// Just rewrite the id
|
||||
return super.handleItemToClient(item);
|
||||
}
|
||||
|
||||
if (item.getTag() == null) {
|
||||
if (item.tag() == null) {
|
||||
item.setTag(new CompoundTag());
|
||||
}
|
||||
|
||||
// Save original id, set remapped id
|
||||
item.getTag().put(nbtTagName + "|id", new IntTag(item.getIdentifier()));
|
||||
item.tag().put(nbtTagName + "|id", new IntTag(item.identifier()));
|
||||
item.setIdentifier(data.getId());
|
||||
|
||||
// Set custom name - only done if there is no original one
|
||||
if (display == null) {
|
||||
item.getTag().put("display", display = new CompoundTag());
|
||||
item.tag().put("display", display = new CompoundTag());
|
||||
}
|
||||
if (!display.contains("Name")) {
|
||||
display.put("Name", new StringTag(data.getJsonName()));
|
||||
@ -99,12 +99,12 @@ public abstract class ItemRewriter<T extends BackwardsProtocol> extends ItemRewr
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToServer(Item item) {
|
||||
public @Nullable Item handleItemToServer(@Nullable Item item) {
|
||||
if (item == null) return null;
|
||||
|
||||
super.handleItemToServer(item);
|
||||
if (item.getTag() != null) {
|
||||
IntTag originalId = item.getTag().remove(nbtTagName + "|id");
|
||||
if (item.tag() != null) {
|
||||
IntTag originalId = item.tag().remove(nbtTagName + "|id");
|
||||
if (originalId != null) {
|
||||
item.setIdentifier(originalId.asInt());
|
||||
}
|
||||
|
@ -19,14 +19,14 @@ package com.viaversion.viabackwards.api.rewriters;
|
||||
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.rewriter.RewriterBase;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends RewriterBase<T> {
|
||||
public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends ItemRewriter<T> {
|
||||
|
||||
protected final String nbtTagName;
|
||||
protected final boolean jsonNameFormat;
|
||||
@ -37,19 +37,10 @@ public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends Rewr
|
||||
nbtTagName = "VB|" + protocol.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
public @Nullable Item handleItemToClient(Item item) {
|
||||
public @Nullable Item handleItemToServer(@Nullable Item item) {
|
||||
if (item == null) return null;
|
||||
if (protocol.getMappingData() != null && protocol.getMappingData().getItemMappings() != null) {
|
||||
item.setIdentifier(protocol.getMappingData().getNewItemId(item.getIdentifier()));
|
||||
}
|
||||
return item;
|
||||
}
|
||||
super.handleItemToServer(item);
|
||||
|
||||
public @Nullable Item handleItemToServer(Item item) {
|
||||
if (item == null) return null;
|
||||
if (protocol.getMappingData() != null && protocol.getMappingData().getItemMappings() != null) {
|
||||
item.setIdentifier(protocol.getMappingData().getOldItemId(item.getIdentifier()));
|
||||
}
|
||||
restoreDisplayTag(item);
|
||||
return item;
|
||||
}
|
||||
@ -81,9 +72,9 @@ public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends Rewr
|
||||
}
|
||||
|
||||
protected void restoreDisplayTag(Item item) {
|
||||
if (item.getTag() == null) return;
|
||||
if (item.tag() == null) return;
|
||||
|
||||
CompoundTag display = item.getTag().get("display");
|
||||
CompoundTag display = item.tag().get("display");
|
||||
if (display != null) {
|
||||
// Remove custom name / restore original name
|
||||
if (display.remove(nbtTagName + "|customName") != null) {
|
||||
|
@ -92,16 +92,16 @@ public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> exten
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToClient(Item item) {
|
||||
public @Nullable Item handleItemToClient(@Nullable Item item) {
|
||||
if (item == null) return null;
|
||||
|
||||
MappedLegacyBlockItem data = replacementData.get(item.getIdentifier());
|
||||
MappedLegacyBlockItem data = replacementData.get(item.identifier());
|
||||
if (data == null) {
|
||||
// Just rewrite the id
|
||||
return super.handleItemToClient(item);
|
||||
}
|
||||
|
||||
short originalData = item.getData();
|
||||
short originalData = item.data();
|
||||
item.setIdentifier(data.getId());
|
||||
// Keep original data if mapped data is set to -1
|
||||
if (data.getData() != -1) {
|
||||
@ -110,13 +110,13 @@ public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> exten
|
||||
|
||||
// Set display name
|
||||
if (data.getName() != null) {
|
||||
if (item.getTag() == null) {
|
||||
if (item.tag() == null) {
|
||||
item.setTag(new CompoundTag());
|
||||
}
|
||||
|
||||
CompoundTag display = item.getTag().get("display");
|
||||
CompoundTag display = item.tag().get("display");
|
||||
if (display == null) {
|
||||
item.getTag().put("display", display = new CompoundTag());
|
||||
item.tag().put("display", display = new CompoundTag());
|
||||
}
|
||||
|
||||
StringTag nameTag = display.get("Name");
|
||||
|
@ -44,9 +44,9 @@ public class Protocol1_10To1_11 extends BackwardsProtocol<ClientboundPackets1_9_
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
(blockItemPackets = new BlockItemPackets1_11(this)).register();
|
||||
entityPackets.register();
|
||||
new PlayerPackets1_11().register(this);
|
||||
(blockItemPackets = new BlockItemPackets1_11(this)).register();
|
||||
|
||||
SoundRewriter soundRewriter = new SoundRewriter(this);
|
||||
soundRewriter.registerNamedSound(ClientboundPackets1_9_3.NAMED_SOUND);
|
||||
@ -67,10 +67,6 @@ public class Protocol1_10To1_11 extends BackwardsProtocol<ClientboundPackets1_9_
|
||||
}
|
||||
}
|
||||
|
||||
public BlockItemPackets1_11 getBlockItemPackets() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BackwardsMappings getMappingData() {
|
||||
return MAPPINGS;
|
||||
@ -81,6 +77,11 @@ public class Protocol1_10To1_11 extends BackwardsProtocol<ClientboundPackets1_9_
|
||||
return entityPackets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemPackets1_11 getItemRewriter() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMappingDataToLoad() {
|
||||
return true;
|
||||
|
@ -30,6 +30,7 @@ import com.viaversion.viaversion.api.data.entity.StoredEntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_11Types;
|
||||
import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
@ -44,7 +45,6 @@ import com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
@ -59,8 +59,6 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.SET_SLOT, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
@ -68,7 +66,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
|
||||
map(Type.SHORT); // 1 - Slot ID
|
||||
map(Type.ITEM); // 2 - Slot Value
|
||||
|
||||
handler(itemRewriter.itemToClientHandler(Type.ITEM));
|
||||
handler(itemToClientHandler(Type.ITEM));
|
||||
|
||||
// Handle Llama
|
||||
handler(new PacketHandler() {
|
||||
@ -119,7 +117,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
|
||||
}
|
||||
});
|
||||
|
||||
itemRewriter.registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM);
|
||||
registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM);
|
||||
|
||||
// Plugin message Packet -> Trading
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketRemapper() {
|
||||
@ -163,7 +161,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
|
||||
map(Type.VAR_INT); // 4 - Mode
|
||||
map(Type.ITEM); // 5 - Clicked Item
|
||||
|
||||
handler(itemRewriter.itemToServerHandler(Type.ITEM));
|
||||
handler(itemToServerHandler(Type.ITEM));
|
||||
|
||||
// Llama slot
|
||||
handler(new PacketHandler() {
|
||||
@ -184,7 +182,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
|
||||
}
|
||||
});
|
||||
|
||||
itemRewriter.registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM);
|
||||
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, new PacketRemapper() {
|
||||
@Override
|
||||
@ -362,7 +360,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
|
||||
if (item == null) return null;
|
||||
super.handleItemToClient(item);
|
||||
|
||||
CompoundTag tag = item.getTag();
|
||||
CompoundTag tag = item.tag();
|
||||
if (tag == null) return item;
|
||||
|
||||
// Rewrite spawn eggs (id checks are done in the method itself)
|
||||
@ -378,11 +376,11 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToServer(final Item item) {
|
||||
public Item handleItemToServer(Item item) {
|
||||
if (item == null) return null;
|
||||
super.handleItemToServer(item);
|
||||
|
||||
CompoundTag tag = item.getTag();
|
||||
CompoundTag tag = item.tag();
|
||||
if (tag == null) return item;
|
||||
|
||||
// Rewrite spawn eggs (id checks are done in the method itself)
|
||||
@ -452,7 +450,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
|
||||
int endNonExistingFormula = 2 + 3 * (storage.isChested() ? 5 : 0);
|
||||
|
||||
if (slotId >= startNonExistingFormula && slotId < endNonExistingFormula)
|
||||
return new Item(166, (byte) 1, (short) 0, getNamedTag("§4SLOT DISABLED"));
|
||||
return new DataItem(166, (byte) 1, (short) 0, getNamedTag("§4SLOT DISABLED"));
|
||||
if (slotId == 1)
|
||||
return null;
|
||||
return current;
|
||||
|
@ -99,7 +99,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<Protocol1_10To1_11>
|
||||
int objType = objectData & 4095;
|
||||
int data = objectData >> 12 & 15;
|
||||
|
||||
Block block = protocol.getBlockItemPackets().handleBlock(objType, data);
|
||||
Block block = protocol.getItemRewriter().handleBlock(objType, data);
|
||||
if (block == null)
|
||||
return;
|
||||
|
||||
|
@ -40,7 +40,7 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||
public class Protocol1_11_1To1_12 extends BackwardsProtocol<ClientboundPackets1_12, ClientboundPackets1_9_3, ServerboundPackets1_12, ServerboundPackets1_9_3> {
|
||||
|
||||
private final EntityPackets1_12 entityPackets = new EntityPackets1_12(this);
|
||||
private BlockItemPackets1_12 blockItemPackets;
|
||||
private final BlockItemPackets1_12 blockItemPackets = new BlockItemPackets1_12(this);
|
||||
|
||||
public Protocol1_11_1To1_12() {
|
||||
super(ClientboundPackets1_12.class, ClientboundPackets1_9_3.class, ServerboundPackets1_12.class, ServerboundPackets1_9_3.class);
|
||||
@ -48,8 +48,8 @@ public class Protocol1_11_1To1_12 extends BackwardsProtocol<ClientboundPackets1_
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
blockItemPackets.register();
|
||||
entityPackets.register();
|
||||
(blockItemPackets = new BlockItemPackets1_12(this)).register();
|
||||
new SoundPackets1_12(this).register();
|
||||
new ChatPackets1_12(this).register();
|
||||
|
||||
@ -83,12 +83,13 @@ public class Protocol1_11_1To1_12 extends BackwardsProtocol<ClientboundPackets1_
|
||||
user.put(new ShoulderTracker(user));
|
||||
}
|
||||
|
||||
public BlockItemPackets1_12 getBlockItemPackets() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPackets1_12 getEntityRewriter() {
|
||||
return entityPackets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemPackets1_12 getItemRewriter() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,6 @@ import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ServerboundPacke
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.Iterator;
|
||||
@ -89,11 +88,9 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<Protocol1_11_1
|
||||
}
|
||||
});
|
||||
|
||||
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
|
||||
|
||||
itemRewriter.registerSetSlot(ClientboundPackets1_12.SET_SLOT, Type.ITEM);
|
||||
itemRewriter.registerWindowItems(ClientboundPackets1_12.WINDOW_ITEMS, Type.ITEM_ARRAY);
|
||||
itemRewriter.registerEntityEquipment(ClientboundPackets1_12.ENTITY_EQUIPMENT, Type.ITEM);
|
||||
registerSetSlot(ClientboundPackets1_12.SET_SLOT, Type.ITEM);
|
||||
registerWindowItems(ClientboundPackets1_12.WINDOW_ITEMS, Type.ITEM_ARRAY);
|
||||
registerEntityEquipment(ClientboundPackets1_12.ENTITY_EQUIPMENT, Type.ITEM);
|
||||
|
||||
// Plugin message Packet -> Trading
|
||||
protocol.registerClientbound(ClientboundPackets1_12.PLUGIN_MESSAGE, new PacketRemapper() {
|
||||
@ -165,7 +162,7 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<Protocol1_11_1
|
||||
}
|
||||
});
|
||||
|
||||
itemRewriter.registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM);
|
||||
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_12.CHUNK_DATA, new PacketRemapper() {
|
||||
@Override
|
||||
@ -264,10 +261,10 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<Protocol1_11_1
|
||||
if (item == null) return null;
|
||||
super.handleItemToClient(item);
|
||||
|
||||
if (item.getTag() != null) {
|
||||
if (item.tag() != null) {
|
||||
CompoundTag backupTag = new CompoundTag();
|
||||
if (handleNbtToClient(item.getTag(), backupTag)) {
|
||||
item.getTag().put("Via|LongArrayTags", backupTag);
|
||||
if (handleNbtToClient(item.tag(), backupTag)) {
|
||||
item.tag().put("Via|LongArrayTags", backupTag);
|
||||
}
|
||||
}
|
||||
|
||||
@ -299,10 +296,10 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<Protocol1_11_1
|
||||
if (item == null) return null;
|
||||
super.handleItemToServer(item);
|
||||
|
||||
if (item.getTag() != null) {
|
||||
Tag tag = item.getTag().remove("Via|LongArrayTags");
|
||||
if (item.tag() != null) {
|
||||
Tag tag = item.tag().remove("Via|LongArrayTags");
|
||||
if (tag instanceof CompoundTag) {
|
||||
handleNbtToServer(item.getTag(), (CompoundTag) tag);
|
||||
handleNbtToServer(item.tag(), (CompoundTag) tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<Protocol1_11_1To1_12
|
||||
int objType = objectData & 4095;
|
||||
int data = objectData >> 12 & 15;
|
||||
|
||||
Block block = protocol.getBlockItemPackets().handleBlock(objType, data);
|
||||
Block block = protocol.getItemRewriter().handleBlock(objType, data);
|
||||
if (block == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.packets.EntityP
|
||||
import com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.packets.ItemPackets1_11_1;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_11Types;
|
||||
import com.viaversion.viaversion.api.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
|
||||
@ -31,6 +32,7 @@ import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.Client
|
||||
public class Protocol1_11To1_11_1 extends BackwardsProtocol<ClientboundPackets1_9_3, ClientboundPackets1_9_3, ServerboundPackets1_9_3, ServerboundPackets1_9_3> {
|
||||
|
||||
private final EntityPackets1_11_1 entityPackets = new EntityPackets1_11_1(this);
|
||||
private final ItemRewriter itemRewriter = new ItemPackets1_11_1(this);
|
||||
|
||||
public Protocol1_11To1_11_1() {
|
||||
super(ClientboundPackets1_9_3.class, ClientboundPackets1_9_3.class, ServerboundPackets1_9_3.class, ServerboundPackets1_9_3.class);
|
||||
@ -39,7 +41,7 @@ public class Protocol1_11To1_11_1 extends BackwardsProtocol<ClientboundPackets1_
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
entityPackets.register();
|
||||
new ItemPackets1_11_1(this).register();
|
||||
itemRewriter.register();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -56,4 +58,9 @@ public class Protocol1_11To1_11_1 extends BackwardsProtocol<ClientboundPackets1_
|
||||
public EntityPackets1_11_1 getEntityRewriter() {
|
||||
return entityPackets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemRewriter getItemRewriter() {
|
||||
return itemRewriter;
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
|
||||
public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<Protocol1_11To1_11_1> {
|
||||
|
||||
@ -42,11 +41,9 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<Protocol1_11To1_1
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
|
||||
|
||||
itemRewriter.registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM);
|
||||
itemRewriter.registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM_ARRAY);
|
||||
itemRewriter.registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM);
|
||||
registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM);
|
||||
registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM_ARRAY);
|
||||
registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM);
|
||||
|
||||
// Plugin message Packet -> Trading
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketRemapper() {
|
||||
@ -80,8 +77,8 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<Protocol1_11To1_1
|
||||
}
|
||||
});
|
||||
|
||||
itemRewriter.registerClickWindow(ServerboundPackets1_9_3.CLICK_WINDOW, Type.ITEM);
|
||||
itemRewriter.registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM);
|
||||
registerClickWindow(ServerboundPackets1_9_3.CLICK_WINDOW, Type.ITEM);
|
||||
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM);
|
||||
|
||||
// Handle item metadata
|
||||
protocol.getEntityRewriter().filter().handler((event, meta) -> {
|
||||
@ -98,11 +95,11 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<Protocol1_11To1_1
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToClient(final Item item) {
|
||||
public Item handleItemToClient(Item item) {
|
||||
if (item == null) return null;
|
||||
super.handleItemToClient(item);
|
||||
|
||||
CompoundTag tag = item.getTag();
|
||||
CompoundTag tag = item.tag();
|
||||
if (tag == null) return item;
|
||||
|
||||
if (tag.get("ench") instanceof ListTag) {
|
||||
@ -115,11 +112,11 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<Protocol1_11To1_1
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToServer(final Item item) {
|
||||
public Item handleItemToServer(Item item) {
|
||||
if (item == null) return null;
|
||||
super.handleItemToServer(item);
|
||||
|
||||
CompoundTag tag = item.getTag();
|
||||
CompoundTag tag = item.tag();
|
||||
if (tag == null) return item;
|
||||
|
||||
if (tag.contains(nbtTagName + "|ench")) {
|
||||
|
@ -48,7 +48,7 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_
|
||||
|
||||
public static final BackwardsMappings MAPPINGS = new BackwardsMappings();
|
||||
private final EntityRewriter entityRewriter = new EntityPackets1_13(this);
|
||||
private BlockItemPackets1_13 blockItemPackets;
|
||||
private final BlockItemPackets1_13 blockItemPackets = new BlockItemPackets1_13(this);
|
||||
|
||||
public Protocol1_12_2To1_13() {
|
||||
super(ClientboundPackets1_13.class, ClientboundPackets1_12_1.class, ServerboundPackets1_13.class, ServerboundPackets1_12_1.class);
|
||||
@ -80,7 +80,7 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_
|
||||
translatableRewriter.registerTitle(ClientboundPackets1_13.TITLE);
|
||||
translatableRewriter.registerTabList(ClientboundPackets1_13.TAB_LIST);
|
||||
|
||||
(blockItemPackets = new BlockItemPackets1_13(this)).register();
|
||||
blockItemPackets.register();
|
||||
entityRewriter.register();
|
||||
new PlayerPacket1_13(this).register();
|
||||
new SoundPackets1_13(this).register();
|
||||
@ -113,10 +113,6 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_
|
||||
}
|
||||
}
|
||||
|
||||
public BlockItemPackets1_13 getBlockItemPackets() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BackwardsMappings getMappingData() {
|
||||
return MAPPINGS;
|
||||
@ -126,4 +122,9 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_
|
||||
public EntityRewriter getEntityRewriter() {
|
||||
return entityRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemPackets1_13 getItemRewriter() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
}
|
||||
|
@ -118,8 +118,8 @@ public class ParticleMapping {
|
||||
}
|
||||
|
||||
private int[] rewrite(Protocol1_12_2To1_13 protocol, Item newItem) {
|
||||
Item item = protocol.getBlockItemPackets().handleItemToClient(newItem);
|
||||
return new int[]{item.getIdentifier(), item.getData()};
|
||||
Item item = protocol.getItemRewriter().handleItemToClient(newItem);
|
||||
return new int[]{item.identifier(), item.data()};
|
||||
}
|
||||
}), // (27->36) minecraft:item -> iconcrack
|
||||
rewrite(33), // (28->33) minecraft:item_slime -> slime
|
||||
|
@ -54,7 +54,6 @@ import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.SpawnEggRew
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -259,15 +258,13 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
});
|
||||
|
||||
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_13.WINDOW_ITEMS, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.UNSIGNED_BYTE);
|
||||
map(Type.FLAT_ITEM_ARRAY, Type.ITEM_ARRAY);
|
||||
|
||||
handler(itemRewriter.itemArrayHandler(Type.ITEM_ARRAY));
|
||||
handler(itemArrayHandler(Type.ITEM_ARRAY));
|
||||
}
|
||||
});
|
||||
|
||||
@ -278,7 +275,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
map(Type.SHORT);
|
||||
map(Type.FLAT_ITEM, Type.ITEM);
|
||||
|
||||
handler(itemRewriter.itemToClientHandler(Type.ITEM));
|
||||
handler(itemToClientHandler(Type.ITEM));
|
||||
}
|
||||
});
|
||||
|
||||
@ -458,7 +455,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
map(Type.VAR_INT);
|
||||
map(Type.FLAT_ITEM, Type.ITEM);
|
||||
|
||||
handler(itemRewriter.itemToClientHandler(Type.ITEM));
|
||||
handler(itemToClientHandler(Type.ITEM));
|
||||
}
|
||||
});
|
||||
|
||||
@ -486,7 +483,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
map(Type.SHORT);
|
||||
map(Type.ITEM, Type.FLAT_ITEM);
|
||||
|
||||
handler(itemRewriter.itemToServerHandler(Type.FLAT_ITEM));
|
||||
handler(itemToServerHandler(Type.FLAT_ITEM));
|
||||
}
|
||||
});
|
||||
|
||||
@ -500,7 +497,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
map(Type.VAR_INT);
|
||||
map(Type.ITEM, Type.FLAT_ITEM);
|
||||
|
||||
handler(itemRewriter.itemToServerHandler(Type.FLAT_ITEM));
|
||||
handler(itemToServerHandler(Type.FLAT_ITEM));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -518,12 +515,12 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
if (item == null) return null;
|
||||
|
||||
// Custom mappings/super call moved down
|
||||
int originalId = item.getIdentifier();
|
||||
int originalId = item.identifier();
|
||||
|
||||
Integer rawId = null;
|
||||
boolean gotRawIdFromTag = false;
|
||||
|
||||
CompoundTag tag = item.getTag();
|
||||
CompoundTag tag = item.tag();
|
||||
|
||||
// Use tag to get original ID and data
|
||||
Tag originalIdTag;
|
||||
@ -537,7 +534,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
super.handleItemToClient(item);
|
||||
|
||||
// Handle one-way special case
|
||||
if (item.getIdentifier() == -1) {
|
||||
if (item.identifier() == -1) {
|
||||
if (originalId == 362) { // base/colorless shulker box
|
||||
rawId = 0xe50000; // purple shulker box
|
||||
} else {
|
||||
@ -550,10 +547,10 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
} else { // Use the found custom mapping
|
||||
// Take the newly added tag
|
||||
if (tag == null) {
|
||||
tag = item.getTag();
|
||||
tag = item.tag();
|
||||
}
|
||||
|
||||
rawId = itemIdToRaw(item.getIdentifier(), item, tag);
|
||||
rawId = itemIdToRaw(item.identifier(), item, tag);
|
||||
}
|
||||
}
|
||||
|
||||
@ -562,14 +559,14 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
// NBT changes
|
||||
if (tag != null) {
|
||||
if (isDamageable(item.getIdentifier())) {
|
||||
if (isDamageable(item.identifier())) {
|
||||
Tag damageTag = tag.remove("Damage");
|
||||
if (!gotRawIdFromTag && damageTag instanceof IntTag) {
|
||||
item.setData((short) (int) damageTag.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
if (item.getIdentifier() == 358) { // map
|
||||
if (item.identifier() == 358) { // map
|
||||
Tag mapTag = tag.remove("map");
|
||||
if (!gotRawIdFromTag && mapTag instanceof IntTag) {
|
||||
item.setData((short) (int) mapTag.getValue());
|
||||
@ -757,21 +754,21 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
@Override
|
||||
public Item handleItemToServer(Item item) {
|
||||
if (item == null) return null;
|
||||
CompoundTag tag = item.getTag();
|
||||
CompoundTag tag = item.tag();
|
||||
|
||||
// Save original id
|
||||
int originalId = (item.getIdentifier() << 16 | item.getData() & 0xFFFF);
|
||||
int originalId = (item.identifier() << 16 | item.data() & 0xFFFF);
|
||||
|
||||
int rawId = (item.getIdentifier() << 4 | item.getData() & 0xF);
|
||||
int rawId = (item.identifier() << 4 | item.data() & 0xF);
|
||||
|
||||
// NBT Additions
|
||||
if (isDamageable(item.getIdentifier())) {
|
||||
if (isDamageable(item.identifier())) {
|
||||
if (tag == null) item.setTag(tag = new CompoundTag());
|
||||
tag.put("Damage", new IntTag(item.getData()));
|
||||
tag.put("Damage", new IntTag(item.data()));
|
||||
}
|
||||
if (item.getIdentifier() == 358) { // map
|
||||
if (item.identifier() == 358) { // map
|
||||
if (tag == null) item.setTag(tag = new CompoundTag());
|
||||
tag.put("map", new IntTag(item.getData()));
|
||||
tag.put("map", new IntTag(item.data()));
|
||||
}
|
||||
|
||||
// NBT Changes
|
||||
@ -798,7 +795,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
rewriteCanPlaceToServer(tag, "CanDestroy");
|
||||
|
||||
// Handle SpawnEggs
|
||||
if (item.getIdentifier() == 383) {
|
||||
if (item.identifier() == 383) {
|
||||
CompoundTag entityTag = tag.get("EntityTag");
|
||||
StringTag identifier;
|
||||
if (entityTag != null && (identifier = entityTag.get("id")) != null) {
|
||||
@ -822,32 +819,32 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
|
||||
// Handle custom mappings
|
||||
int identifier = item.getIdentifier();
|
||||
int identifier = item.identifier();
|
||||
item.setIdentifier(rawId);
|
||||
super.handleItemToServer(item);
|
||||
|
||||
// Mapped with original data, we can return here
|
||||
if (item.getIdentifier() != rawId && item.getIdentifier() != -1) return item;
|
||||
if (item.identifier() != rawId && item.identifier() != -1) return item;
|
||||
|
||||
// Set to legacy id again
|
||||
item.setIdentifier(identifier);
|
||||
|
||||
int newId = -1;
|
||||
if (!protocol.getMappingData().getItemMappings().inverse().containsKey(rawId)) {
|
||||
if (!isDamageable(item.getIdentifier()) && item.getIdentifier() != 358) { // Map
|
||||
if (!isDamageable(item.identifier()) && item.identifier() != 358) { // Map
|
||||
if (tag == null) item.setTag(tag = new CompoundTag());
|
||||
tag.put(extraNbtTag, new IntTag(originalId)); // Data will be lost, saving original id
|
||||
}
|
||||
|
||||
if (item.getIdentifier() == 229) { // purple shulker box
|
||||
if (item.identifier() == 229) { // purple shulker box
|
||||
newId = 362; // directly set the new id -> base/colorless shulker box
|
||||
} else if (item.getIdentifier() == 31 && item.getData() == 0) { // Shrub was removed
|
||||
} else if (item.identifier() == 31 && item.data() == 0) { // Shrub was removed
|
||||
rawId = 32 << 4; // Dead Bush
|
||||
} else if (protocol.getMappingData().getItemMappings().inverse().containsKey(rawId & ~0xF)) {
|
||||
rawId &= ~0xF; // Remove data
|
||||
} else {
|
||||
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Failed to get 1.13 item for " + item.getIdentifier());
|
||||
ViaBackwards.getPlatform().getLogger().warning("Failed to get 1.13 item for " + item.identifier());
|
||||
}
|
||||
rawId = 16; // Stone
|
||||
}
|
||||
@ -961,7 +958,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
|
||||
private void invertShieldAndBannerId(Item item, CompoundTag tag) {
|
||||
if (item.getIdentifier() != 442 && item.getIdentifier() != 425) return;
|
||||
if (item.identifier() != 442 && item.identifier() != 425) return;
|
||||
|
||||
Tag blockEntityTag = tag.get("BlockEntityTag");
|
||||
if (!(blockEntityTag instanceof CompoundTag)) return;
|
||||
|
@ -314,7 +314,7 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<Protocol1_12_2To1_13
|
||||
// Rewrite items
|
||||
else if (typeId == 6) {
|
||||
Item item = (Item) meta.getValue();
|
||||
meta.setTypeAndValue(MetaType1_12.Slot, protocol.getBlockItemPackets().handleItemToClient(item));
|
||||
meta.setTypeAndValue(MetaType1_12.Slot, protocol.getItemRewriter().handleItemToClient(item));
|
||||
}
|
||||
|
||||
// Discontinue particles
|
||||
|
@ -92,16 +92,16 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
|
||||
for (int i = 0; i < size; i++) {
|
||||
//Input Item
|
||||
Item input = wrapper.read(Type.FLAT_ITEM);
|
||||
wrapper.write(Type.ITEM, protocol.getBlockItemPackets().handleItemToClient(input));
|
||||
wrapper.write(Type.ITEM, protocol.getItemRewriter().handleItemToClient(input));
|
||||
//Output Item
|
||||
Item output = wrapper.read(Type.FLAT_ITEM);
|
||||
wrapper.write(Type.ITEM, protocol.getBlockItemPackets().handleItemToClient(output));
|
||||
wrapper.write(Type.ITEM, protocol.getItemRewriter().handleItemToClient(output));
|
||||
|
||||
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); //Has second item
|
||||
if (secondItem) {
|
||||
//Second Item
|
||||
Item second = wrapper.read(Type.FLAT_ITEM);
|
||||
wrapper.write(Type.ITEM, protocol.getBlockItemPackets().handleItemToClient(second));
|
||||
wrapper.write(Type.ITEM, protocol.getItemRewriter().handleItemToClient(second));
|
||||
}
|
||||
|
||||
wrapper.passthrough(Type.BOOLEAN); //Trade disabled
|
||||
@ -447,7 +447,7 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
|
||||
case "MC|BEdit":
|
||||
wrapper.setId(0x0B);
|
||||
Item book = wrapper.read(Type.ITEM);
|
||||
wrapper.write(Type.FLAT_ITEM, protocol.getBlockItemPackets().handleItemToServer(book));
|
||||
wrapper.write(Type.FLAT_ITEM, protocol.getItemRewriter().handleItemToServer(book));
|
||||
boolean signing = channel.equals("MC|BSign");
|
||||
wrapper.write(Type.BOOLEAN, signing);
|
||||
break;
|
||||
|
@ -196,10 +196,6 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol<ClientboundPackets1_
|
||||
}
|
||||
}
|
||||
|
||||
public BlockItemPackets1_14 getBlockItemPackets() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BackwardsMappings getMappingData() {
|
||||
return MAPPINGS;
|
||||
@ -209,4 +205,9 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol<ClientboundPackets1_
|
||||
public EntityRewriter getEntityRewriter() {
|
||||
return entityRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemPackets1_14 getItemRewriter() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,6 @@ import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.rewriter.RecipeRewriter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -191,13 +190,12 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
});
|
||||
|
||||
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
|
||||
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION);
|
||||
|
||||
itemRewriter.registerSetCooldown(ClientboundPackets1_14.COOLDOWN);
|
||||
itemRewriter.registerWindowItems(ClientboundPackets1_14.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
|
||||
itemRewriter.registerSetSlot(ClientboundPackets1_14.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
|
||||
itemRewriter.registerAdvancements(ClientboundPackets1_14.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
|
||||
registerSetCooldown(ClientboundPackets1_14.COOLDOWN);
|
||||
registerWindowItems(ClientboundPackets1_14.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
|
||||
registerSetSlot(ClientboundPackets1_14.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
|
||||
registerAdvancements(ClientboundPackets1_14.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
|
||||
|
||||
// Trade List -> Plugin Message
|
||||
protocol.registerClientbound(ClientboundPackets1_14.TRADE_LIST, ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketRemapper() {
|
||||
@ -269,7 +267,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
|
||||
map(Type.VAR_INT); // 1 - Slot ID
|
||||
map(Type.FLAT_VAR_INT_ITEM); // 2 - Item
|
||||
|
||||
handler(itemRewriter.itemToClientHandler(Type.FLAT_VAR_INT_ITEM));
|
||||
handler(itemToClientHandler(Type.FLAT_VAR_INT_ITEM));
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
@ -284,7 +282,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
|
||||
wrapper.passthrough(Type.VAR_INT);
|
||||
wrapper.read(Type.VAR_INT);
|
||||
Item item = wrapper.read(Type.FLAT_VAR_INT_ITEM);
|
||||
int armorType = item == null || item.getIdentifier() == 0 ? 0 : item.getIdentifier() - 726;
|
||||
int armorType = item == null || item.identifier() == 0 ? 0 : item.identifier() - 726;
|
||||
if (armorType < 0 || armorType > 3) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Received invalid horse armor: " + item);
|
||||
wrapper.cancel();
|
||||
@ -299,7 +297,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
});
|
||||
|
||||
RecipeRewriter recipeHandler = new RecipeRewriter1_13_2(protocol, this::handleItemToClient);
|
||||
RecipeRewriter recipeHandler = new RecipeRewriter1_13_2(protocol);
|
||||
protocol.registerClientbound(ClientboundPackets1_14.DECLARE_RECIPES, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
@ -347,8 +345,8 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
|
||||
});
|
||||
|
||||
|
||||
itemRewriter.registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
|
||||
itemRewriter.registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
|
||||
registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
|
||||
registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_14.BLOCK_BREAK_ANIMATION, new PacketRemapper() {
|
||||
@Override
|
||||
@ -515,7 +513,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
});
|
||||
|
||||
itemRewriter.registerSpawnParticle(ClientboundPackets1_14.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.FLOAT);
|
||||
registerSpawnParticle(ClientboundPackets1_14.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.FLOAT);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_14.MAP_DATA, new PacketRemapper() {
|
||||
@Override
|
||||
@ -549,7 +547,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
|
||||
super.handleItemToClient(item);
|
||||
|
||||
// Lore now uses JSON
|
||||
CompoundTag tag = item.getTag();
|
||||
CompoundTag tag = item.tag();
|
||||
CompoundTag display;
|
||||
if (tag != null && (display = tag.get("display")) != null) {
|
||||
ListTag lore = display.get("Lore");
|
||||
@ -577,7 +575,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
|
||||
if (item == null) return null;
|
||||
|
||||
// Lore now uses JSON
|
||||
CompoundTag tag = item.getTag();
|
||||
CompoundTag tag = item.tag();
|
||||
CompoundTag display;
|
||||
if (tag != null && (display = tag.get("display")) != null) {
|
||||
// Transform to json if no backup tag is found (else process that in the super method)
|
||||
|
@ -365,7 +365,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
|
||||
|
||||
if (type == MetaType1_13_2.Slot) {
|
||||
Item item = (Item) meta.getValue();
|
||||
meta.setValue(protocol.getBlockItemPackets().handleItemToClient(item));
|
||||
meta.setValue(protocol.getItemRewriter().handleItemToClient(item));
|
||||
} else if (type == MetaType1_13_2.BlockID) {
|
||||
int blockstate = (Integer) meta.getValue();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockstate));
|
||||
|
@ -32,6 +32,7 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
|
||||
import com.viaversion.viaversion.api.rewriter.EntityRewriter;
|
||||
import com.viaversion.viaversion.api.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
@ -49,6 +50,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
|
||||
|
||||
public static final BackwardsMappings MAPPINGS = new BackwardsMappings("1.13.2", "1.13", Protocol1_13_1To1_13.class, true);
|
||||
private final EntityRewriter entityRewriter = new EntityPackets1_13_1(this);
|
||||
private final ItemRewriter itemRewriter = new InventoryPackets1_13_1(this);
|
||||
|
||||
public Protocol1_13To1_13_1() {
|
||||
super(ClientboundPackets1_13.class, ClientboundPackets1_13.class, ServerboundPackets1_13.class, ServerboundPackets1_13.class);
|
||||
@ -59,7 +61,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
|
||||
executeAsyncAfterLoaded(Protocol1_13_1To1_13.class, MAPPINGS::load);
|
||||
|
||||
entityRewriter.register();
|
||||
InventoryPackets1_13_1.register(this);
|
||||
itemRewriter.register();
|
||||
WorldPackets1_13_1.register(this);
|
||||
|
||||
TranslatableRewriter translatableRewriter = new TranslatableRewriter(this);
|
||||
@ -94,7 +96,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
InventoryPackets1_13_1.toServer(wrapper.get(Type.FLAT_ITEM, 0));
|
||||
itemRewriter.handleItemToServer(wrapper.get(Type.FLAT_ITEM, 0));
|
||||
wrapper.write(Type.VAR_INT, 0);
|
||||
}
|
||||
});
|
||||
@ -191,7 +193,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
|
||||
wrapper.passthrough(Type.COMPONENT); // Title
|
||||
wrapper.passthrough(Type.COMPONENT); // Description
|
||||
Item icon = wrapper.passthrough(Type.FLAT_ITEM);
|
||||
InventoryPackets1_13_1.toClient(icon);
|
||||
itemRewriter.handleItemToClient(icon);
|
||||
wrapper.passthrough(Type.VAR_INT); // Frame type
|
||||
int flags = wrapper.passthrough(Type.INT); // Flags
|
||||
if ((flags & 1) != 0)
|
||||
@ -234,4 +236,9 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
|
||||
public EntityRewriter getEntityRewriter() {
|
||||
return entityRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemRewriter getItemRewriter() {
|
||||
return itemRewriter;
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ public class EntityPackets1_13_1 extends LegacyEntityRewriter<Protocol1_13To1_13
|
||||
// Rewrite items & blocks
|
||||
filter().handler((event, meta) -> {
|
||||
if (meta.metaType() == MetaType1_13.Slot) {
|
||||
InventoryPackets1_13_1.toClient((Item) meta.getValue());
|
||||
protocol.getItemRewriter().handleItemToClient((Item) meta.getValue());
|
||||
} else if (meta.metaType() == MetaType1_13.BlockID) {
|
||||
// Convert to new block id
|
||||
int data = (int) meta.getValue();
|
||||
|
@ -19,7 +19,6 @@ package com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.packets;
|
||||
|
||||
import com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
@ -28,14 +27,17 @@ import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPacke
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
|
||||
public class InventoryPackets1_13_1 {
|
||||
public class InventoryPackets1_13_1 extends ItemRewriter<Protocol1_13To1_13_1> {
|
||||
|
||||
public static void register(Protocol protocol) {
|
||||
ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets1_13_1::toClient, InventoryPackets1_13_1::toServer);
|
||||
public InventoryPackets1_13_1(Protocol1_13To1_13_1 protocol) {
|
||||
super(protocol);
|
||||
}
|
||||
|
||||
itemRewriter.registerSetCooldown(ClientboundPackets1_13.COOLDOWN);
|
||||
itemRewriter.registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS, Type.FLAT_ITEM_ARRAY);
|
||||
itemRewriter.registerSetSlot(ClientboundPackets1_13.SET_SLOT, Type.FLAT_ITEM);
|
||||
@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
|
||||
@ -51,16 +53,16 @@ public class InventoryPackets1_13_1 {
|
||||
for (int i = 0; i < size; i++) {
|
||||
//Input Item
|
||||
Item input = wrapper.passthrough(Type.FLAT_ITEM);
|
||||
toClient(input);
|
||||
handleItemToClient(input);
|
||||
//Output Item
|
||||
Item output = wrapper.passthrough(Type.FLAT_ITEM);
|
||||
toClient(output);
|
||||
handleItemToClient(output);
|
||||
|
||||
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); //Has second item
|
||||
if (secondItem) {
|
||||
//Second Item
|
||||
Item second = wrapper.passthrough(Type.FLAT_ITEM);
|
||||
toClient(second);
|
||||
handleItemToClient(second);
|
||||
}
|
||||
|
||||
wrapper.passthrough(Type.BOOLEAN); //Trade disabled
|
||||
@ -73,20 +75,10 @@ public class InventoryPackets1_13_1 {
|
||||
}
|
||||
});
|
||||
|
||||
itemRewriter.registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT, Type.FLAT_ITEM);
|
||||
itemRewriter.registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW, Type.FLAT_ITEM);
|
||||
itemRewriter.registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, Type.FLAT_ITEM);
|
||||
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);
|
||||
|
||||
itemRewriter.registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, Type.FLAT_ITEM, Type.FLOAT);
|
||||
}
|
||||
|
||||
public static void toClient(Item item) {
|
||||
if (item == null) return;
|
||||
item.setIdentifier(Protocol1_13To1_13_1.MAPPINGS.getNewItemId(item.getIdentifier()));
|
||||
}
|
||||
|
||||
public static void toServer(Item item) {
|
||||
if (item == null) return;
|
||||
item.setIdentifier(Protocol1_13To1_13_1.MAPPINGS.getOldItemId(item.getIdentifier()));
|
||||
registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, Type.FLAT_ITEM, Type.FLOAT);
|
||||
}
|
||||
}
|
||||
|
@ -66,8 +66,7 @@ public class Protocol1_14_2To1_14_3 extends BackwardsProtocol<ClientboundPackets
|
||||
}
|
||||
});
|
||||
|
||||
RecipeRewriter recipeHandler = new RecipeRewriter1_14(this, item -> {
|
||||
});
|
||||
RecipeRewriter recipeHandler = new RecipeRewriter1_14(this);
|
||||
registerClientbound(ClientboundPackets1_14.DECLARE_RECIPES, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
|
@ -108,10 +108,6 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol<ClientboundPackets1_
|
||||
user.addEntityTracker(getClass(), new EntityTrackerBase(user, Entity1_15Types.PLAYER));
|
||||
}
|
||||
|
||||
public BlockItemPackets1_15 getBlockItemPackets() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BackwardsMappings getMappingData() {
|
||||
return MAPPINGS;
|
||||
@ -121,4 +117,9 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol<ClientboundPackets1_
|
||||
public EntityRewriter getEntityRewriter() {
|
||||
return entityRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemPackets1_15 getItemRewriter() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.types.Chunk1_14T
|
||||
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
|
||||
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type;
|
||||
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
|
||||
public class BlockItemPackets1_15 extends com.viaversion.viabackwards.api.rewriters.ItemRewriter<Protocol1_14_4To1_15> {
|
||||
|
||||
@ -42,10 +41,9 @@ public class BlockItemPackets1_15 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
|
||||
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
|
||||
|
||||
new RecipeRewriter1_14(protocol, this::handleItemToClient).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES);
|
||||
new RecipeRewriter1_14(protocol).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES);
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {
|
||||
@Override
|
||||
@ -54,14 +52,14 @@ public class BlockItemPackets1_15 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
});
|
||||
|
||||
itemRewriter.registerSetCooldown(ClientboundPackets1_15.COOLDOWN);
|
||||
itemRewriter.registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
|
||||
itemRewriter.registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
|
||||
itemRewriter.registerTradeList(ClientboundPackets1_15.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
|
||||
itemRewriter.registerEntityEquipment(ClientboundPackets1_15.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
|
||||
itemRewriter.registerAdvancements(ClientboundPackets1_15.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
|
||||
itemRewriter.registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
|
||||
itemRewriter.registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, 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);
|
||||
|
@ -46,7 +46,6 @@ import com.viaversion.viaversion.rewriter.RegistryType;
|
||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -207,10 +206,6 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol<ClientboundPackets1_
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_16Types.PLAYER));
|
||||
}
|
||||
|
||||
public BlockItemPackets1_16 getBlockItemPackets() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableRewriter getTranslatableRewriter() {
|
||||
return translatableRewriter;
|
||||
@ -225,4 +220,9 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol<ClientboundPackets1_
|
||||
public EntityRewriter getEntityRewriter() {
|
||||
return entityRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemPackets1_16 getItemRewriter() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,6 @@ import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPacke
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.InventoryPackets;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type;
|
||||
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.util.CompactArrayUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -61,10 +60,9 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
|
||||
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
|
||||
|
||||
RecipeRewriter1_14 recipeRewriter = new RecipeRewriter1_14(protocol, this::handleItemToClient);
|
||||
RecipeRewriter1_14 recipeRewriter = new RecipeRewriter1_14(protocol);
|
||||
// Remove new smithing type, only in this handler
|
||||
protocol.registerClientbound(ClientboundPackets1_16.DECLARE_RECIPES, new PacketRemapper() {
|
||||
@Override
|
||||
@ -95,11 +93,11 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
});
|
||||
|
||||
itemRewriter.registerSetCooldown(ClientboundPackets1_16.COOLDOWN);
|
||||
itemRewriter.registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
|
||||
itemRewriter.registerSetSlot(ClientboundPackets1_16.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
|
||||
itemRewriter.registerTradeList(ClientboundPackets1_16.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
|
||||
itemRewriter.registerAdvancements(ClientboundPackets1_16.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
|
||||
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);
|
||||
@ -196,7 +194,7 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
blockRewriter.registerEffect(ClientboundPackets1_16.EFFECT, 1010, 2001);
|
||||
|
||||
itemRewriter.registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
|
||||
registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_16.WINDOW_PROPERTY, new PacketRemapper() {
|
||||
@Override
|
||||
@ -241,8 +239,8 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
});
|
||||
|
||||
itemRewriter.registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
|
||||
itemRewriter.registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, 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);
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {
|
||||
@Override
|
||||
@ -296,8 +294,8 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
super.handleItemToClient(item);
|
||||
|
||||
CompoundTag tag = item.getTag();
|
||||
if (item.getIdentifier() == 771 && tag != null) {
|
||||
CompoundTag tag = item.tag();
|
||||
if (item.identifier() == 771 && tag != null) {
|
||||
Tag ownerTag = tag.get("SkullOwner");
|
||||
if (ownerTag instanceof CompoundTag) {
|
||||
CompoundTag ownerCompundTag = (CompoundTag) ownerTag;
|
||||
@ -318,10 +316,10 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
|
||||
public Item handleItemToServer(Item item) {
|
||||
if (item == null) return null;
|
||||
|
||||
int identifier = item.getIdentifier();
|
||||
int identifier = item.identifier();
|
||||
super.handleItemToServer(item);
|
||||
|
||||
CompoundTag tag = item.getTag();
|
||||
CompoundTag tag = item.tag();
|
||||
if (identifier == 771 && tag != null) {
|
||||
Tag ownerTag = tag.get("SkullOwner");
|
||||
if (ownerTag instanceof CompoundTag) {
|
||||
|
@ -246,7 +246,7 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
|
||||
filter().handler((event, meta) -> {
|
||||
MetaType type = meta.metaType();
|
||||
if (type == MetaType1_14.Slot) {
|
||||
meta.setValue(protocol.getBlockItemPackets().handleItemToClient((Item) meta.getValue()));
|
||||
meta.setValue(protocol.getItemRewriter().handleItemToClient((Item) meta.getValue()));
|
||||
} else if (type == MetaType1_14.BlockID) {
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId((int) meta.getValue()));
|
||||
} else if (type == MetaType1_14.PARTICLE) {
|
||||
|
@ -140,10 +140,6 @@ public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_16_2Types.PLAYER));
|
||||
}
|
||||
|
||||
public BlockItemPackets1_16_2 getBlockItemPackets() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
|
||||
public TranslatableRewriter getTranslatableRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
@ -157,4 +153,9 @@ public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets
|
||||
public EntityRewriter getEntityRewriter() {
|
||||
return entityRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemPackets1_16_2 getItemRewriter() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,6 @@ import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPacke
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type;
|
||||
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
|
||||
public class BlockItemPackets1_16_2 extends com.viaversion.viabackwards.api.rewriters.ItemRewriter<Protocol1_16_1To1_16_2> {
|
||||
|
||||
@ -48,17 +47,16 @@ public class BlockItemPackets1_16_2 extends com.viaversion.viabackwards.api.rewr
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
|
||||
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
|
||||
|
||||
new RecipeRewriter1_16(protocol, this::handleItemToClient).registerDefaultHandler(ClientboundPackets1_16_2.DECLARE_RECIPES);
|
||||
new RecipeRewriter1_16(protocol).registerDefaultHandler(ClientboundPackets1_16_2.DECLARE_RECIPES);
|
||||
|
||||
itemRewriter.registerSetCooldown(ClientboundPackets1_16_2.COOLDOWN);
|
||||
itemRewriter.registerWindowItems(ClientboundPackets1_16_2.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
|
||||
itemRewriter.registerSetSlot(ClientboundPackets1_16_2.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
|
||||
itemRewriter.registerEntityEquipmentArray(ClientboundPackets1_16_2.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
|
||||
itemRewriter.registerTradeList(ClientboundPackets1_16_2.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
|
||||
itemRewriter.registerAdvancements(ClientboundPackets1_16_2.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
|
||||
registerSetCooldown(ClientboundPackets1_16_2.COOLDOWN);
|
||||
registerWindowItems(ClientboundPackets1_16_2.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
|
||||
registerSetSlot(ClientboundPackets1_16_2.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
|
||||
registerEntityEquipmentArray(ClientboundPackets1_16_2.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
|
||||
registerTradeList(ClientboundPackets1_16_2.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
|
||||
registerAdvancements(ClientboundPackets1_16_2.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_16_2.UNLOCK_RECIPES, new PacketRemapper() {
|
||||
@Override
|
||||
@ -151,10 +149,10 @@ public class BlockItemPackets1_16_2 extends com.viaversion.viabackwards.api.rewr
|
||||
|
||||
blockRewriter.registerEffect(ClientboundPackets1_16_2.EFFECT, 1010, 2001);
|
||||
|
||||
itemRewriter.registerSpawnParticle(ClientboundPackets1_16_2.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
|
||||
registerSpawnParticle(ClientboundPackets1_16_2.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
|
||||
|
||||
itemRewriter.registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
|
||||
itemRewriter.registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
|
||||
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.EDIT_BOOK, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
|
@ -231,11 +231,6 @@ public class Protocol1_16_4To1_17 extends BackwardsProtocol<ClientboundPackets1_
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_17Types.PLAYER));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemPackets1_17 getBlockItemPackets() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
|
||||
public TranslatableRewriter getTranslatableRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
@ -261,4 +256,9 @@ public class Protocol1_16_4To1_17 extends BackwardsProtocol<ClientboundPackets1_
|
||||
public EntityRewriter getEntityRewriter() {
|
||||
return entityRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemPackets1_17 getItemRewriter() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewri
|
||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17;
|
||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.types.Chunk1_17Type;
|
||||
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -50,24 +49,23 @@ public class BlockItemPackets1_17 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
|
||||
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
|
||||
|
||||
new RecipeRewriter1_16(protocol, this::handleItemToClient).registerDefaultHandler(ClientboundPackets1_17.DECLARE_RECIPES);
|
||||
new RecipeRewriter1_16(protocol).registerDefaultHandler(ClientboundPackets1_17.DECLARE_RECIPES);
|
||||
|
||||
itemRewriter.registerSetCooldown(ClientboundPackets1_17.COOLDOWN);
|
||||
itemRewriter.registerWindowItems(ClientboundPackets1_17.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
|
||||
itemRewriter.registerSetSlot(ClientboundPackets1_17.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
|
||||
itemRewriter.registerEntityEquipmentArray(ClientboundPackets1_17.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
|
||||
itemRewriter.registerTradeList(ClientboundPackets1_17.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
|
||||
itemRewriter.registerAdvancements(ClientboundPackets1_17.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
|
||||
registerSetCooldown(ClientboundPackets1_17.COOLDOWN);
|
||||
registerWindowItems(ClientboundPackets1_17.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
|
||||
registerSetSlot(ClientboundPackets1_17.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
|
||||
registerEntityEquipmentArray(ClientboundPackets1_17.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
|
||||
registerTradeList(ClientboundPackets1_17.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
|
||||
registerAdvancements(ClientboundPackets1_17.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
|
||||
|
||||
blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_17.ACKNOWLEDGE_PLAYER_DIGGING);
|
||||
blockRewriter.registerBlockAction(ClientboundPackets1_17.BLOCK_ACTION);
|
||||
blockRewriter.registerEffect(ClientboundPackets1_17.EFFECT, 1010, 2001);
|
||||
|
||||
|
||||
itemRewriter.registerCreativeInvAction(ServerboundPackets1_16_2.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
|
||||
registerCreativeInvAction(ServerboundPackets1_16_2.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
|
||||
protocol.registerServerbound(ServerboundPackets1_16_2.EDIT_BOOK, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
@ -125,7 +123,7 @@ public class BlockItemPackets1_17 extends com.viaversion.viabackwards.api.rewrit
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
handler(itemRewriter.getSpawnParticleHandler(Type.FLAT_VAR_INT_ITEM));
|
||||
handler(getSpawnParticleHandler(Type.FLAT_VAR_INT_ITEM));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -43,7 +43,7 @@ public class Protocol1_9_4To1_10 extends BackwardsProtocol<ClientboundPackets1_9
|
||||
}
|
||||
};
|
||||
private final EntityPackets1_10 entityPackets = new EntityPackets1_10(this);
|
||||
private BlockItemPackets1_10 blockItemPackets;
|
||||
private final BlockItemPackets1_10 blockItemPackets = new BlockItemPackets1_10(this);
|
||||
|
||||
public Protocol1_9_4To1_10() {
|
||||
super(ClientboundPackets1_9_3.class, ClientboundPackets1_9_3.class, ServerboundPackets1_9_3.class, ServerboundPackets1_9_3.class);
|
||||
@ -51,7 +51,7 @@ public class Protocol1_9_4To1_10 extends BackwardsProtocol<ClientboundPackets1_9
|
||||
|
||||
protected void registerPackets() {
|
||||
entityPackets.register();
|
||||
(blockItemPackets = new BlockItemPackets1_10(this)).register();
|
||||
blockItemPackets.register();
|
||||
|
||||
SoundRewriter soundRewriter = new SoundRewriter(this);
|
||||
registerClientbound(ClientboundPackets1_9_3.NAMED_SOUND, new PacketRemapper() {
|
||||
@ -99,10 +99,6 @@ public class Protocol1_9_4To1_10 extends BackwardsProtocol<ClientboundPackets1_9
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_10Types.EntityType.PLAYER));
|
||||
}
|
||||
|
||||
public BlockItemPackets1_10 getBlockItemPackets() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BackwardsMappings getMappingData() {
|
||||
return MAPPINGS;
|
||||
@ -113,6 +109,11 @@ public class Protocol1_9_4To1_10 extends BackwardsProtocol<ClientboundPackets1_9
|
||||
return entityPackets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemPackets1_10 getItemRewriter() {
|
||||
return blockItemPackets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMappingDataToLoad() {
|
||||
return true;
|
||||
|
@ -31,7 +31,6 @@ import com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
|
||||
public class BlockItemPackets1_10 extends LegacyBlockItemRewriter<Protocol1_9_4To1_10> {
|
||||
|
||||
@ -41,13 +40,11 @@ public class BlockItemPackets1_10 extends LegacyBlockItemRewriter<Protocol1_9_4T
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
|
||||
|
||||
itemRewriter.registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM);
|
||||
itemRewriter.registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM_ARRAY);
|
||||
registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM);
|
||||
registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM_ARRAY);
|
||||
|
||||
// Entity Equipment Packet
|
||||
itemRewriter.registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM);
|
||||
registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketRemapper() {
|
||||
@Override
|
||||
@ -80,8 +77,8 @@ public class BlockItemPackets1_10 extends LegacyBlockItemRewriter<Protocol1_9_4T
|
||||
}
|
||||
});
|
||||
|
||||
itemRewriter.registerClickWindow(ServerboundPackets1_9_3.CLICK_WINDOW, Type.ITEM);
|
||||
itemRewriter.registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM);
|
||||
registerClickWindow(ServerboundPackets1_9_3.CLICK_WINDOW, Type.ITEM);
|
||||
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, new PacketRemapper() {
|
||||
@Override
|
||||
|
@ -74,7 +74,7 @@ public class EntityPackets1_10 extends LegacyEntityRewriter<Protocol1_9_4To1_10>
|
||||
int objType = objectData & 4095;
|
||||
int data = objectData >> 12 & 15;
|
||||
|
||||
Block block = protocol.getBlockItemPackets().handleBlock(objType, data);
|
||||
Block block = protocol.getItemRewriter().handleBlock(objType, data);
|
||||
if (block == null)
|
||||
return;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user