Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-11-17 13:30:14 +01:00
Various API changes to LegacyBlockItemRewriter (#703)
Dieser Commit ist enthalten in:
Ursprung
082cc010b2
Commit
4e856ef396
@ -67,7 +67,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
|
||||
// Save original id, set remapped id
|
||||
final CompoundTag tag = createCustomTag(item);
|
||||
tag.putInt(nbtTagName + "|id", item.identifier());
|
||||
tag.putInt(getNbtTagName() + "|id", item.identifier());
|
||||
item.setIdentifier(mappedItem.getId());
|
||||
|
||||
// Add custom model data
|
||||
@ -95,7 +95,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
|
||||
final CompoundTag tag = customTag(item);
|
||||
if (tag != null) {
|
||||
final Tag originalId = tag.remove(nbtTagName + "|id");
|
||||
final Tag originalId = tag.remove(getNbtTagName() + "|id");
|
||||
if (originalId instanceof IntTag) {
|
||||
item.setIdentifier(((NumberTag) originalId).asInt());
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
||||
}
|
||||
|
||||
// Save original id, set remapped id
|
||||
item.tag().putInt(nbtTagName + "|id", item.identifier());
|
||||
item.tag().putInt(getNbtTagName() + "|id", item.identifier());
|
||||
item.setIdentifier(data.getId());
|
||||
|
||||
// Add custom model data
|
||||
@ -105,7 +105,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
||||
}
|
||||
if (!display.contains("Name")) {
|
||||
display.put("Name", new StringTag(data.getJsonName()));
|
||||
display.put(nbtTagName + "|customName", new ByteTag());
|
||||
display.put(getNbtTagName() + "|customName", new ByteTag());
|
||||
}
|
||||
return item;
|
||||
}
|
||||
@ -116,7 +116,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
||||
|
||||
super.handleItemToServer(item);
|
||||
if (item.tag() != null) {
|
||||
Tag originalId = item.tag().remove(nbtTagName + "|id");
|
||||
Tag originalId = item.tag().remove(getNbtTagName() + "|id");
|
||||
if (originalId instanceof IntTag) {
|
||||
item.setIdentifier(((NumberTag) originalId).asInt());
|
||||
}
|
||||
|
@ -32,13 +32,13 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extends ServerboundPacketType,
|
||||
T extends BackwardsProtocol<C, ?, ?, S>> extends ItemRewriter<C, S, T> {
|
||||
|
||||
protected final String nbtTagName;
|
||||
protected final boolean jsonNameFormat;
|
||||
protected final String protocolName;
|
||||
|
||||
protected ItemRewriterBase(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, Type<Item> mappedItemType, Type<Item[]> mappedItemArrayType, boolean jsonFormat) {
|
||||
super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType);
|
||||
this.jsonNameFormat = jsonFormat;
|
||||
nbtTagName = "VB|" + protocol.getClass().getSimpleName();
|
||||
protocolName = protocol.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
protected ItemRewriterBase(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, boolean jsonNameFormat) {
|
||||
@ -55,12 +55,12 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
|
||||
}
|
||||
|
||||
protected boolean hasBackupTag(CompoundTag displayTag, String tagName) {
|
||||
return displayTag.contains(nbtTagName + "|o" + tagName);
|
||||
return displayTag.contains(getNbtTagName() + "|o" + tagName);
|
||||
}
|
||||
|
||||
protected void saveStringTag(CompoundTag displayTag, StringTag original, String name) {
|
||||
// Multiple places might try to backup data
|
||||
String backupName = nbtTagName + "|o" + name;
|
||||
String backupName = getNbtTagName() + "|o" + name;
|
||||
if (!displayTag.contains(backupName)) {
|
||||
displayTag.putString(backupName, original.getValue());
|
||||
}
|
||||
@ -68,7 +68,7 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
|
||||
|
||||
protected void saveListTag(CompoundTag displayTag, ListTag<?> original, String name) {
|
||||
// Multiple places might try to backup data
|
||||
String backupName = nbtTagName + "|o" + name;
|
||||
String backupName = getNbtTagName() + "|o" + name;
|
||||
if (!displayTag.contains(backupName)) {
|
||||
displayTag.put(backupName, original.copy());
|
||||
}
|
||||
@ -80,7 +80,7 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
|
||||
CompoundTag display = item.tag().getCompoundTag("display");
|
||||
if (display != null) {
|
||||
// Remove custom name / restore original name
|
||||
if (display.remove(nbtTagName + "|customName") != null) {
|
||||
if (display.remove(getNbtTagName() + "|customName") != null) {
|
||||
display.remove("Name");
|
||||
} else {
|
||||
restoreStringTag(display, "Name");
|
||||
@ -92,20 +92,20 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
|
||||
}
|
||||
|
||||
protected void restoreStringTag(CompoundTag tag, String tagName) {
|
||||
Tag original = tag.remove(nbtTagName + "|o" + tagName);
|
||||
Tag original = tag.remove(getNbtTagName() + "|o" + tagName);
|
||||
if (original instanceof StringTag) {
|
||||
tag.putString(tagName, ((StringTag) original).getValue());
|
||||
}
|
||||
}
|
||||
|
||||
protected void restoreListTag(CompoundTag tag, String tagName) {
|
||||
Tag original = tag.remove(nbtTagName + "|o" + tagName);
|
||||
Tag original = tag.remove(getNbtTagName() + "|o" + tagName);
|
||||
if (original instanceof ListTag) {
|
||||
tag.put(tagName, ((ListTag<?>) original).copy());
|
||||
}
|
||||
}
|
||||
|
||||
public String getNbtTagName() {
|
||||
return nbtTagName;
|
||||
return "VB|" + protocolName;
|
||||
}
|
||||
}
|
||||
|
@ -23,13 +23,17 @@ import com.viaversion.viabackwards.api.data.MappedLegacyBlockItem;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingDataLoader;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.BlockColors;
|
||||
import com.viaversion.viabackwards.utils.Block;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12;
|
||||
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.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
@ -43,26 +47,27 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
|
||||
T extends BackwardsProtocol<C, ?, ?, S>> extends ItemRewriterBase<C, S, T> {
|
||||
|
||||
private static final Map<String, Int2ObjectMap<MappedLegacyBlockItem>> LEGACY_MAPPINGS = new HashMap<>();
|
||||
protected final Int2ObjectMap<MappedLegacyBlockItem> replacementData; // Raw id -> mapped data
|
||||
protected final Int2ObjectMap<MappedLegacyBlockItem> replacementData = new Int2ObjectOpenHashMap<>(8); // Raw id -> mapped data
|
||||
|
||||
static {
|
||||
JsonObject jsonObject = BackwardsMappingDataLoader.INSTANCE.loadFromDataDir("legacy-mappings.json");
|
||||
for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
|
||||
Int2ObjectMap<MappedLegacyBlockItem> mappings = new Int2ObjectOpenHashMap<>(8);
|
||||
LEGACY_MAPPINGS.put(entry.getKey(), mappings);
|
||||
for (Map.Entry<String, JsonElement> dataEntry : entry.getValue().getAsJsonObject().entrySet()) {
|
||||
addMapping(dataEntry.getKey(), dataEntry.getValue().getAsJsonObject(), mappings);
|
||||
}
|
||||
protected LegacyBlockItemRewriter(T protocol, String name) {
|
||||
super(protocol, Type.ITEM1_8, Type.ITEM1_8_SHORT_ARRAY, false);
|
||||
final JsonObject jsonObject = readMappingsFile("item-mappings-" + name + ".json");
|
||||
for (Map.Entry<String, JsonElement> dataEntry : jsonObject.entrySet()) {
|
||||
addMapping(dataEntry.getKey(), dataEntry.getValue().getAsJsonObject(), replacementData);
|
||||
}
|
||||
}
|
||||
|
||||
private static void addMapping(String key, JsonObject object, Int2ObjectMap<MappedLegacyBlockItem> mappings) {
|
||||
protected JsonObject readMappingsFile(final String name) {
|
||||
return BackwardsMappingDataLoader.INSTANCE.loadFromDataDir(name);
|
||||
}
|
||||
|
||||
private void addMapping(String key, JsonObject object, Int2ObjectMap<MappedLegacyBlockItem> mappings) {
|
||||
int id = object.getAsJsonPrimitive("id").getAsInt();
|
||||
JsonPrimitive jsonData = object.getAsJsonPrimitive("data");
|
||||
short data = jsonData != null ? jsonData.getAsShort() : 0;
|
||||
@ -104,9 +109,36 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
}
|
||||
}
|
||||
|
||||
protected LegacyBlockItemRewriter(T protocol) {
|
||||
super(protocol, Type.ITEM1_8, Type.ITEM1_8_SHORT_ARRAY, false);
|
||||
replacementData = LEGACY_MAPPINGS.get(protocol.getClass().getSimpleName().split("To")[1].replace("_", "."));
|
||||
public void registerBlockChange(C packetType) {
|
||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.POSITION1_8); // 0 - Block Position
|
||||
map(Type.VAR_INT); // 1 - Block
|
||||
|
||||
handler(wrapper -> {
|
||||
int idx = wrapper.get(Type.VAR_INT, 0);
|
||||
wrapper.set(Type.VAR_INT, 0, handleBlockID(idx));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void registerMultiBlockChange(C packetType) {
|
||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.INT); // 0 - Chunk X
|
||||
map(Type.INT); // 1 - Chunk Z
|
||||
map(Type.BLOCK_CHANGE_RECORD_ARRAY);
|
||||
|
||||
handler(wrapper -> {
|
||||
for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) {
|
||||
record.setBlockId(handleBlockID(record.getBlockId()));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -141,7 +173,7 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
if (nameTag == null) {
|
||||
nameTag = new StringTag(data.getName());
|
||||
display.put("Name", nameTag);
|
||||
display.put(nbtTagName + "|customName", new ByteTag());
|
||||
display.put(getNbtTagName() + "|customName", new ByteTag());
|
||||
}
|
||||
|
||||
// Handle colors
|
||||
@ -163,6 +195,20 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
return (b.getId() << 4 | (b.getData() & 15));
|
||||
}
|
||||
|
||||
public PacketHandler getFallingBlockHandler() {
|
||||
return wrapper -> {
|
||||
final Optional<EntityTypes1_12.ObjectType> type = EntityTypes1_12.ObjectType.findById(wrapper.get(Type.BYTE, 0));
|
||||
if (type.isPresent() && type.get() == EntityTypes1_12.ObjectType.FALLING_BLOCK) {
|
||||
final int objectData = wrapper.get(Type.INT, 0);
|
||||
|
||||
final Block block = handleBlock(objectData & 4095, objectData >> 12 & 15);
|
||||
if (block == null) return;
|
||||
|
||||
wrapper.set(Type.INT, 0, block.getId() | block.getData() << 12);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public @Nullable Block handleBlock(int blockId, int data) {
|
||||
MappedLegacyBlockItem settings = getMappedBlockItem(blockId, data);
|
||||
if (settings == null || !settings.isBlock()) return null;
|
||||
|
@ -49,11 +49,14 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
|
||||
private LegacyEnchantmentRewriter enchantmentRewriter;
|
||||
|
||||
public BlockItemPackets1_11(Protocol1_10To1_11 protocol) {
|
||||
super(protocol);
|
||||
super(protocol, "1.11");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
registerBlockChange(ClientboundPackets1_9_3.BLOCK_CHANGE);
|
||||
registerMultiBlockChange(ClientboundPackets1_9_3.MULTI_BLOCK_CHANGE);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.SET_SLOT, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
@ -187,34 +190,6 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.BLOCK_CHANGE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.POSITION1_8); // 0 - Block Position
|
||||
map(Type.VAR_INT); // 1 - Block
|
||||
|
||||
handler(wrapper -> {
|
||||
int idx = wrapper.get(Type.VAR_INT, 0);
|
||||
wrapper.set(Type.VAR_INT, 0, handleBlockID(idx));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.MULTI_BLOCK_CHANGE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.INT); // 0 - Chunk X
|
||||
map(Type.INT); // 1 - Chunk Z
|
||||
map(Type.BLOCK_CHANGE_RECORD_ARRAY);
|
||||
|
||||
handler(wrapper -> {
|
||||
for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) {
|
||||
record.setBlockId(handleBlockID(record.getBlockId()));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.BLOCK_ENTITY_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
@ -305,7 +280,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
|
||||
return tag;
|
||||
});
|
||||
|
||||
enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName);
|
||||
enchantmentRewriter = new LegacyEnchantmentRewriter(getNbtTagName());
|
||||
enchantmentRewriter.registerEnchantment(71, "§cCurse of Vanishing");
|
||||
enchantmentRewriter.registerEnchantment(10, "§cCurse of Binding");
|
||||
|
||||
@ -343,10 +318,10 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
|
||||
// Rewrite spawn eggs (id checks are done in the method itself)
|
||||
EntityIdRewriter.toServerItem(item, true);
|
||||
|
||||
if (tag.getListTag(nbtTagName + "|ench") != null) {
|
||||
if (tag.getListTag(getNbtTagName() + "|ench") != null) {
|
||||
enchantmentRewriter.rewriteEnchantmentsToServer(tag, false);
|
||||
}
|
||||
if (tag.getListTag(nbtTagName + "|StoredEnchantments") != null) {
|
||||
if (tag.getListTag(getNbtTagName() + "|StoredEnchantments") != null) {
|
||||
enchantmentRewriter.rewriteEnchantmentsToServer(tag, true);
|
||||
}
|
||||
return item;
|
||||
|
@ -24,11 +24,9 @@ import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.PotionSplashHandler;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage;
|
||||
import com.viaversion.viabackwards.utils.Block;
|
||||
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
@ -36,7 +34,6 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_9;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_9_3, Protocol1_10To1_11> {
|
||||
|
||||
@ -86,21 +83,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_
|
||||
handler(getObjectTrackerHandler());
|
||||
handler(getObjectRewriter(id -> EntityTypes1_11.ObjectType.findById(id).orElse(null)));
|
||||
|
||||
// Handle FallingBlock blocks
|
||||
handler(wrapper -> {
|
||||
Optional<EntityTypes1_12.ObjectType> type = EntityTypes1_12.ObjectType.findById(wrapper.get(Type.BYTE, 0));
|
||||
if (type.isPresent() && type.get() == EntityTypes1_12.ObjectType.FALLING_BLOCK) {
|
||||
int objectData = wrapper.get(Type.INT, 0);
|
||||
int objType = objectData & 4095;
|
||||
int data = objectData >> 12 & 15;
|
||||
|
||||
Block block = protocol.getItemRewriter().handleBlock(objType, data);
|
||||
if (block == null)
|
||||
return;
|
||||
|
||||
wrapper.set(Type.INT, 0, block.getId() | block.getData() << 12);
|
||||
}
|
||||
});
|
||||
handler(protocol.getItemRewriter().getFallingBlockHandler());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -43,11 +43,14 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPackets1_12, ServerboundPackets1_9_3, Protocol1_11_1To1_12> {
|
||||
|
||||
public BlockItemPackets1_12(Protocol1_11_1To1_12 protocol) {
|
||||
super(protocol);
|
||||
super(protocol, "1.12");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
registerBlockChange(ClientboundPackets1_12.BLOCK_CHANGE);
|
||||
registerMultiBlockChange(ClientboundPackets1_12.MULTI_BLOCK_CHANGE);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_12.MAP_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
@ -159,34 +162,6 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPac
|
||||
handleChunk(chunk);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_12.BLOCK_CHANGE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.POSITION1_8); // 0 - Block Position
|
||||
map(Type.VAR_INT); // 1 - Block
|
||||
|
||||
handler(wrapper -> {
|
||||
int idx = wrapper.get(Type.VAR_INT, 0);
|
||||
wrapper.set(Type.VAR_INT, 0, handleBlockID(idx));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_12.MULTI_BLOCK_CHANGE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.INT); // 0 - Chunk X
|
||||
map(Type.INT); // 1 - Chunk Z
|
||||
map(Type.BLOCK_CHANGE_RECORD_ARRAY);
|
||||
|
||||
handler(wrapper -> {
|
||||
for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) {
|
||||
record.setBlockId(handleBlockID(record.getBlockId()));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_12.BLOCK_ENTITY_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
|
@ -22,7 +22,6 @@ import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ParrotStorage;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker;
|
||||
import com.viaversion.viabackwards.utils.Block;
|
||||
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12;
|
||||
@ -36,7 +35,6 @@ import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
import java.util.Optional;
|
||||
|
||||
public class EntityPackets1_12 extends LegacyEntityRewriter<ClientboundPackets1_12, Protocol1_11_1To1_12> {
|
||||
|
||||
@ -63,22 +61,7 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<ClientboundPackets1_
|
||||
handler(getObjectTrackerHandler());
|
||||
handler(getObjectRewriter(id -> EntityTypes1_12.ObjectType.findById(id).orElse(null)));
|
||||
|
||||
// Handle FallingBlock blocks
|
||||
handler(wrapper -> {
|
||||
Optional<EntityTypes1_12.ObjectType> type = EntityTypes1_12.ObjectType.findById(wrapper.get(Type.BYTE, 0));
|
||||
if (type.isPresent() && type.get() == EntityTypes1_12.ObjectType.FALLING_BLOCK) {
|
||||
int objectData = wrapper.get(Type.INT, 0);
|
||||
int objType = objectData & 4095;
|
||||
int data = objectData >> 12 & 15;
|
||||
|
||||
Block block = protocol.getItemRewriter().handleBlock(objType, data);
|
||||
if (block == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
wrapper.set(Type.INT, 0, block.getId() | block.getData() << 12);
|
||||
}
|
||||
});
|
||||
handler(protocol.getItemRewriter().getFallingBlockHandler());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
|
||||
private LegacyEnchantmentRewriter enchantmentRewriter;
|
||||
|
||||
public ItemPackets1_11_1(Protocol1_11To1_11_1 protocol) {
|
||||
super(protocol);
|
||||
super(protocol, "1.11.1");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -84,7 +84,7 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName);
|
||||
enchantmentRewriter = new LegacyEnchantmentRewriter(getNbtTagName());
|
||||
enchantmentRewriter.registerEnchantment(22, "§7Sweeping Edge");
|
||||
}
|
||||
|
||||
@ -113,10 +113,10 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
|
||||
CompoundTag tag = item.tag();
|
||||
if (tag == null) return item;
|
||||
|
||||
if (tag.getListTag(nbtTagName + "|ench") != null) {
|
||||
if (tag.getListTag(getNbtTagName() + "|ench") != null) {
|
||||
enchantmentRewriter.rewriteEnchantmentsToServer(tag, false);
|
||||
}
|
||||
if (tag.getListTag(nbtTagName + "|StoredEnchantments") != null) {
|
||||
if (tag.getListTag(getNbtTagName() + "|StoredEnchantments") != null) {
|
||||
enchantmentRewriter.rewriteEnchantmentsToServer(tag, true);
|
||||
}
|
||||
return item;
|
||||
|
@ -71,7 +71,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
public BlockItemPackets1_13(Protocol1_12_2To1_13 protocol) {
|
||||
super(protocol, null, null);
|
||||
extraNbtTag = "VB|" + protocol.getClass().getSimpleName() + "|2";
|
||||
extraNbtTag = getNbtTagName() + "|2";
|
||||
}
|
||||
|
||||
public static boolean isDamageable(int id) {
|
||||
|
@ -166,7 +166,7 @@ public final class BlockItemPackets1_20 extends ItemRewriter<ClientboundPackets1
|
||||
final String pattern = Key.stripMinecraftNamespace(patternTag.getValue());
|
||||
if (NEW_TRIM_PATTERNS.contains(pattern)) {
|
||||
tag.remove("Trim");
|
||||
tag.put(nbtTagName + "|Trim", trimTag);
|
||||
tag.put(getNbtTagName() + "|Trim", trimTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -184,7 +184,7 @@ public final class BlockItemPackets1_20 extends ItemRewriter<ClientboundPackets1
|
||||
// Add back original trim tag
|
||||
final Tag trimTag;
|
||||
final CompoundTag tag = item.tag();
|
||||
if (tag != null && (trimTag = tag.remove(nbtTagName + "|Trim")) != null) {
|
||||
if (tag != null && (trimTag = tag.remove(getNbtTagName() + "|Trim")) != null) {
|
||||
tag.put("Trim", trimTag);
|
||||
}
|
||||
return item;
|
||||
|
@ -33,11 +33,14 @@ import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPac
|
||||
public class BlockItemPackets1_10 extends LegacyBlockItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_9_3, Protocol1_9_4To1_10> {
|
||||
|
||||
public BlockItemPackets1_10(Protocol1_9_4To1_10 protocol) {
|
||||
super(protocol);
|
||||
super(protocol, "1.10");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
registerBlockChange(ClientboundPackets1_9_3.BLOCK_CHANGE);
|
||||
registerMultiBlockChange(ClientboundPackets1_9_3.MULTI_BLOCK_CHANGE);
|
||||
|
||||
registerSetSlot(ClientboundPackets1_9_3.SET_SLOT);
|
||||
registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS);
|
||||
|
||||
@ -83,36 +86,6 @@ public class BlockItemPackets1_10 extends LegacyBlockItemRewriter<ClientboundPac
|
||||
handleChunk(chunk);
|
||||
});
|
||||
|
||||
// Block Change Packet
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.BLOCK_CHANGE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.POSITION1_8); // 0 - Block Position
|
||||
map(Type.VAR_INT); // 1 - Block
|
||||
|
||||
handler(wrapper -> {
|
||||
int idx = wrapper.get(Type.VAR_INT, 0);
|
||||
wrapper.set(Type.VAR_INT, 0, handleBlockID(idx));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Multi Block Change Packet
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.MULTI_BLOCK_CHANGE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.INT); // 0 - Chunk X
|
||||
map(Type.INT); // 1 - Chunk Z
|
||||
map(Type.BLOCK_CHANGE_RECORD_ARRAY);
|
||||
|
||||
handler(wrapper -> {
|
||||
for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) {
|
||||
record.setBlockId(handleBlockID(record.getBlockId()));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Rewrite metadata items
|
||||
protocol.getEntityRewriter().filter().handler((event, meta) -> {
|
||||
if (meta.metaType().type().equals(Type.ITEM1_8)) // Is Item
|
||||
|
@ -22,11 +22,9 @@ import com.viaversion.viabackwards.api.entities.storage.EntityData;
|
||||
import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10;
|
||||
import com.viaversion.viabackwards.utils.Block;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
@ -34,7 +32,6 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_9;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class EntityPackets1_10 extends LegacyEntityRewriter<ClientboundPackets1_9_3, Protocol1_9_4To1_10> {
|
||||
|
||||
@ -61,21 +58,7 @@ public class EntityPackets1_10 extends LegacyEntityRewriter<ClientboundPackets1_
|
||||
handler(getObjectTrackerHandler());
|
||||
handler(getObjectRewriter(id -> EntityTypes1_11.ObjectType.findById(id).orElse(null)));
|
||||
|
||||
// Handle FallingBlock blocks
|
||||
handler(wrapper -> {
|
||||
Optional<EntityTypes1_12.ObjectType> type = EntityTypes1_12.ObjectType.findById(wrapper.get(Type.BYTE, 0));
|
||||
if (type.isPresent() && type.get() == EntityTypes1_12.ObjectType.FALLING_BLOCK) {
|
||||
int objectData = wrapper.get(Type.INT, 0);
|
||||
int objType = objectData & 4095;
|
||||
int data = objectData >> 12 & 15;
|
||||
|
||||
Block block = protocol.getItemRewriter().handleBlock(objType, data);
|
||||
if (block == null)
|
||||
return;
|
||||
|
||||
wrapper.set(Type.INT, 0, block.getId() | block.getData() << 12);
|
||||
}
|
||||
});
|
||||
handler(protocol.getItemRewriter().getFallingBlockHandler());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -0,0 +1,33 @@
|
||||
{
|
||||
"255": {
|
||||
"id": 217,
|
||||
"name": "1.10 Structure Block"
|
||||
},
|
||||
"217": {
|
||||
"id": 287,
|
||||
"name": "1.10 Structure Void",
|
||||
"block": true
|
||||
},
|
||||
"213": {
|
||||
"id": 159,
|
||||
"data": 1,
|
||||
"name": "1.10 Magma Block",
|
||||
"block": true
|
||||
},
|
||||
"214": {
|
||||
"id": 159,
|
||||
"data": 14,
|
||||
"name": "1.10 Nether Wart Block",
|
||||
"block": true
|
||||
},
|
||||
"215": {
|
||||
"id": 112,
|
||||
"name": "1.10 Red Nether Bricks",
|
||||
"block": true
|
||||
},
|
||||
"216": {
|
||||
"id": 155,
|
||||
"name": "1.10 Bone Block",
|
||||
"block": true
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"452": {
|
||||
"id": 265,
|
||||
"name": "1.11.1 Iron Nugget"
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
{
|
||||
"218": {
|
||||
"id": 23,
|
||||
"data": -1,
|
||||
"name": "1.11 Observer",
|
||||
"block": true
|
||||
},
|
||||
"449": {
|
||||
"id": 418,
|
||||
"name": "1.11 Totem of Undying"
|
||||
},
|
||||
"450": {
|
||||
"id": 433,
|
||||
"name": "1.11 Shulker Shell"
|
||||
},
|
||||
"219-234": {
|
||||
"id": 158,
|
||||
"name": "1.11 %color% Shulker Box",
|
||||
"block": true
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
{
|
||||
"251": {
|
||||
"id": 159,
|
||||
"data": -1,
|
||||
"name": "1.12 %vb_color% Concrete",
|
||||
"block": true
|
||||
},
|
||||
"252": {
|
||||
"id": 35,
|
||||
"data": -1,
|
||||
"name": "1.12 %vb_color% Concrete Powder",
|
||||
"block": true
|
||||
},
|
||||
"453": {
|
||||
"id": 340,
|
||||
"name": "1.12 Knowledge Book"
|
||||
},
|
||||
"355": {
|
||||
"id": 355,
|
||||
"name": "1.12 %vb_color% Bed"
|
||||
},
|
||||
"235-250": {
|
||||
"id": 159,
|
||||
"name": "1.12 %color% Glazed Terracotta",
|
||||
"block": true
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
{
|
||||
"1.12": {
|
||||
"251": {
|
||||
"id": 159,
|
||||
"data": -1,
|
||||
"name": "1.12 %vb_color% Concrete",
|
||||
"block": true
|
||||
},
|
||||
"252": {
|
||||
"id": 35,
|
||||
"data": -1,
|
||||
"name": "1.12 %vb_color% Concrete Powder",
|
||||
"block": true
|
||||
},
|
||||
"453": {
|
||||
"id": 340,
|
||||
"name": "1.12 Knowledge Book"
|
||||
},
|
||||
"355": {
|
||||
"id": 355,
|
||||
"name": "1.12 %vb_color% Bed"
|
||||
},
|
||||
"235-250": {
|
||||
"id": 159,
|
||||
"name": "1.12 %color% Glazed Terracotta",
|
||||
"block": true
|
||||
}
|
||||
},
|
||||
"1.11.1": {
|
||||
"452": {
|
||||
"id": 265,
|
||||
"name": "1.11.1 Iron Nugget"
|
||||
}
|
||||
},
|
||||
"1.11": {
|
||||
"218": {
|
||||
"id": 23,
|
||||
"data": -1,
|
||||
"name": "1.11 Observer",
|
||||
"block": true
|
||||
},
|
||||
"449": {
|
||||
"id": 418,
|
||||
"name": "1.11 Totem of Undying"
|
||||
},
|
||||
"450": {
|
||||
"id": 433,
|
||||
"name": "1.11 Shulker Shell"
|
||||
},
|
||||
"219-234": {
|
||||
"id": 158,
|
||||
"name": "1.11 %color% Shulker Box",
|
||||
"block": true
|
||||
}
|
||||
},
|
||||
"1.10": {
|
||||
"255": {
|
||||
"id": 217,
|
||||
"name": "1.10 Structure Block"
|
||||
},
|
||||
"217": {
|
||||
"id": 287,
|
||||
"name": "1.10 Structure Void",
|
||||
"block": true
|
||||
},
|
||||
"213": {
|
||||
"id": 159,
|
||||
"data": 1,
|
||||
"name": "1.10 Magma Block",
|
||||
"block": true
|
||||
},
|
||||
"214": {
|
||||
"id": 159,
|
||||
"data": 14,
|
||||
"name": "1.10 Nether Wart Block",
|
||||
"block": true
|
||||
},
|
||||
"215": {
|
||||
"id": 112,
|
||||
"name": "1.10 Red Nether Bricks",
|
||||
"block": true
|
||||
},
|
||||
"216": {
|
||||
"id": 155,
|
||||
"name": "1.10 Bone Block",
|
||||
"block": true
|
||||
}
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren