Compare commits
24
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
132cf1d6e1 | ||
|
|
5f57041413 | ||
|
|
f91a25cba7 | ||
|
|
547041cb62 | ||
|
|
b7af3b7d8e | ||
|
|
bb927b31f7 | ||
|
|
eceda8ac58 | ||
|
|
65d829065a | ||
|
|
0b38dc18a5 | ||
|
|
4b58f6d154 | ||
|
|
6d8fee053d | ||
|
|
335415efd7 | ||
|
|
59f7ce339e | ||
|
|
a9b9c48b26 | ||
|
|
8fb814ef11 | ||
|
|
9873f279a4 | ||
|
|
ab1467dba5 | ||
|
|
3749a5d5da | ||
|
|
6f8da18f65 | ||
|
|
1a24ce6d87 | ||
|
|
e9d142e2ec | ||
|
|
218b2abe45 | ||
|
|
263790e9f6 | ||
|
|
094bfe34c6 |
No files matched your search
@@ -65,7 +65,8 @@ public abstract class BackwardsProtocol<CU extends ClientboundPacketType, CM ext
|
||||
return null;
|
||||
}
|
||||
|
||||
public @Nullable TranslatableRewriter<CU> getTranslatableRewriter() {
|
||||
@Override
|
||||
public @Nullable TranslatableRewriter<CU> getComponentRewriter() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,7 @@ import com.viaversion.viabackwards.protocol.v1_19_1to1_19.Protocol1_19_1To1_19;
|
||||
import com.viaversion.viabackwards.protocol.v1_20_3to1_20_2.Protocol1_20_3To1_20_2;
|
||||
import com.viaversion.viabackwards.protocol.v1_20_5to1_20_3.Protocol1_20_5To1_20_3;
|
||||
import com.viaversion.viabackwards.protocol.v1_20_2to1_20.Protocol1_20_2To1_20;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.Protocol1_21To1_20_5;
|
||||
import com.viaversion.viabackwards.protocol.v1_9_3to1_9_1.Protocol1_9_3To1_9_1;
|
||||
import com.viaversion.viabackwards.protocol.v1_10to1_9_3.Protocol1_10To1_9_3;
|
||||
import com.viaversion.viabackwards.protocol.v1_9_1to1_9.Protocol1_9_1To1_9;
|
||||
@@ -138,6 +139,8 @@ public interface ViaBackwardsPlatform {
|
||||
protocolManager.registerProtocol(new Protocol1_20_2To1_20(), ProtocolVersion.v1_20, ProtocolVersion.v1_20_2);
|
||||
protocolManager.registerProtocol(new Protocol1_20_3To1_20_2(), ProtocolVersion.v1_20_2, ProtocolVersion.v1_20_3);
|
||||
protocolManager.registerProtocol(new Protocol1_20_5To1_20_3(), ProtocolVersion.v1_20_3, ProtocolVersion.v1_20_5);
|
||||
|
||||
protocolManager.registerProtocol(new Protocol1_21To1_20_5(), ProtocolVersion.v1_20_5, ProtocolVersion.v1_21);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,7 +55,7 @@ public class BackwardsMappingData extends MappingDataBase {
|
||||
|
||||
public BackwardsMappingData(final String unmappedVersion, final String mappedVersion, @Nullable final Class<? extends Protocol<?, ?, ?, ?>> vvProtocolClass) {
|
||||
super(unmappedVersion, mappedVersion);
|
||||
Preconditions.checkArgument(vvProtocolClass == null || !vvProtocolClass.isAssignableFrom(BackwardsProtocol.class));
|
||||
Preconditions.checkArgument(vvProtocolClass == null || !BackwardsProtocol.class.isAssignableFrom(vvProtocolClass));
|
||||
this.vvProtocolClass = vvProtocolClass;
|
||||
}
|
||||
|
||||
@@ -151,6 +151,11 @@ public class BackwardsMappingData extends MappingDataBase {
|
||||
return checkValidity(id, this.itemMappings.inverse().getNewId(id), "item");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNewAttributeId(final int id) {
|
||||
return this.attributeMappings.getNewId(id);
|
||||
}
|
||||
|
||||
public @Nullable MappedItem getMappedItem(final int id) {
|
||||
return backwardsItemMappings != null ? backwardsItemMappings.get(id) : null;
|
||||
}
|
||||
|
||||
+10
-101
@@ -17,16 +17,6 @@
|
||||
*/
|
||||
package com.viaversion.viabackwards.api.rewriters;
|
||||
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.data.MappedItem;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
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.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.nbt.tag.ByteTag;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.IntTag;
|
||||
@@ -34,6 +24,13 @@ import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.nbt.tag.NumberTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.data.MappedItem;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class BackwardsItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
|
||||
@@ -54,11 +51,11 @@ public class BackwardsItemRewriter<C extends ClientboundPacketType, S extends Se
|
||||
}
|
||||
|
||||
CompoundTag display = item.tag() != null ? item.tag().getCompoundTag("display") : null;
|
||||
if (protocol.getTranslatableRewriter() != null && display != null) {
|
||||
if (protocol.getComponentRewriter() != null && display != null) {
|
||||
// Handle name and lore components
|
||||
StringTag name = display.getStringTag("Name");
|
||||
if (name != null) {
|
||||
String newValue = protocol.getTranslatableRewriter().processText(connection, name.getValue()).toString();
|
||||
String newValue = protocol.getComponentRewriter().processText(connection, name.getValue()).toString();
|
||||
if (!newValue.equals(name.getValue())) {
|
||||
saveStringTag(display, name, "Name");
|
||||
}
|
||||
@@ -70,7 +67,7 @@ public class BackwardsItemRewriter<C extends ClientboundPacketType, S extends Se
|
||||
if (lore != null) {
|
||||
boolean changed = false;
|
||||
for (StringTag loreEntry : lore) {
|
||||
String newValue = protocol.getTranslatableRewriter().processText(connection, loreEntry.getValue()).toString();
|
||||
String newValue = protocol.getComponentRewriter().processText(connection, loreEntry.getValue()).toString();
|
||||
if (!changed && !newValue.equals(loreEntry.getValue())) {
|
||||
// Backup original lore before doing any modifications
|
||||
changed = true;
|
||||
@@ -125,92 +122,4 @@ public class BackwardsItemRewriter<C extends ClientboundPacketType, S extends Se
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerAdvancements(C packetType) {
|
||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
wrapper.passthrough(Types.BOOLEAN); // Reset/clear
|
||||
final int size = wrapper.passthrough(Types.VAR_INT); // Mapping size
|
||||
for (int i = 0; i < size; i++) {
|
||||
wrapper.passthrough(Types.STRING); // Identifier
|
||||
wrapper.passthrough(Types.OPTIONAL_STRING); // Parent
|
||||
|
||||
// Display data
|
||||
if (wrapper.passthrough(Types.BOOLEAN)) {
|
||||
final JsonElement title = wrapper.passthrough(Types.COMPONENT);
|
||||
final JsonElement description = wrapper.passthrough(Types.COMPONENT);
|
||||
final TranslatableRewriter<C> translatableRewriter = protocol.getTranslatableRewriter();
|
||||
if (translatableRewriter != null) {
|
||||
translatableRewriter.processText(wrapper.user(), title);
|
||||
translatableRewriter.processText(wrapper.user(), description);
|
||||
}
|
||||
|
||||
final Item icon = handleItemToClient(wrapper.user(), wrapper.read(itemType()));
|
||||
wrapper.write(mappedItemType(), icon);
|
||||
|
||||
wrapper.passthrough(Types.VAR_INT); // Frame type
|
||||
int flags = wrapper.passthrough(Types.INT); // Flags
|
||||
if ((flags & 1) != 0) {
|
||||
wrapper.passthrough(Types.STRING); // Background texture
|
||||
}
|
||||
wrapper.passthrough(Types.FLOAT); // X
|
||||
wrapper.passthrough(Types.FLOAT); // Y
|
||||
}
|
||||
|
||||
wrapper.passthrough(Types.STRING_ARRAY); // Criteria
|
||||
|
||||
final int arrayLength = wrapper.passthrough(Types.VAR_INT);
|
||||
for (int array = 0; array < arrayLength; array++) {
|
||||
wrapper.passthrough(Types.STRING_ARRAY); // String array
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerAdvancements1_20_3(final C packetType) {
|
||||
// Insert translatable rewriter
|
||||
protocol.registerClientbound(packetType, wrapper -> {
|
||||
wrapper.passthrough(Types.BOOLEAN); // Reset/clear
|
||||
final int size = wrapper.passthrough(Types.VAR_INT); // Mapping size
|
||||
for (int i = 0; i < size; i++) {
|
||||
wrapper.passthrough(Types.STRING); // Identifier
|
||||
wrapper.passthrough(Types.OPTIONAL_STRING); // Parent
|
||||
|
||||
// Display data
|
||||
if (wrapper.passthrough(Types.BOOLEAN)) {
|
||||
final Tag title = wrapper.passthrough(Types.TAG);
|
||||
final Tag description = wrapper.passthrough(Types.TAG);
|
||||
final TranslatableRewriter<C> translatableRewriter = protocol.getTranslatableRewriter();
|
||||
if (translatableRewriter != null) {
|
||||
translatableRewriter.processTag(wrapper.user(), title);
|
||||
translatableRewriter.processTag(wrapper.user(), description);
|
||||
}
|
||||
|
||||
final Item icon = handleItemToClient(wrapper.user(), wrapper.read(itemType()));
|
||||
wrapper.write(mappedItemType(), icon);
|
||||
|
||||
wrapper.passthrough(Types.VAR_INT); // Frame type
|
||||
final int flags = wrapper.passthrough(Types.INT);
|
||||
if ((flags & 1) != 0) {
|
||||
wrapper.passthrough(Types.STRING); // Background texture
|
||||
}
|
||||
wrapper.passthrough(Types.FLOAT); // X
|
||||
wrapper.passthrough(Types.FLOAT); // Y
|
||||
}
|
||||
|
||||
final int requirements = wrapper.passthrough(Types.VAR_INT);
|
||||
for (int array = 0; array < requirements; array++) {
|
||||
wrapper.passthrough(Types.STRING_ARRAY);
|
||||
}
|
||||
|
||||
wrapper.passthrough(Types.BOOLEAN); // Send telemetry
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
-34
@@ -75,29 +75,6 @@ public abstract class BackwardsItemRewriterBase<C extends ClientboundPacketType,
|
||||
}
|
||||
}
|
||||
|
||||
protected void saveGenericTagList(CompoundTag tag, List<Tag> original, String name) {
|
||||
// List tags cannot contain tags of different types, so we have to store them a bit more awkwardly as an indexed compound tag
|
||||
String backupName = nbtTagName(name);
|
||||
if (!tag.contains(backupName)) {
|
||||
CompoundTag output = new CompoundTag();
|
||||
for (int i = 0; i < original.size(); i++) {
|
||||
output.put(Integer.toString(i), original.get(i));
|
||||
}
|
||||
tag.put(backupName, output);
|
||||
}
|
||||
}
|
||||
|
||||
protected List<Tag> removeGenericTagList(CompoundTag tag, String name) {
|
||||
String backupName = nbtTagName(name);
|
||||
CompoundTag data = tag.getCompoundTag(backupName);
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
tag.remove(backupName);
|
||||
return new ArrayList<>(data.values());
|
||||
}
|
||||
|
||||
protected void restoreDisplayTag(Item item) {
|
||||
if (item.tag() == null) return;
|
||||
|
||||
@@ -129,17 +106,6 @@ public abstract class BackwardsItemRewriterBase<C extends ClientboundPacketType,
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends Tag> @Nullable ListTag<T> removeListTag(CompoundTag tag, String tagName, Class<T> tagType) {
|
||||
String backupName = nbtTagName(tagName);
|
||||
ListTag<T> data = tag.getListTag(backupName, tagType);
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
tag.remove(backupName);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nbtTagName() {
|
||||
return "VB|" + protocol.getClass().getSimpleName();
|
||||
|
||||
+93
-62
@@ -19,12 +19,14 @@ package com.viaversion.viabackwards.api.rewriters;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.IntTag;
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.nbt.tag.NumberTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
|
||||
import com.viaversion.viabackwards.api.data.MappedItem;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.FullMappings;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
||||
@@ -32,12 +34,14 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntFunction;
|
||||
import com.viaversion.viaversion.rewriter.StructuredItemRewriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
|
||||
T extends BackwardsProtocol<C, ?, ?, S>> extends BackwardsItemRewriter<C, S, T> {
|
||||
|
||||
protected final StructuredEnchantmentRewriter enchantmentRewriter = new StructuredEnchantmentRewriter(this);
|
||||
T extends BackwardsProtocol<C, ?, ?, S>> extends StructuredItemRewriter<C, S, T> {
|
||||
|
||||
public BackwardsStructuredItemRewriter(final T protocol, final Type<Item> itemType, final Type<Item[]> itemArrayType) {
|
||||
super(protocol, itemType, itemArrayType);
|
||||
@@ -53,39 +57,48 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
return item;
|
||||
}
|
||||
|
||||
final StructuredDataContainer data = item.dataContainer();
|
||||
data.setIdLookup(protocol, true);
|
||||
|
||||
if (protocol.getMappingData().getEnchantmentMappings() != null) {
|
||||
enchantmentRewriter.handleToClient(item);
|
||||
final StructuredDataContainer dataContainer = item.dataContainer();
|
||||
final BackwardsMappingData mappingData = protocol.getMappingData();
|
||||
if (mappingData != null && mappingData.getDataComponentSerializerMappings() != null) {
|
||||
final FullMappings mappings = mappingData.getDataComponentSerializerMappings();
|
||||
dataContainer.setIdLookup(protocol, true);
|
||||
dataContainer.updateIds(protocol, mappings::getNewId);
|
||||
}
|
||||
|
||||
if (protocol.getTranslatableRewriter() != null) {
|
||||
if (protocol.getComponentRewriter() != null) {
|
||||
// Handle name and lore components
|
||||
final StructuredData<Tag> customNameData = data.getNonEmpty(StructuredDataKey.CUSTOM_NAME);
|
||||
final StructuredData<Tag> customNameData = dataContainer.getNonEmpty(StructuredDataKey.CUSTOM_NAME);
|
||||
if (customNameData != null) {
|
||||
final Tag originalName = customNameData.value().copy();
|
||||
protocol.getTranslatableRewriter().processTag(connection, customNameData.value());
|
||||
protocol.getComponentRewriter().processTag(connection, customNameData.value());
|
||||
if (!customNameData.value().equals(originalName)) {
|
||||
saveTag(createCustomTag(item), originalName, "Name");
|
||||
}
|
||||
}
|
||||
|
||||
final StructuredData<Tag[]> loreData = data.getNonEmpty(StructuredDataKey.LORE);
|
||||
final StructuredData<Tag[]> loreData = dataContainer.getNonEmpty(StructuredDataKey.LORE);
|
||||
if (loreData != null) {
|
||||
for (final Tag tag : loreData.value()) {
|
||||
protocol.getTranslatableRewriter().processTag(connection, tag);
|
||||
protocol.getComponentRewriter().processTag(connection, tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final BackwardsMappingData mappingData = protocol.getMappingData();
|
||||
Int2IntFunction itemIdRewriter = null;
|
||||
Int2IntFunction blockIdRewriter = null;
|
||||
if (mappingData != null) {
|
||||
itemIdRewriter = mappingData.getItemMappings() != null ? mappingData::getNewItemId : null;
|
||||
blockIdRewriter = mappingData.getBlockMappings() != null ? mappingData::getNewBlockId : null;
|
||||
}
|
||||
|
||||
final MappedItem mappedItem = mappingData != null ? mappingData.getMappedItem(item.identifier()) : null;
|
||||
if (mappedItem == null) {
|
||||
// Just rewrite the id
|
||||
if (mappingData != null && mappingData.getItemMappings() != null) {
|
||||
item.setIdentifier(mappingData.getNewItemId(item.identifier()));
|
||||
}
|
||||
|
||||
updateItemComponents(connection, dataContainer, this::handleItemToClient, itemIdRewriter, blockIdRewriter);
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -95,15 +108,17 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
item.setIdentifier(mappedItem.id());
|
||||
|
||||
// Add custom model data
|
||||
if (mappedItem.customModelData() != null && !data.contains(StructuredDataKey.CUSTOM_MODEL_DATA)) {
|
||||
data.set(StructuredDataKey.CUSTOM_MODEL_DATA, mappedItem.customModelData());
|
||||
if (mappedItem.customModelData() != null && !dataContainer.contains(StructuredDataKey.CUSTOM_MODEL_DATA)) {
|
||||
dataContainer.set(StructuredDataKey.CUSTOM_MODEL_DATA, mappedItem.customModelData());
|
||||
}
|
||||
|
||||
// Set custom name - only done if there is no original one
|
||||
if (!data.contains(StructuredDataKey.CUSTOM_NAME)) {
|
||||
data.set(StructuredDataKey.CUSTOM_NAME, mappedItem.tagName());
|
||||
if (!dataContainer.contains(StructuredDataKey.CUSTOM_NAME)) {
|
||||
dataContainer.set(StructuredDataKey.CUSTOM_NAME, mappedItem.tagName());
|
||||
tag.putBoolean(nbtTagName("customName"), true);
|
||||
}
|
||||
|
||||
updateItemComponents(connection, dataContainer, this::handleItemToClient, itemIdRewriter, blockIdRewriter);
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -114,16 +129,19 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
}
|
||||
|
||||
final BackwardsMappingData mappingData = protocol.getMappingData();
|
||||
if (mappingData != null && mappingData.getItemMappings() != null) {
|
||||
item.setIdentifier(mappingData.getOldItemId(item.identifier()));
|
||||
final StructuredDataContainer dataContainer = item.dataContainer();
|
||||
if (mappingData != null) {
|
||||
if (mappingData.getItemMappings() != null) {
|
||||
item.setIdentifier(mappingData.getOldItemId(item.identifier()));
|
||||
}
|
||||
|
||||
final FullMappings dataComponentMappings = mappingData.getDataComponentSerializerMappings();
|
||||
if (dataComponentMappings != null) {
|
||||
dataContainer.setIdLookup(protocol, false);
|
||||
dataContainer.updateIds(protocol, id -> dataComponentMappings.inverse().getNewId(id));
|
||||
}
|
||||
}
|
||||
|
||||
final StructuredDataContainer data = item.dataContainer();
|
||||
data.setIdLookup(protocol, false);
|
||||
|
||||
if (protocol.getMappingData().getEnchantmentMappings() != null) {
|
||||
enchantmentRewriter.handleToServer(item);
|
||||
}
|
||||
|
||||
final CompoundTag tag = customTag(item);
|
||||
if (tag != null) {
|
||||
@@ -133,7 +151,15 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
}
|
||||
}
|
||||
|
||||
restoreDisplayTag(item);
|
||||
restoreTextComponents(item);
|
||||
|
||||
Int2IntFunction itemIdRewriter = null;
|
||||
Int2IntFunction blockIdRewriter = null;
|
||||
if (mappingData != null) {
|
||||
itemIdRewriter = mappingData.getItemMappings() != null ? mappingData::getOldItemId : null;
|
||||
blockIdRewriter = mappingData.getBlockMappings() != null ? mappingData::getOldBlockId : null;
|
||||
}
|
||||
updateItemComponents(connection, dataContainer, this::handleItemToServer, itemIdRewriter, blockIdRewriter);
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -142,45 +168,50 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
return customData != null ? customData.value() : null;
|
||||
}
|
||||
|
||||
protected CompoundTag createCustomTag(final Item item) {
|
||||
final StructuredDataContainer data = item.dataContainer();
|
||||
final StructuredData<CompoundTag> customData = data.getNonEmpty(StructuredDataKey.CUSTOM_DATA);
|
||||
if (customData != null) {
|
||||
return customData.value();
|
||||
protected void saveListTag(CompoundTag tag, ListTag<?> original, String name) {
|
||||
// Multiple places might try to backup data
|
||||
String backupName = nbtTagName(name);
|
||||
if (!tag.contains(backupName)) {
|
||||
tag.put(backupName, original.copy());
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends Tag> @Nullable ListTag<T> removeListTag(CompoundTag tag, String tagName, Class<T> tagType) {
|
||||
String backupName = nbtTagName(tagName);
|
||||
ListTag<T> data = tag.getListTag(backupName, tagType);
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final CompoundTag tag = new CompoundTag();
|
||||
data.set(StructuredDataKey.CUSTOM_DATA, tag);
|
||||
return tag;
|
||||
tag.remove(backupName);
|
||||
return data;
|
||||
}
|
||||
|
||||
protected void saveGenericTagList(CompoundTag tag, List<Tag> original, String name) {
|
||||
// List tags cannot contain tags of different types, so we have to store them a bit more awkwardly as an indexed compound tag
|
||||
String backupName = nbtTagName(name);
|
||||
if (!tag.contains(backupName)) {
|
||||
CompoundTag output = new CompoundTag();
|
||||
for (int i = 0; i < original.size(); i++) {
|
||||
output.put(Integer.toString(i), original.get(i));
|
||||
}
|
||||
tag.put(backupName, output);
|
||||
}
|
||||
}
|
||||
|
||||
protected List<Tag> removeGenericTagList(CompoundTag tag, String name) {
|
||||
String backupName = nbtTagName(name);
|
||||
CompoundTag data = tag.getCompoundTag(backupName);
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
tag.remove(backupName);
|
||||
return new ArrayList<>(data.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void restoreDisplayTag(final Item item) {
|
||||
final StructuredDataContainer data = item.dataContainer();
|
||||
final StructuredData<CompoundTag> customData = data.getNonEmpty(StructuredDataKey.CUSTOM_DATA);
|
||||
if (customData == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove custom name
|
||||
if (customData.value().remove(nbtTagName("customName")) != null) {
|
||||
data.remove(StructuredDataKey.CUSTOM_NAME);
|
||||
} else {
|
||||
final Tag name = removeBackupTag(customData.value(), "Name");
|
||||
if (name != null) {
|
||||
data.set(StructuredDataKey.CUSTOM_NAME, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void saveTag(CompoundTag customData, Tag tag, String name) {
|
||||
String backupName = nbtTagName(name);
|
||||
if (!customData.contains(backupName)) {
|
||||
customData.put(backupName, tag);
|
||||
}
|
||||
}
|
||||
|
||||
protected @Nullable Tag removeBackupTag(CompoundTag customData, String tagName) {
|
||||
return customData.remove(nbtTagName(tagName));
|
||||
public String nbtTagName() {
|
||||
return "VB|" + protocol.getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -187,7 +187,7 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
|
||||
rewriteParticle(event.user(), meta.value());
|
||||
} else if (type == optionalComponentType || type == componentType) {
|
||||
JsonElement text = meta.value();
|
||||
protocol.getTranslatableRewriter().processText(event.user(), text);
|
||||
protocol.getComponentRewriter().processText(event.user(), text);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -221,7 +221,7 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
|
||||
rewriteParticle(event.user(), particle);
|
||||
}
|
||||
} else if (type == optionalComponentType || type == componentType) {
|
||||
protocol.getTranslatableRewriter().processTag(event.user(), meta.value());
|
||||
protocol.getComponentRewriter().processTag(event.user(), meta.value());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+38
-26
@@ -17,6 +17,11 @@
|
||||
*/
|
||||
package com.viaversion.viabackwards.api.rewriters;
|
||||
|
||||
import com.viaversion.nbt.tag.ByteTag;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.nbt.tag.NumberTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
|
||||
import com.viaversion.viaversion.api.data.Mappings;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
|
||||
@@ -27,11 +32,7 @@ import com.viaversion.viaversion.api.minecraft.item.data.Enchantments;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.IntIntPair;
|
||||
import com.viaversion.viaversion.libs.fastutil.objects.ObjectIterator;
|
||||
import com.viaversion.nbt.tag.ByteTag;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.nbt.tag.NumberTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viaversion.rewriter.IdRewriteFunction;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -39,17 +40,26 @@ import java.util.List;
|
||||
|
||||
public class StructuredEnchantmentRewriter {
|
||||
|
||||
protected final BackwardsItemRewriter<?, ?, ?> itemRewriter;
|
||||
protected final BackwardsStructuredItemRewriter<?, ?, ?> itemRewriter;
|
||||
private boolean rewriteIds = true;
|
||||
|
||||
public StructuredEnchantmentRewriter(final BackwardsItemRewriter<?, ?, ?> itemRewriter) {
|
||||
public StructuredEnchantmentRewriter(final BackwardsStructuredItemRewriter<?, ?, ?> itemRewriter) {
|
||||
this.itemRewriter = itemRewriter;
|
||||
}
|
||||
|
||||
public void handleToClient(final Item item) {
|
||||
final StructuredDataContainer data = item.dataContainer();
|
||||
rewriteEnchantmentsToClient(data, StructuredDataKey.ENCHANTMENTS, false);
|
||||
rewriteEnchantmentsToClient(data, StructuredDataKey.STORED_ENCHANTMENTS, true);
|
||||
final BackwardsMappingData mappingData = itemRewriter.protocol().getMappingData();
|
||||
final IdRewriteFunction idRewriteFunction = id -> {
|
||||
final Mappings mappings = mappingData.getEnchantmentMappings();
|
||||
return mappings.getNewId(id);
|
||||
};
|
||||
final DescriptionSupplier descriptionSupplier = (id, level) -> {
|
||||
final String remappedName = mappingData.mappedEnchantmentName(id);
|
||||
return ComponentUtil.jsonStringToTag(ComponentUtil.legacyToJsonString("§7" + remappedName + " " + EnchantmentRewriter.getRomanNumber(level), true));
|
||||
};
|
||||
rewriteEnchantmentsToClient(data, StructuredDataKey.ENCHANTMENTS, idRewriteFunction, descriptionSupplier, false);
|
||||
rewriteEnchantmentsToClient(data, StructuredDataKey.STORED_ENCHANTMENTS, idRewriteFunction, descriptionSupplier, true);
|
||||
}
|
||||
|
||||
public void handleToServer(final Item item) {
|
||||
@@ -60,15 +70,11 @@ public class StructuredEnchantmentRewriter {
|
||||
}
|
||||
|
||||
final CompoundTag tag = customData.value();
|
||||
if (tag.contains(itemRewriter.nbtTagName("enchantments"))) {
|
||||
rewriteEnchantmentsToServer(data, tag, StructuredDataKey.ENCHANTMENTS, false);
|
||||
}
|
||||
if (tag.contains(itemRewriter.nbtTagName("stored_enchantments"))) {
|
||||
rewriteEnchantmentsToServer(data, tag, StructuredDataKey.STORED_ENCHANTMENTS, true);
|
||||
}
|
||||
rewriteEnchantmentsToServer(data, tag, StructuredDataKey.ENCHANTMENTS);
|
||||
rewriteEnchantmentsToServer(data, tag, StructuredDataKey.STORED_ENCHANTMENTS);
|
||||
}
|
||||
|
||||
public void rewriteEnchantmentsToClient(final StructuredDataContainer data, final StructuredDataKey<Enchantments> key, final boolean storedEnchant) {
|
||||
public void rewriteEnchantmentsToClient(final StructuredDataContainer data, final StructuredDataKey<Enchantments> key, final IdRewriteFunction rewriteFunction, final DescriptionSupplier descriptionSupplier, final boolean storedEnchant) {
|
||||
final StructuredData<Enchantments> enchantmentsData = data.getNonEmpty(key);
|
||||
if (enchantmentsData == null) {
|
||||
return;
|
||||
@@ -83,33 +89,33 @@ public class StructuredEnchantmentRewriter {
|
||||
final List<IntIntPair> updatedIds = new ArrayList<>();
|
||||
while (iterator.hasNext()) {
|
||||
final Int2IntMap.Entry entry = iterator.next();
|
||||
final BackwardsMappingData mappingData = itemRewriter.protocol().getMappingData();
|
||||
final Mappings mappings = mappingData.getEnchantmentMappings();
|
||||
final int mappedId = mappings.getNewId(entry.getIntKey());
|
||||
final int id = entry.getIntKey();
|
||||
final int mappedId = rewriteFunction.rewrite(id);
|
||||
if (mappedId != -1) {
|
||||
if (rewriteIds) {
|
||||
// Update the map after to iteration to preserve the current ids before possibly saving the original, avoid CME
|
||||
updatedIds.add(IntIntPair.of(entry.getIntKey(), mappedId));
|
||||
updatedIds.add(IntIntPair.of(id, mappedId));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
final String remappedName = mappingData.mappedEnchantmentName(entry.getIntKey());
|
||||
if (remappedName != null) {
|
||||
final int level = entry.getIntValue();
|
||||
final Tag description = descriptionSupplier.get(id, level);
|
||||
if (description != null) {
|
||||
if (!changed) {
|
||||
// Backup original before doing modifications
|
||||
itemRewriter.saveListTag(tag, asTag(enchantments), key.identifier());
|
||||
changed = true;
|
||||
}
|
||||
|
||||
final int level = entry.getIntValue();
|
||||
loreToAdd.add(ComponentUtil.jsonStringToTag(ComponentUtil.legacyToJsonString("§7" + remappedName + " " + EnchantmentRewriter.getRomanNumber(level), true)));
|
||||
loreToAdd.add(description);
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for (final IntIntPair pair : updatedIds) {
|
||||
enchantments.add(pair.firstInt(), pair.secondInt());
|
||||
final int level = enchantments.enchantments().remove(pair.firstInt());
|
||||
enchantments.add(pair.secondInt(), level);
|
||||
}
|
||||
|
||||
if (loreToAdd.isEmpty()) {
|
||||
@@ -156,7 +162,7 @@ public class StructuredEnchantmentRewriter {
|
||||
return listTag;
|
||||
}
|
||||
|
||||
public void rewriteEnchantmentsToServer(final StructuredDataContainer data, final CompoundTag tag, final StructuredDataKey<Enchantments> key, final boolean storedEnchant) {
|
||||
public void rewriteEnchantmentsToServer(final StructuredDataContainer data, final CompoundTag tag, final StructuredDataKey<Enchantments> key) {
|
||||
final ListTag<CompoundTag> enchantmentsTag = itemRewriter.removeListTag(tag, key.identifier(), CompoundTag.class);
|
||||
if (enchantmentsTag == null) {
|
||||
return;
|
||||
@@ -186,4 +192,10 @@ public class StructuredEnchantmentRewriter {
|
||||
public void setRewriteIds(final boolean rewriteIds) {
|
||||
this.rewriteIds = rewriteIds;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface DescriptionSupplier {
|
||||
|
||||
Tag get(int id, int level);
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -17,14 +17,14 @@
|
||||
*/
|
||||
package com.viaversion.viabackwards.api.rewriters;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingDataLoader;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -56,11 +56,11 @@ public class TranslatableRewriter<C extends ClientboundPacketType> extends Compo
|
||||
this(protocol, type, protocol.getClass().getSimpleName().replace("Protocol", "").split("To")[0].replace("_", "."));
|
||||
}
|
||||
|
||||
public TranslatableRewriter(final BackwardsProtocol<C, ?, ?, ?> protocol, final ReadType type, final String sectionIdentifier) {
|
||||
public TranslatableRewriter(final BackwardsProtocol<C, ?, ?, ?> protocol, final ReadType type, final String version) {
|
||||
super(protocol, type);
|
||||
final Map<String, String> translatableMappings = getTranslatableMappings(sectionIdentifier);
|
||||
final Map<String, String> translatableMappings = getTranslatableMappings(version);
|
||||
if (translatableMappings == null) {
|
||||
protocol.getLogger().warning("Missing " + sectionIdentifier + " translatables!");
|
||||
protocol.getLogger().warning("Missing " + version + " translatables!");
|
||||
this.translatables = new HashMap<>();
|
||||
} else {
|
||||
this.translatables = translatableMappings;
|
||||
|
||||
+1
-30
@@ -20,12 +20,10 @@ package com.viaversion.viabackwards.protocol.v1_10to1_9_3.rewriter;
|
||||
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyBlockItemRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_10to1_9_3.Protocol1_10To1_9_3;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
|
||||
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
|
||||
@@ -46,34 +44,7 @@ public class BlockItemPacketRewriter1_10 extends LegacyBlockItemRewriter<Clientb
|
||||
registerSetContent(ClientboundPackets1_9_3.CONTAINER_SET_CONTENT);
|
||||
|
||||
registerSetEquippedItem(ClientboundPackets1_9_3.SET_EQUIPPED_ITEM);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.CUSTOM_PAYLOAD, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // 0 - Channel
|
||||
|
||||
handler(wrapper -> {
|
||||
if (wrapper.get(Types.STRING, 0).equals("MC|TrList")) {
|
||||
wrapper.passthrough(Types.INT); // Passthrough Window ID
|
||||
|
||||
int size = wrapper.passthrough(Types.UNSIGNED_BYTE);
|
||||
for (int i = 0; i < size; i++) {
|
||||
wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Input Item
|
||||
wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Output Item
|
||||
|
||||
boolean secondItem = wrapper.passthrough(Types.BOOLEAN); // Has second item
|
||||
if (secondItem) {
|
||||
wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Second Item
|
||||
}
|
||||
|
||||
wrapper.passthrough(Types.BOOLEAN); // Trade disabled
|
||||
wrapper.passthrough(Types.INT); // Number of tools uses
|
||||
wrapper.passthrough(Types.INT); // Maximum number of trade uses
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
registerCustomPayloadTradeList(ClientboundPackets1_9_3.CUSTOM_PAYLOAD);
|
||||
|
||||
registerContainerClick(ServerboundPackets1_9_3.CONTAINER_CLICK);
|
||||
registerSetCreativeModeSlot(ServerboundPackets1_9_3.SET_CREATIVE_MODE_SLOT);
|
||||
|
||||
+1
-29
@@ -42,35 +42,7 @@ public class ItemPacketRewriter1_11_1 extends LegacyBlockItemRewriter<Clientboun
|
||||
registerSetSlot(ClientboundPackets1_9_3.CONTAINER_SET_SLOT);
|
||||
registerSetContent(ClientboundPackets1_9_3.CONTAINER_SET_CONTENT);
|
||||
registerSetEquippedItem(ClientboundPackets1_9_3.SET_EQUIPPED_ITEM);
|
||||
|
||||
// Plugin message Packet -> Trading
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.CUSTOM_PAYLOAD, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // 0 - Channel
|
||||
|
||||
handler(wrapper -> {
|
||||
if (wrapper.get(Types.STRING, 0).equals("MC|TrList")) {
|
||||
wrapper.passthrough(Types.INT); // Passthrough Window ID
|
||||
|
||||
int size = wrapper.passthrough(Types.UNSIGNED_BYTE);
|
||||
for (int i = 0; i < size; i++) {
|
||||
wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Input Item
|
||||
wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Output Item
|
||||
|
||||
boolean secondItem = wrapper.passthrough(Types.BOOLEAN); // Has second item
|
||||
if (secondItem) {
|
||||
wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Second Item
|
||||
}
|
||||
|
||||
wrapper.passthrough(Types.BOOLEAN); // Trade disabled
|
||||
wrapper.passthrough(Types.INT); // Number of tools uses
|
||||
wrapper.passthrough(Types.INT); // Maximum number of trade uses
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
registerCustomPayloadTradeList(ClientboundPackets1_9_3.CUSTOM_PAYLOAD);
|
||||
|
||||
registerContainerClick(ServerboundPackets1_9_3.CONTAINER_CLICK);
|
||||
registerSetCreativeModeSlot(ServerboundPackets1_9_3.SET_CREATIVE_MODE_SLOT);
|
||||
|
||||
+2
-30
@@ -113,35 +113,7 @@ public class BlockItemPacketRewriter1_11 extends LegacyBlockItemRewriter<Clientb
|
||||
});
|
||||
|
||||
registerSetEquippedItem(ClientboundPackets1_9_3.SET_EQUIPPED_ITEM);
|
||||
|
||||
// Plugin message -> Trading
|
||||
protocol.registerClientbound(ClientboundPackets1_9_3.CUSTOM_PAYLOAD, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // 0 - Channel
|
||||
|
||||
handler(wrapper -> {
|
||||
if (wrapper.get(Types.STRING, 0).equals("MC|TrList")) {
|
||||
wrapper.passthrough(Types.INT); // Passthrough Window ID
|
||||
|
||||
int size = wrapper.passthrough(Types.UNSIGNED_BYTE);
|
||||
for (int i = 0; i < size; i++) {
|
||||
wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Input Item
|
||||
wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Output Item
|
||||
|
||||
boolean secondItem = wrapper.passthrough(Types.BOOLEAN); // Has second item
|
||||
if (secondItem) {
|
||||
wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Second Item
|
||||
}
|
||||
|
||||
wrapper.passthrough(Types.BOOLEAN); // Trade disabled
|
||||
wrapper.passthrough(Types.INT); // Number of tools uses
|
||||
wrapper.passthrough(Types.INT); // Maximum number of trade uses
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
registerCustomPayloadTradeList(ClientboundPackets1_9_3.CUSTOM_PAYLOAD);
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_9_3.CONTAINER_CLICK, new PacketHandlers() {
|
||||
@Override
|
||||
@@ -295,7 +267,7 @@ public class BlockItemPacketRewriter1_11 extends LegacyBlockItemRewriter<Clientb
|
||||
|
||||
@Override
|
||||
public Item handleItemToClient(UserConnection connection, Item item) {
|
||||
if (item == null || item.isEmpty()) return null;
|
||||
if (item == null) return null;
|
||||
super.handleItemToClient(connection, item);
|
||||
|
||||
CompoundTag tag = item.tag();
|
||||
|
||||
+1
-28
@@ -86,34 +86,7 @@ public class BlockItemPacketRewriter1_12 extends LegacyBlockItemRewriter<Clientb
|
||||
registerSetSlot(ClientboundPackets1_12.CONTAINER_SET_SLOT);
|
||||
registerSetContent(ClientboundPackets1_12.CONTAINER_SET_CONTENT);
|
||||
registerSetEquippedItem(ClientboundPackets1_12.SET_EQUIPPED_ITEM);
|
||||
|
||||
// Plugin message Packet -> Trading
|
||||
protocol.registerClientbound(ClientboundPackets1_12.CUSTOM_PAYLOAD, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.STRING); // 0 - Channel
|
||||
|
||||
handler(wrapper -> {
|
||||
if (wrapper.get(Types.STRING, 0).equals("MC|TrList")) {
|
||||
wrapper.passthrough(Types.INT); // Passthrough Window ID
|
||||
|
||||
int size = wrapper.passthrough(Types.UNSIGNED_BYTE);
|
||||
for (int i = 0; i < size; i++) {
|
||||
wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Input Item
|
||||
wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Output Item
|
||||
|
||||
boolean secondItem = wrapper.passthrough(Types.BOOLEAN); // Has second item
|
||||
if (secondItem)
|
||||
wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Second Item
|
||||
|
||||
wrapper.passthrough(Types.BOOLEAN); // Trade disabled
|
||||
wrapper.passthrough(Types.INT); // Number of tools uses
|
||||
wrapper.passthrough(Types.INT); // Maximum number of trade uses
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
registerCustomPayloadTradeList(ClientboundPackets1_12.CUSTOM_PAYLOAD);
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_9_3.CONTAINER_CLICK, new PacketHandlers() {
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ public class BlockItemPacketRewriter1_13 extends BackwardsItemRewriter<Clientbou
|
||||
private final String extraNbtTag;
|
||||
|
||||
public BlockItemPacketRewriter1_13(Protocol1_13To1_12_2 protocol) {
|
||||
super(protocol, null, null);
|
||||
super(protocol, Types.ITEM1_13, Types.ITEM1_13_SHORT_ARRAY, Types.ITEM1_8, Types.ITEM1_8_SHORT_ARRAY);
|
||||
extraNbtTag = nbtTagName("2");
|
||||
}
|
||||
|
||||
|
||||
+1
-22
@@ -77,28 +77,7 @@ public class PlayerPacketRewriter1_13 extends RewriterBase<Protocol1_13To1_12_2>
|
||||
String channel = wrapper.read(Types.STRING);
|
||||
if (channel.equals("minecraft:trader_list")) {
|
||||
wrapper.write(Types.STRING, "MC|TrList");
|
||||
wrapper.passthrough(Types.INT); //Passthrough Window ID
|
||||
|
||||
int size = wrapper.passthrough(Types.UNSIGNED_BYTE);
|
||||
for (int i = 0; i < size; i++) {
|
||||
//Input Item
|
||||
Item input = wrapper.read(Types.ITEM1_13);
|
||||
wrapper.write(Types.ITEM1_8, protocol.getItemRewriter().handleItemToClient(wrapper.user(), input));
|
||||
//Output Item
|
||||
Item output = wrapper.read(Types.ITEM1_13);
|
||||
wrapper.write(Types.ITEM1_8, protocol.getItemRewriter().handleItemToClient(wrapper.user(), output));
|
||||
|
||||
boolean secondItem = wrapper.passthrough(Types.BOOLEAN); //Has second item
|
||||
if (secondItem) {
|
||||
//Second Item
|
||||
Item second = wrapper.read(Types.ITEM1_13);
|
||||
wrapper.write(Types.ITEM1_8, protocol.getItemRewriter().handleItemToClient(wrapper.user(), second));
|
||||
}
|
||||
|
||||
wrapper.passthrough(Types.BOOLEAN); //Trade disabled
|
||||
wrapper.passthrough(Types.INT); //Number of tools uses
|
||||
wrapper.passthrough(Types.INT); //Maximum number of trade uses
|
||||
}
|
||||
protocol.getItemRewriter().handleTradeList(wrapper);
|
||||
} else {
|
||||
String oldChannel = ItemPacketRewriter1_13.getOldPluginChannelId(channel);
|
||||
if (oldChannel == null) {
|
||||
|
||||
+1
-1
@@ -191,7 +191,7 @@ public class Protocol1_14To1_13_2 extends BackwardsProtocol<ClientboundPackets1_
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableRewriter<ClientboundPackets1_14> getTranslatableRewriter() {
|
||||
public TranslatableRewriter<ClientboundPackets1_14> getComponentRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -127,7 +127,7 @@ public class Protocol1_15To1_14_4 extends BackwardsProtocol<ClientboundPackets1_
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableRewriter<ClientboundPackets1_15> getTranslatableRewriter() {
|
||||
public TranslatableRewriter<ClientboundPackets1_15> getComponentRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -127,7 +127,7 @@ public class Protocol1_16_2To1_16_1 extends BackwardsProtocol<ClientboundPackets
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableRewriter<ClientboundPackets1_16_2> getTranslatableRewriter() {
|
||||
public TranslatableRewriter<ClientboundPackets1_16_2> getComponentRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -177,7 +177,7 @@ public class Protocol1_16To1_15_2 extends BackwardsProtocol<ClientboundPackets1_
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableRewriter1_16 getTranslatableRewriter() {
|
||||
public TranslatableRewriter1_16 getComponentRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -283,7 +283,7 @@ public class BlockItemPacketRewriter1_16 extends BackwardsItemRewriter<Clientbou
|
||||
ListTag<StringTag> pagesTag = tag.getListTag("pages", StringTag.class);
|
||||
if (pagesTag != null) {
|
||||
for (StringTag page : pagesTag) {
|
||||
JsonElement jsonElement = protocol.getTranslatableRewriter().processText(connection, page.getValue());
|
||||
JsonElement jsonElement = protocol.getComponentRewriter().processText(connection, page.getValue());
|
||||
page.setValue(jsonElement.toString());
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -215,14 +215,14 @@ public class EntityPacketRewriter1_16 extends EntityRewriter<ClientboundPackets1
|
||||
wrapper.passthrough(Types.VAR_INT);
|
||||
wrapper.passthrough(Types.VAR_INT);
|
||||
// Display Name
|
||||
protocol.getTranslatableRewriter().processText(wrapper.user(), wrapper.passthrough(Types.OPTIONAL_COMPONENT));
|
||||
protocol.getComponentRewriter().processText(wrapper.user(), wrapper.passthrough(Types.OPTIONAL_COMPONENT));
|
||||
} else if (action == 1) { // Update Game Mode
|
||||
wrapper.passthrough(Types.VAR_INT);
|
||||
} else if (action == 2) { // Update Ping
|
||||
wrapper.passthrough(Types.VAR_INT);
|
||||
} else if (action == 3) { // Update Display Name
|
||||
// Display name
|
||||
protocol.getTranslatableRewriter().processText(wrapper.user(), wrapper.passthrough(Types.OPTIONAL_COMPONENT));
|
||||
protocol.getComponentRewriter().processText(wrapper.user(), wrapper.passthrough(Types.OPTIONAL_COMPONENT));
|
||||
} // 4 = Remove Player
|
||||
}
|
||||
});
|
||||
@@ -243,7 +243,7 @@ public class EntityPacketRewriter1_16 extends EntityRewriter<ClientboundPackets1
|
||||
} else if (type == Types1_14.ENTITY_DATA_TYPES.optionalComponentType) {
|
||||
JsonElement text = meta.value();
|
||||
if (text != null) {
|
||||
protocol.getTranslatableRewriter().processText(event.user(), text);
|
||||
protocol.getComponentRewriter().processText(event.user(), text);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+1
-1
@@ -231,7 +231,7 @@ public final class Protocol1_17To1_16_4 extends BackwardsProtocol<ClientboundPac
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableRewriter<ClientboundPackets1_17> getTranslatableRewriter() {
|
||||
public TranslatableRewriter<ClientboundPackets1_17> getComponentRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -152,7 +152,7 @@ public final class Protocol1_18To1_17_1 extends BackwardsProtocol<ClientboundPac
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableRewriter<ClientboundPackets1_18> getTranslatableRewriter() {
|
||||
public TranslatableRewriter<ClientboundPackets1_18> getComponentRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -395,7 +395,7 @@ public final class Protocol1_19_1To1_19 extends BackwardsProtocol<ClientboundPac
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableRewriter<ClientboundPackets1_19_1> getTranslatableRewriter() {
|
||||
public TranslatableRewriter<ClientboundPackets1_19_1> getComponentRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -403,7 +403,7 @@ public final class Protocol1_19_3To1_19_1 extends BackwardsProtocol<ClientboundP
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableRewriter<ClientboundPackets1_19_3> getTranslatableRewriter() {
|
||||
public TranslatableRewriter<ClientboundPackets1_19_3> getComponentRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -136,7 +136,7 @@ public final class Protocol1_19_4To1_19_3 extends BackwardsProtocol<ClientboundP
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableRewriter<ClientboundPackets1_19_4> getTranslatableRewriter() {
|
||||
public TranslatableRewriter<ClientboundPackets1_19_4> getComponentRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -21,7 +21,6 @@ import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_19_4to1_19_3.Protocol1_19_4To1_19_3;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18;
|
||||
import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.packet.ServerboundPackets1_19_3;
|
||||
@@ -60,7 +59,7 @@ public final class BlockItemPacketRewriter1_19_4 extends BackwardsItemRewriter<C
|
||||
wrapper.set(Types.VAR_INT, 1, windowType - 1);
|
||||
}
|
||||
|
||||
protocol.getTranslatableRewriter().processText(wrapper.user(), wrapper.get(Types.COMPONENT, 0));
|
||||
protocol.getComponentRewriter().processText(wrapper.user(), wrapper.get(Types.COMPONENT, 0));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
+1
-1
@@ -159,7 +159,7 @@ public final class EntityPacketRewriter1_19_4 extends EntityRewriter<Clientbound
|
||||
event.createExtraData(new EntityData(3, Types1_19_3.ENTITY_DATA_TYPES.booleanType, true)); // Show custom name
|
||||
|
||||
final JsonElement element = meta.value();
|
||||
protocol.getTranslatableRewriter().processText(event.user(), element);
|
||||
protocol.getComponentRewriter().processText(event.user(), element);
|
||||
}));
|
||||
filter().type(EntityTypes1_19_4.DISPLAY).handler((event, meta) -> {
|
||||
// TODO Maybe spawn an extra entity to ride the armor stand for blocks and items
|
||||
|
||||
+1
-1
@@ -372,7 +372,7 @@ public final class Protocol1_19To1_18_2 extends BackwardsProtocol<ClientboundPac
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableRewriter<ClientboundPackets1_19> getTranslatableRewriter() {
|
||||
public TranslatableRewriter<ClientboundPackets1_19> getComponentRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
|
||||
|
||||
+12
-1
@@ -18,6 +18,7 @@
|
||||
package com.viaversion.viabackwards.protocol.v1_20_2to1_20.rewriter;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.IntArrayTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter;
|
||||
@@ -378,6 +379,11 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
|
||||
}
|
||||
if (item.tag() != null) {
|
||||
com.viaversion.viaversion.protocols.v1_20to1_20_2.rewriter.BlockItemPacketRewriter1_20_2.to1_20_1Effects(item);
|
||||
|
||||
final CompoundTag skullOwnerTag = item.tag().getCompoundTag("SkullOwner");
|
||||
if (skullOwnerTag != null && !skullOwnerTag.contains("Id") && skullOwnerTag.contains("Properties")) {
|
||||
skullOwnerTag.put("Id", new IntArrayTag(new int[]{0, 0, 0, 0}));
|
||||
}
|
||||
}
|
||||
|
||||
return super.handleItemToClient(connection, item);
|
||||
@@ -411,6 +417,11 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<C
|
||||
final String effectKey = Key.stripMinecraftNamespace(((StringTag) secondaryEffect).getValue());
|
||||
tag.putInt("Secondary", PotionEffects1_20_2.keyToId(effectKey) + 1); // Empty effect at 0
|
||||
}
|
||||
|
||||
final CompoundTag skullOwnerTag = tag.getCompoundTag("SkullOwner");
|
||||
if (skullOwnerTag != null && !skullOwnerTag.contains("Id") && skullOwnerTag.contains("Properties")) {
|
||||
skullOwnerTag.put("Id", new IntArrayTag(new int[]{0, 0, 0, 0}));
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -398,7 +398,7 @@ public final class Protocol1_20_3To1_20_2 extends BackwardsProtocol<ClientboundP
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableRewriter<ClientboundPacket1_20_3> getTranslatableRewriter() {
|
||||
public TranslatableRewriter<ClientboundPacket1_20_3> getComponentRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -254,7 +254,7 @@ public final class Protocol1_20_5To1_20_3 extends BackwardsProtocol<ClientboundP
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableRewriter<ClientboundPacket1_20_5> getTranslatableRewriter() {
|
||||
public TranslatableRewriter<ClientboundPacket1_20_5> getComponentRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
|
||||
|
||||
+27
-9
@@ -23,10 +23,13 @@ import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.StructuredEnchantmentRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_20_5to1_20_3.Protocol1_20_5To1_20_3;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.Holder;
|
||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
import com.viaversion.viaversion.api.minecraft.SoundEvent;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
@@ -37,6 +40,7 @@ import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_20_3;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntFunction;
|
||||
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ServerboundPacket1_20_3;
|
||||
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ServerboundPackets1_20_3;
|
||||
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.rewriter.RecipeRewriter1_20_3;
|
||||
@@ -53,6 +57,7 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem
|
||||
|
||||
private static final StructuredDataConverter DATA_CONVERTER = new StructuredDataConverter(true);
|
||||
private final Protocol1_20_3To1_20_5 vvProtocol = Via.getManager().getProtocolManager().getProtocol(Protocol1_20_3To1_20_5.class);
|
||||
private final StructuredEnchantmentRewriter enchantmentRewriter = new StructuredEnchantmentRewriter(this);
|
||||
|
||||
public BlockItemPacketRewriter1_20_5(final Protocol1_20_5To1_20_3 protocol) {
|
||||
super(protocol, Types1_20_5.ITEM, Types1_20_5.ITEM_ARRAY, Types.ITEM1_20_2, Types.ITEM1_20_2_ARRAY);
|
||||
@@ -140,16 +145,17 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem
|
||||
protocol.getEntityRewriter().rewriteParticle(wrapper, Types1_20_5.PARTICLE, Types1_20_3.PARTICLE); // Small explosion particle
|
||||
protocol.getEntityRewriter().rewriteParticle(wrapper, Types1_20_5.PARTICLE, Types1_20_3.PARTICLE); // Large explosion particle
|
||||
|
||||
int soundId = wrapper.read(Types.VAR_INT) - 1;
|
||||
if (soundId == -1) {
|
||||
// Already followed by the resource location
|
||||
return;
|
||||
final Holder<SoundEvent> soundEventHolder = wrapper.read(Types.SOUND_EVENT);
|
||||
if (soundEventHolder.isDirect()) {
|
||||
final SoundEvent soundEvent = soundEventHolder.value();
|
||||
wrapper.write(Types.STRING, soundEvent.identifier());
|
||||
wrapper.write(Types.OPTIONAL_FLOAT, soundEvent.fixedRange());
|
||||
} else {
|
||||
final int soundId = protocol.getMappingData().getSoundMappings().getNewId(soundEventHolder.id());
|
||||
final String soundKey = Protocol1_20_3To1_20_5.MAPPINGS.soundName(soundId);
|
||||
wrapper.write(Types.STRING, soundKey != null ? soundKey : "minecraft:entity.generic.explode");
|
||||
wrapper.write(Types.OPTIONAL_FLOAT, null); // Fixed range
|
||||
}
|
||||
|
||||
soundId = protocol.getMappingData().getSoundMappings().getNewId(soundId);
|
||||
final String soundKey = Protocol1_20_3To1_20_5.MAPPINGS.soundName(soundId);
|
||||
wrapper.write(Types.STRING, soundKey != null ? soundKey : "minecraft:entity.generic.explode");
|
||||
wrapper.write(Types.OPTIONAL_FLOAT, null); // Fixed range
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_20_5.MERCHANT_OFFERS, wrapper -> {
|
||||
@@ -329,6 +335,9 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem
|
||||
return null;
|
||||
}
|
||||
|
||||
item.dataContainer().setIdLookup(protocol, true);
|
||||
enchantmentRewriter.handleToClient(item);
|
||||
|
||||
super.handleItemToClient(connection, item);
|
||||
|
||||
// In 1.20.6, some items have default values which are not written into the components
|
||||
@@ -345,6 +354,11 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem
|
||||
return oldItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateItemComponents(final UserConnection connection, final StructuredDataContainer container, final ItemHandler itemHandler, @Nullable final Int2IntFunction idRewriter, @Nullable final Int2IntFunction blockIdRewriter) {
|
||||
// Items and data within components are handled in this protocol
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToServer(final UserConnection connection, @Nullable final Item item) {
|
||||
if (item == null) {
|
||||
@@ -354,6 +368,10 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem
|
||||
|
||||
// Convert to structured item first
|
||||
final Item structuredItem = vvProtocol.getItemRewriter().toStructuredItem(connection, item);
|
||||
|
||||
structuredItem.dataContainer().setIdLookup(protocol, false);
|
||||
enchantmentRewriter.handleToServer(structuredItem);
|
||||
|
||||
return super.handleItemToServer(connection, structuredItem);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -113,7 +113,7 @@ public final class Protocol1_20To1_19_4 extends BackwardsProtocol<ClientboundPac
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableRewriter<ClientboundPackets1_19_4> getTranslatableRewriter() {
|
||||
public TranslatableRewriter<ClientboundPackets1_19_4> getComponentRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
|
||||
|
||||
+219
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.v1_21to1_20_5;
|
||||
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
|
||||
import com.viaversion.viabackwards.api.rewriters.SoundRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.rewriter.BlockItemPacketRewriter1_21;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.rewriter.ComponentRewriter1_21;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.rewriter.EntityPacketRewriter1_21;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage.EnchantmentsPaintingsStorage;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.Holder;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.ChatType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
|
||||
import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundConfigurationPackets1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPacket1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundConfigurationPackets1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.Protocol1_20_5To1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21;
|
||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
|
||||
import static com.viaversion.viaversion.util.ProtocolUtil.packetTypeMap;
|
||||
|
||||
public final class Protocol1_21To1_20_5 extends BackwardsProtocol<ClientboundPacket1_21, ClientboundPacket1_20_5, ServerboundPacket1_20_5, ServerboundPacket1_20_5> {
|
||||
|
||||
public static final BackwardsMappingData MAPPINGS = new BackwardsMappingData("1.21", "1.20.5", Protocol1_20_5To1_21.class);
|
||||
private final EntityPacketRewriter1_21 entityRewriter = new EntityPacketRewriter1_21(this);
|
||||
private final BlockItemPacketRewriter1_21 itemRewriter = new BlockItemPacketRewriter1_21(this);
|
||||
private final TranslatableRewriter<ClientboundPacket1_21> translatableRewriter = new ComponentRewriter1_21(this);
|
||||
private final TagRewriter<ClientboundPacket1_21> tagRewriter = new TagRewriter<>(this);
|
||||
|
||||
public Protocol1_21To1_20_5() {
|
||||
super(ClientboundPacket1_21.class, ClientboundPacket1_20_5.class, ServerboundPacket1_20_5.class, ServerboundPacket1_20_5.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
super.registerPackets();
|
||||
|
||||
tagRewriter.registerGeneric(ClientboundPackets1_21.UPDATE_TAGS);
|
||||
tagRewriter.registerGeneric(ClientboundConfigurationPackets1_21.UPDATE_TAGS);
|
||||
|
||||
final SoundRewriter<ClientboundPacket1_21> soundRewriter = new SoundRewriter<>(this);
|
||||
soundRewriter.registerSound1_19_3(ClientboundPackets1_21.SOUND);
|
||||
soundRewriter.registerSound1_19_3(ClientboundPackets1_21.SOUND_ENTITY);
|
||||
soundRewriter.registerStopSound(ClientboundPackets1_21.STOP_SOUND);
|
||||
|
||||
new StatisticsRewriter<>(this).register(ClientboundPackets1_21.AWARD_STATS);
|
||||
|
||||
translatableRewriter.registerOpenScreen(ClientboundPackets1_21.OPEN_SCREEN);
|
||||
translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SET_ACTION_BAR_TEXT);
|
||||
translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SET_TITLE_TEXT);
|
||||
translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SET_SUBTITLE_TEXT);
|
||||
translatableRewriter.registerBossEvent(ClientboundPackets1_21.BOSS_EVENT);
|
||||
translatableRewriter.registerComponentPacket(ClientboundPackets1_21.DISCONNECT);
|
||||
translatableRewriter.registerTabList(ClientboundPackets1_21.TAB_LIST);
|
||||
translatableRewriter.registerPlayerCombatKill1_20(ClientboundPackets1_21.PLAYER_COMBAT_KILL);
|
||||
translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SYSTEM_CHAT);
|
||||
translatableRewriter.registerPing();
|
||||
|
||||
// Format change we can't properly map - all this really results in is a desync one version earlier
|
||||
cancelClientbound(ClientboundPackets1_21.PROJECTILE_POWER);
|
||||
|
||||
cancelClientbound(ClientboundPackets1_21.CUSTOM_REPORT_DETAILS);
|
||||
cancelClientbound(ClientboundPackets1_21.SERVER_LINKS);
|
||||
cancelClientbound(ClientboundConfigurationPackets1_21.CUSTOM_REPORT_DETAILS);
|
||||
cancelClientbound(ClientboundConfigurationPackets1_21.SERVER_LINKS);
|
||||
|
||||
registerClientbound(ClientboundPackets1_21.DISGUISED_CHAT, wrapper -> {
|
||||
translatableRewriter.processTag(wrapper.user(), wrapper.passthrough(Types.TAG)); // Message
|
||||
|
||||
final Holder<ChatType> chatType = wrapper.read(ChatType.TYPE);
|
||||
if (chatType.isDirect()) {
|
||||
// Oh well
|
||||
wrapper.write(Types.VAR_INT, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
wrapper.write(Types.VAR_INT, chatType.id());
|
||||
});
|
||||
registerClientbound(ClientboundPackets1_21.PLAYER_CHAT, wrapper -> {
|
||||
wrapper.passthrough(Types.UUID); // Sender
|
||||
wrapper.passthrough(Types.VAR_INT); // Index
|
||||
wrapper.passthrough(Types.OPTIONAL_SIGNATURE_BYTES); // Signature
|
||||
wrapper.passthrough(Types.STRING); // Plain content
|
||||
wrapper.passthrough(Types.LONG); // Timestamp
|
||||
wrapper.passthrough(Types.LONG); // Salt
|
||||
|
||||
final int lastSeen = wrapper.passthrough(Types.VAR_INT);
|
||||
for (int i = 0; i < lastSeen; i++) {
|
||||
final int index = wrapper.passthrough(Types.VAR_INT);
|
||||
if (index == 0) {
|
||||
wrapper.passthrough(Types.SIGNATURE_BYTES);
|
||||
}
|
||||
}
|
||||
|
||||
wrapper.passthrough(Types.OPTIONAL_TAG); // Unsigned content
|
||||
|
||||
final int filterMaskType = wrapper.passthrough(Types.VAR_INT);
|
||||
if (filterMaskType == 2) {
|
||||
wrapper.passthrough(Types.LONG_ARRAY_PRIMITIVE); // Mask
|
||||
}
|
||||
|
||||
final Holder<ChatType> chatType = wrapper.read(ChatType.TYPE);
|
||||
if (chatType.isDirect()) {
|
||||
// Oh well
|
||||
wrapper.write(Types.VAR_INT, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
wrapper.write(Types.VAR_INT, chatType.id());
|
||||
});
|
||||
|
||||
registerClientbound(ClientboundPackets1_21.UPDATE_ATTRIBUTES, wrapper -> {
|
||||
wrapper.passthrough(Types.VAR_INT); // Entity ID
|
||||
|
||||
final int size = wrapper.passthrough(Types.VAR_INT);
|
||||
int newSize = size;
|
||||
for (int i = 0; i < size; i++) {
|
||||
final int attributeId = wrapper.read(Types.VAR_INT);
|
||||
final int mappedId = MAPPINGS.getNewAttributeId(attributeId);
|
||||
if (mappedId == -1) {
|
||||
newSize--;
|
||||
|
||||
wrapper.read(Types.DOUBLE); // Base
|
||||
final int modifierSize = wrapper.read(Types.VAR_INT);
|
||||
for (int j = 0; j < modifierSize; j++) {
|
||||
wrapper.read(Types.STRING); // ID
|
||||
wrapper.read(Types.DOUBLE); // Amount
|
||||
wrapper.read(Types.BYTE); // Operation
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
wrapper.write(Types.VAR_INT, mappedId);
|
||||
wrapper.passthrough(Types.DOUBLE); // Base
|
||||
final int modifierSize = wrapper.passthrough(Types.VAR_INT);
|
||||
for (int j = 0; j < modifierSize; j++) {
|
||||
final String id = wrapper.read(Types.STRING);
|
||||
wrapper.write(Types.UUID, Protocol1_20_5To1_21.mapAttributeId(id));
|
||||
wrapper.passthrough(Types.DOUBLE); // Amount
|
||||
wrapper.passthrough(Types.BYTE); // Operation
|
||||
}
|
||||
}
|
||||
|
||||
if (size != newSize) {
|
||||
wrapper.set(Types.VAR_INT, 1, newSize);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(final UserConnection user) {
|
||||
addEntityTracker(user, new EntityTrackerBase(user, EntityTypes1_20_5.PLAYER));
|
||||
user.put(new EnchantmentsPaintingsStorage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BackwardsMappingData getMappingData() {
|
||||
return MAPPINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPacketRewriter1_21 getEntityRewriter() {
|
||||
return entityRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockItemPacketRewriter1_21 getItemRewriter() {
|
||||
return itemRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableRewriter<ClientboundPacket1_21> getComponentRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagRewriter<ClientboundPacket1_21> getTagRewriter() {
|
||||
return tagRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PacketTypesProvider<ClientboundPacket1_21, ClientboundPacket1_20_5, ServerboundPacket1_20_5, ServerboundPacket1_20_5> createPacketTypesProvider() {
|
||||
return new SimplePacketTypesProvider<>(
|
||||
packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_21.class, ClientboundConfigurationPackets1_21.class),
|
||||
packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_20_5.class, ClientboundConfigurationPackets1_20_5.class),
|
||||
packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class),
|
||||
packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class)
|
||||
);
|
||||
}
|
||||
}
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.v1_21to1_20_5.rewriter;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.StructuredEnchantmentRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.Protocol1_21To1_20_5;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage.EnchantmentsPaintingsStorage;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Enchantments;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_21;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
|
||||
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.rewriter.RecipeRewriter1_20_3;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.Enchantments1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21;
|
||||
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
||||
import com.viaversion.viaversion.rewriter.IdRewriteFunction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.BlockItemPacketRewriter1_21.downgradeItemData;
|
||||
import static com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.BlockItemPacketRewriter1_21.updateItemData;
|
||||
|
||||
public final class BlockItemPacketRewriter1_21 extends BackwardsStructuredItemRewriter<ClientboundPacket1_21, ServerboundPacket1_20_5, Protocol1_21To1_20_5> {
|
||||
|
||||
private final StructuredEnchantmentRewriter enchantmentRewriter = new StructuredEnchantmentRewriter(this);
|
||||
|
||||
public BlockItemPacketRewriter1_21(final Protocol1_21To1_20_5 protocol) {
|
||||
super(protocol, Types1_21.ITEM, Types1_21.ITEM_ARRAY, Types1_20_5.ITEM, Types1_20_5.ITEM_ARRAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPackets() {
|
||||
final BlockRewriter<ClientboundPacket1_21> blockRewriter = BlockRewriter.for1_20_2(protocol);
|
||||
blockRewriter.registerBlockEvent(ClientboundPackets1_21.BLOCK_EVENT);
|
||||
blockRewriter.registerBlockUpdate(ClientboundPackets1_21.BLOCK_UPDATE);
|
||||
blockRewriter.registerSectionBlocksUpdate1_20(ClientboundPackets1_21.SECTION_BLOCKS_UPDATE);
|
||||
blockRewriter.registerLevelChunk1_19(ClientboundPackets1_21.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_20_2::new);
|
||||
blockRewriter.registerBlockEntityData(ClientboundPackets1_21.BLOCK_ENTITY_DATA);
|
||||
|
||||
registerCooldown(ClientboundPackets1_21.COOLDOWN);
|
||||
registerSetContent1_17_1(ClientboundPackets1_21.CONTAINER_SET_CONTENT);
|
||||
registerSetSlot1_17_1(ClientboundPackets1_21.CONTAINER_SET_SLOT);
|
||||
registerAdvancements1_20_3(ClientboundPackets1_21.UPDATE_ADVANCEMENTS);
|
||||
registerSetEquipment(ClientboundPackets1_21.SET_EQUIPMENT);
|
||||
registerContainerClick1_17_1(ServerboundPackets1_20_5.CONTAINER_CLICK);
|
||||
registerMerchantOffers1_20_5(ClientboundPackets1_21.MERCHANT_OFFERS, Types1_21.ITEM_COST, Types1_20_5.ITEM_COST, Types1_21.OPTIONAL_ITEM_COST, Types1_20_5.OPTIONAL_ITEM_COST);
|
||||
registerSetCreativeModeSlot(ServerboundPackets1_20_5.SET_CREATIVE_MODE_SLOT);
|
||||
registerContainerSetData(ClientboundPackets1_21.CONTAINER_SET_DATA);
|
||||
registerLevelParticles1_20_5(ClientboundPackets1_21.LEVEL_PARTICLES, Types1_21.PARTICLE, Types1_20_5.PARTICLE);
|
||||
registerExplosion(ClientboundPackets1_21.EXPLODE, Types1_21.PARTICLE, Types1_20_5.PARTICLE);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_21.HORSE_SCREEN_OPEN, wrapper -> {
|
||||
wrapper.passthrough(Types.UNSIGNED_BYTE); // Container id
|
||||
|
||||
// From columns to size
|
||||
final int columns = wrapper.read(Types.VAR_INT);
|
||||
wrapper.write(Types.VAR_INT, columns * 3 + 1);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_21.LEVEL_EVENT, wrapper -> {
|
||||
final int event = wrapper.passthrough(Types.INT);
|
||||
wrapper.passthrough(Types.BLOCK_POSITION1_14);
|
||||
|
||||
final int data = wrapper.read(Types.INT);
|
||||
if (event == 1010) {
|
||||
final int itemId = wrapper.user().get(EnchantmentsPaintingsStorage.class).jubeboxSongToItem(data);
|
||||
if (itemId == -1) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
wrapper.write(Types.INT, itemId);
|
||||
} else if (event == 2001) {
|
||||
wrapper.write(Types.INT, protocol.getMappingData().getNewBlockStateId(data));
|
||||
} else {
|
||||
wrapper.write(Types.INT, data);
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_20_5.USE_ITEM, wrapper -> {
|
||||
wrapper.passthrough(Types.VAR_INT); // Hand
|
||||
wrapper.passthrough(Types.VAR_INT); // Sequence
|
||||
wrapper.write(Types.FLOAT, 0f); // Y rotation
|
||||
wrapper.write(Types.FLOAT, 0f); // X rotation
|
||||
});
|
||||
|
||||
new RecipeRewriter1_20_3<>(protocol).register1_20_5(ClientboundPackets1_21.UPDATE_RECIPES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToClient(final UserConnection connection, final Item item) {
|
||||
if (item.isEmpty()) {
|
||||
return item;
|
||||
}
|
||||
|
||||
final StructuredDataContainer data = item.dataContainer();
|
||||
data.setIdLookup(protocol, true);
|
||||
|
||||
// Enchantments
|
||||
final EnchantmentsPaintingsStorage storage = connection.get(EnchantmentsPaintingsStorage.class);
|
||||
final IdRewriteFunction idRewriteFunction = id -> {
|
||||
final String key = storage.enchantments().idToKey(id);
|
||||
return key != null ? Enchantments1_20_5.keyToId(key) : -1;
|
||||
};
|
||||
final StructuredEnchantmentRewriter.DescriptionSupplier descriptionSupplier = (id, level) -> {
|
||||
final Tag description = storage.enchantmentDescription(id);
|
||||
if (description == null) {
|
||||
return new StringTag("Unknown enchantment");
|
||||
}
|
||||
|
||||
final CompoundTag fullDescription = new CompoundTag();
|
||||
fullDescription.putString("translate", "%s " + EnchantmentRewriter.getRomanNumber(level));
|
||||
fullDescription.put("with", new ListTag<>(Arrays.asList(description)));
|
||||
return fullDescription;
|
||||
};
|
||||
enchantmentRewriter.rewriteEnchantmentsToClient(data, StructuredDataKey.ENCHANTMENTS, idRewriteFunction, descriptionSupplier, false);
|
||||
enchantmentRewriter.rewriteEnchantmentsToClient(data, StructuredDataKey.STORED_ENCHANTMENTS, idRewriteFunction, descriptionSupplier, true);
|
||||
|
||||
// Order is important
|
||||
super.handleItemToClient(connection, item);
|
||||
downgradeItemData(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToServer(final UserConnection connection, final Item item) {
|
||||
if (item.isEmpty()) {
|
||||
return item;
|
||||
}
|
||||
|
||||
final StructuredDataContainer dataContainer = item.dataContainer();
|
||||
dataContainer.setIdLookup(protocol, false);
|
||||
|
||||
// Rewrite enchantments
|
||||
final EnchantmentsPaintingsStorage storage = connection.get(EnchantmentsPaintingsStorage.class);
|
||||
rewriteEnchantmentToServer(storage, item, StructuredDataKey.ENCHANTMENTS);
|
||||
rewriteEnchantmentToServer(storage, item, StructuredDataKey.STORED_ENCHANTMENTS);
|
||||
|
||||
// Restore originals if present
|
||||
enchantmentRewriter.handleToServer(item);
|
||||
|
||||
// Order is important
|
||||
super.handleItemToServer(connection, item);
|
||||
updateItemData(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
private void rewriteEnchantmentToServer(final EnchantmentsPaintingsStorage storage, final Item item, final StructuredDataKey<Enchantments> key) {
|
||||
final StructuredData<Enchantments> enchantmentsData = item.dataContainer().getNonEmpty(key);
|
||||
if (enchantmentsData == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Enchantments enchantments = enchantmentsData.value();
|
||||
for (final Int2IntMap.Entry entry : new ArrayList<>(enchantments.enchantments().int2IntEntrySet())) {
|
||||
final int id = entry.getIntKey();
|
||||
final String enchantmentKey = Enchantments1_20_5.idToKey(id);
|
||||
if (enchantmentKey == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final int mappedId = storage.enchantments().keyToId(enchantmentKey);
|
||||
if (id != mappedId) {
|
||||
enchantments.enchantments().remove(id);
|
||||
enchantments.enchantments().put(mappedId, entry.getIntValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.v1_21to1_20_5.rewriter;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.IntArrayTag;
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.Protocol1_21To1_20_5;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.Protocol1_20_5To1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.data.AttributeModifierMappings1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21;
|
||||
import com.viaversion.viaversion.util.SerializerVersion;
|
||||
import com.viaversion.viaversion.util.TagUtil;
|
||||
import com.viaversion.viaversion.util.UUIDUtil;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class ComponentRewriter1_21 extends TranslatableRewriter<ClientboundPacket1_21> {
|
||||
|
||||
public ComponentRewriter1_21(final Protocol1_21To1_20_5 protocol) {
|
||||
super(protocol, ReadType.NBT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleShowItem(final UserConnection connection, final CompoundTag componentsTag) {
|
||||
final CompoundTag attributeModifiers = TagUtil.getNamespacedCompoundTag(componentsTag, "attribute_modifiers");
|
||||
if (attributeModifiers != null) {
|
||||
final ListTag<CompoundTag> modifiers = attributeModifiers.getListTag("modifiers", CompoundTag.class);
|
||||
for (final CompoundTag modifier : modifiers) {
|
||||
final String id = modifier.getString("id");
|
||||
final UUID uuid = Protocol1_20_5To1_21.mapAttributeId(id);
|
||||
final String name = AttributeModifierMappings1_21.idToName(id);
|
||||
modifier.put("uuid", new IntArrayTag(UUIDUtil.toIntArray(uuid)));
|
||||
modifier.putString("name", name != null ? name : id);
|
||||
}
|
||||
}
|
||||
|
||||
TagUtil.removeNamespaced(componentsTag, "jukebox_playable");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SerializerVersion inputSerializerVersion() {
|
||||
return SerializerVersion.V1_20_5;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SerializerVersion outputSerializerVersion() {
|
||||
return SerializerVersion.V1_20_5;
|
||||
}
|
||||
}
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.v1_21to1_20_5.rewriter;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viabackwards.api.rewriters.EntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.Protocol1_21To1_20_5;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage.EnchantmentsPaintingsStorage;
|
||||
import com.viaversion.viaversion.api.minecraft.Holder;
|
||||
import com.viaversion.viaversion.api.minecraft.PaintingVariant;
|
||||
import com.viaversion.viaversion.api.minecraft.RegistryEntry;
|
||||
import com.viaversion.viaversion.api.minecraft.WolfVariant;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.data.Paintings1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import com.viaversion.viaversion.util.KeyMappings;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class EntityPacketRewriter1_21 extends EntityRewriter<ClientboundPacket1_21, Protocol1_21To1_20_5> {
|
||||
|
||||
private final Map<String, PaintingData> oldPaintings = new HashMap<>();
|
||||
|
||||
public EntityPacketRewriter1_21(final Protocol1_21To1_20_5 protocol) {
|
||||
super(protocol, Types1_20_5.ENTITY_DATA_TYPES.optionalComponentType, Types1_20_5.ENTITY_DATA_TYPES.booleanType);
|
||||
|
||||
for (int i = 0; i < Paintings1_20_5.PAINTINGS.length; i++) {
|
||||
final PaintingVariant painting = Paintings1_20_5.PAINTINGS[i];
|
||||
oldPaintings.put(painting.assetId(), new PaintingData(painting, i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPackets() {
|
||||
registerTrackerWithData1_19(ClientboundPackets1_21.ADD_ENTITY, EntityTypes1_20_5.FALLING_BLOCK);
|
||||
registerSetEntityData(ClientboundPackets1_21.SET_ENTITY_DATA, Types1_21.ENTITY_DATA_LIST, Types1_20_5.ENTITY_DATA_LIST);
|
||||
registerRemoveEntities(ClientboundPackets1_21.REMOVE_ENTITIES);
|
||||
|
||||
protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, wrapper -> {
|
||||
final String key = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING));
|
||||
final RegistryEntry[] entries = wrapper.passthrough(Types.REGISTRY_ENTRY_ARRAY);
|
||||
final boolean paintingVariant = key.equals("painting_variant");
|
||||
final boolean enchantment = key.equals("enchantment");
|
||||
if (paintingVariant || enchantment || key.equals("jukebox_song")) {
|
||||
// Track custom registries and cancel the packet
|
||||
final String[] keys = new String[entries.length];
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
keys[i] = Key.stripMinecraftNamespace(entries[i].key());
|
||||
}
|
||||
|
||||
final EnchantmentsPaintingsStorage storage = wrapper.user().get(EnchantmentsPaintingsStorage.class);
|
||||
if (paintingVariant) {
|
||||
storage.setPaintings(new KeyMappings(keys), paintingMappingsForEntries(entries));
|
||||
} else if (enchantment) {
|
||||
final Tag[] descriptions = new Tag[entries.length];
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
final RegistryEntry entry = entries[i];
|
||||
if (entry.tag() != null) {
|
||||
descriptions[i] = ((CompoundTag) entry.tag()).get("description");
|
||||
}
|
||||
}
|
||||
storage.setEnchantments(new KeyMappings(keys), descriptions);
|
||||
} else {
|
||||
final int[] jukeboxSongMappings = new int[keys.length];
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
final int itemId = protocol.getMappingData().getFullItemMappings().mappedId("music_disc_" + keys[i]);
|
||||
jukeboxSongMappings[i] = itemId;
|
||||
}
|
||||
storage.setJubeboxSongsToItems(jukeboxSongMappings);
|
||||
}
|
||||
|
||||
wrapper.cancel();
|
||||
} else {
|
||||
handleRegistryData1_20_5(wrapper.user(), key, entries);
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_21.LOGIN, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.INT); // Entity id
|
||||
map(Types.BOOLEAN); // Hardcore
|
||||
map(Types.STRING_ARRAY); // World List
|
||||
map(Types.VAR_INT); // Max players
|
||||
map(Types.VAR_INT); // View distance
|
||||
map(Types.VAR_INT); // Simulation distance
|
||||
map(Types.BOOLEAN); // Reduced debug info
|
||||
map(Types.BOOLEAN); // Show death screen
|
||||
map(Types.BOOLEAN); // Limited crafting
|
||||
map(Types.VAR_INT); // Dimension key
|
||||
map(Types.STRING); // World
|
||||
handler(worldDataTrackerHandlerByKey1_20_5(3));
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_21.RESPAWN, wrapper -> {
|
||||
final int dimensionId = wrapper.passthrough(Types.VAR_INT);
|
||||
final String world = wrapper.passthrough(Types.STRING);
|
||||
trackWorldDataByKey1_20_5(wrapper.user(), dimensionId, world); // Tracks world height and name for chunk data and entity (un)tracking
|
||||
});
|
||||
}
|
||||
|
||||
private int[] paintingMappingsForEntries(final RegistryEntry[] entries) {
|
||||
final int[] mappings = new int[entries.length];
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
final RegistryEntry entry = entries[i];
|
||||
final PaintingData paintingData = oldPaintings.get(Key.stripMinecraftNamespace(entry.key()));
|
||||
if (paintingData != null) {
|
||||
mappings[i] = paintingData.id;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Figure out which works by size
|
||||
if (entry.tag() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final CompoundTag tag = (CompoundTag) entry.tag();
|
||||
for (int j = 0; j < Paintings1_20_5.PAINTINGS.length; j++) {
|
||||
final PaintingVariant painting = Paintings1_20_5.PAINTINGS[j];
|
||||
if (painting.width() == tag.getInt("width") && painting.height() == tag.getInt("height")) {
|
||||
mappings[i] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
filter().handler((event, data) -> {
|
||||
final EntityDataType type = data.dataType();
|
||||
if (type == Types1_21.ENTITY_DATA_TYPES.wolfVariantType) {
|
||||
final Holder<WolfVariant> variant = data.value();
|
||||
if (variant.hasId()) {
|
||||
data.setTypeAndValue(Types1_20_5.ENTITY_DATA_TYPES.wolfVariantType, variant.id());
|
||||
} else {
|
||||
event.cancel();
|
||||
}
|
||||
} else if (type == Types1_21.ENTITY_DATA_TYPES.paintingVariantType) {
|
||||
final Holder<PaintingVariant> variant = data.value();
|
||||
if (variant.hasId()) {
|
||||
final EnchantmentsPaintingsStorage storage = event.user().get(EnchantmentsPaintingsStorage.class);
|
||||
final int mappedId = storage.mappedPainting(variant.id());
|
||||
data.setTypeAndValue(Types1_20_5.ENTITY_DATA_TYPES.paintingVariantType, mappedId);
|
||||
} else {
|
||||
event.cancel();
|
||||
}
|
||||
} else {
|
||||
data.setDataType(Types1_20_5.ENTITY_DATA_TYPES.byId(type.typeId()));
|
||||
}
|
||||
});
|
||||
registerMetaTypeHandler1_20_3(
|
||||
Types1_20_5.ENTITY_DATA_TYPES.itemType,
|
||||
Types1_20_5.ENTITY_DATA_TYPES.blockStateType,
|
||||
Types1_20_5.ENTITY_DATA_TYPES.optionalBlockStateType,
|
||||
Types1_20_5.ENTITY_DATA_TYPES.particleType,
|
||||
Types1_20_5.ENTITY_DATA_TYPES.particlesType,
|
||||
Types1_20_5.ENTITY_DATA_TYPES.componentType,
|
||||
Types1_20_5.ENTITY_DATA_TYPES.optionalComponentType
|
||||
);
|
||||
registerBlockStateHandler(EntityTypes1_20_5.ABSTRACT_MINECART, 11);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType typeFromId(final int type) {
|
||||
return EntityTypes1_20_5.getTypeFromId(type);
|
||||
}
|
||||
|
||||
private record PaintingData(PaintingVariant painting, int id) {
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage;
|
||||
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.util.KeyMappings;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class EnchantmentsPaintingsStorage implements StorableObject {
|
||||
private KeyMappings enchantments;
|
||||
private KeyMappings paintings;
|
||||
private int[] paintingMappings;
|
||||
private Tag[] enchantmentDescriptions;
|
||||
private int[] jubeboxSongsToItems;
|
||||
|
||||
public KeyMappings enchantments() {
|
||||
return enchantments;
|
||||
}
|
||||
|
||||
public void setEnchantments(final KeyMappings enchantment, final Tag[] enchantmentDescriptions) {
|
||||
this.enchantments = enchantment;
|
||||
this.enchantmentDescriptions = enchantmentDescriptions;
|
||||
}
|
||||
|
||||
public KeyMappings paintings() {
|
||||
return paintings;
|
||||
}
|
||||
|
||||
public void setPaintings(final KeyMappings paintings, final int[] paintingMappings) {
|
||||
this.paintings = paintings;
|
||||
this.paintingMappings = paintingMappings;
|
||||
}
|
||||
|
||||
public void setJubeboxSongsToItems(final int[] jubeboxSongsToItems) {
|
||||
this.jubeboxSongsToItems = jubeboxSongsToItems;
|
||||
}
|
||||
|
||||
public int jubeboxSongToItem(final int id) {
|
||||
return id >= 0 && id < jubeboxSongsToItems.length ? jubeboxSongsToItems[id] : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearOnServerSwitch() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int mappedPainting(final int id) {
|
||||
return id > 0 && id < paintingMappings.length ? paintingMappings[id] : 0;
|
||||
}
|
||||
|
||||
public @Nullable Tag enchantmentDescription(final int id) {
|
||||
return id > 0 && id < enchantmentDescriptions.length ? enchantmentDescriptions[id] : null;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -1,4 +1,106 @@
|
||||
{
|
||||
"1.21": {
|
||||
"argument.entity.selector.nearestEntity": "Nearest entity",
|
||||
"attribute.name.generic.burning_time": "Burning Time",
|
||||
"attribute.name.generic.explosion_knockback_resistance": "Explosion Knockback Resistance",
|
||||
"attribute.name.generic.movement_efficiency": "Movement Efficiency",
|
||||
"attribute.name.generic.oxygen_bonus": "Oxygen Bonus",
|
||||
"attribute.name.generic.water_movement_efficiency": "Water Movement Efficiency",
|
||||
"attribute.name.player.mining_efficiency": "Mining Efficiency",
|
||||
"attribute.name.player.sneaking_speed": "Sneaking Speed",
|
||||
"attribute.name.player.submerged_mining_speed": "Submerged Mining Speed",
|
||||
"attribute.name.player.sweeping_damage_ratio": "Sweeping Damage Ratio",
|
||||
"gamerule.entitiesWithPassengersCanUsePortals": "Entities with passengers can use portals",
|
||||
"gamerule.entitiesWithPassengersCanUsePortals.description": "Allow entities with passengers to teleport through nether portals, end portals and end gateways.",
|
||||
"gui.fileDropFailure.detail": "Rejected %d files",
|
||||
"gui.fileDropFailure.title": "Failed to add files",
|
||||
"gui.open_report_dir": "Open Report Directory",
|
||||
"gui.report_to_server": "Report To Server",
|
||||
"item.minecraft.music_disc_creator": "Music Disc",
|
||||
"item.minecraft.music_disc_creator_music_box": "Music Disc",
|
||||
"item.minecraft.music_disc_creator_music_box.desc": "Lena Raine - Creator (Music Box)",
|
||||
"item.minecraft.music_disc_creator.desc": "Lena Raine - Creator",
|
||||
"item.minecraft.music_disc_precipice": "Music Disc",
|
||||
"item.minecraft.music_disc_precipice.desc": "Aaron Cherof - Precipice",
|
||||
"item.modifiers.any": "When equipped:",
|
||||
"item.modifiers.armor": "When worn:",
|
||||
"item.modifiers.hand": "When held:",
|
||||
"jukebox_song.minecraft.5": "Samuel �berg - 5",
|
||||
"jukebox_song.minecraft.11": "C418 - 11",
|
||||
"jukebox_song.minecraft.13": "C418 - 13",
|
||||
"jukebox_song.minecraft.blocks": "C418 - blocks",
|
||||
"jukebox_song.minecraft.cat": "C418 - cat",
|
||||
"jukebox_song.minecraft.chirp": "C418 - chirp",
|
||||
"jukebox_song.minecraft.creator": "Lena Raine - Creator",
|
||||
"jukebox_song.minecraft.creator_music_box": "Lena Raine - Creator (Music Box)",
|
||||
"jukebox_song.minecraft.far": "C418 - far",
|
||||
"jukebox_song.minecraft.mall": "C418 - mall",
|
||||
"jukebox_song.minecraft.mellohi": "C418 - mellohi",
|
||||
"jukebox_song.minecraft.otherside": "Lena Raine - otherside",
|
||||
"jukebox_song.minecraft.pigstep": "Lena Raine - Pigstep",
|
||||
"jukebox_song.minecraft.precipice": "Aaron Cherof - Precipice",
|
||||
"jukebox_song.minecraft.relic": "Aaron Cherof - Relic",
|
||||
"jukebox_song.minecraft.stal": "C418 - stal",
|
||||
"jukebox_song.minecraft.strad": "C418 - strad",
|
||||
"jukebox_song.minecraft.wait": "C418 - wait",
|
||||
"jukebox_song.minecraft.ward": "C418 - ward",
|
||||
"known_server_link.report_bug": "Report Server Bug",
|
||||
"mco.compatibility.incompatible.popup.title": "Incompatible version",
|
||||
"mco.compatibility.incompatible.releaseType.popup.message": "The world you are trying to join is incompatible with the version you are on.",
|
||||
"mco.compatibility.incompatible.series.popup.message": "This world was last played in version %s; you are on version %s.\n\nThese series are not compatible with each other. A new world is needed to play on this version.",
|
||||
"mco.compatibility.upgrade.friend.description": "This world was last played in version %s; you are on version %s.\n\nA backup of the world will be saved under \"World Backups\".\n\nThe owner of the Realm can restore the world if needed.",
|
||||
"mco.configure.world.resourcepack.question": "You need a custom resource pack to play on this realm\n\nDo you want to download it and play?",
|
||||
"mco.download.confirmation.oversized": "The world you are going to download is larger than %s\n\nYou won't be able to upload this world to your realm again",
|
||||
"mco.onlinePlayers": "Online Players",
|
||||
"menu.feedback": "Feedback...",
|
||||
"menu.feedback.title": "Feedback",
|
||||
"menu.server_links": "Server Links...",
|
||||
"menu.server_links.title": "Server Links",
|
||||
"options.realmsNotifications.tooltip": "Fetches Realms news and invites in the title screen and displays their respective icon on the Realms button.",
|
||||
"painting.minecraft.backyard.author": "Kristoffer Zetterstrand",
|
||||
"painting.minecraft.backyard.title": "Backyard",
|
||||
"painting.minecraft.baroque.author": "Sarah Boeving",
|
||||
"painting.minecraft.baroque.title": "Baroque",
|
||||
"painting.minecraft.bouquet.author": "Kristoffer Zetterstrand",
|
||||
"painting.minecraft.bouquet.title": "Bouquet",
|
||||
"painting.minecraft.cavebird.author": "Kristoffer Zetterstrand",
|
||||
"painting.minecraft.cavebird.title": "Cavebird",
|
||||
"painting.minecraft.changing.author": "Kristoffer Zetterstrand",
|
||||
"painting.minecraft.changing.title": "Changing",
|
||||
"painting.minecraft.cotan.author": "Kristoffer Zetterstrand",
|
||||
"painting.minecraft.cotan.title": "Cot�n",
|
||||
"painting.minecraft.endboss.author": "Kristoffer Zetterstrand",
|
||||
"painting.minecraft.endboss.title": "Endboss",
|
||||
"painting.minecraft.fern.author": "Kristoffer Zetterstrand",
|
||||
"painting.minecraft.fern.title": "Fern",
|
||||
"painting.minecraft.finding.author": "Kristoffer Zetterstrand",
|
||||
"painting.minecraft.finding.title": "Finding",
|
||||
"painting.minecraft.humble.author": "Sarah Boeving",
|
||||
"painting.minecraft.humble.title": "Humble",
|
||||
"painting.minecraft.lowmist.author": "Kristoffer Zetterstrand",
|
||||
"painting.minecraft.lowmist.title": "Lowmist",
|
||||
"painting.minecraft.meditative.author": "Sarah Boeving",
|
||||
"painting.minecraft.meditative.title": "Meditative",
|
||||
"painting.minecraft.orb.author": "Kristoffer Zetterstrand",
|
||||
"painting.minecraft.orb.title": "Orb",
|
||||
"painting.minecraft.owlemons.author": "Kristoffer Zetterstrand",
|
||||
"painting.minecraft.owlemons.title": "Owlemons",
|
||||
"painting.minecraft.passage.author": "Kristoffer Zetterstrand",
|
||||
"painting.minecraft.passage.title": "Passage",
|
||||
"painting.minecraft.pond.author": "Kristoffer Zetterstrand",
|
||||
"painting.minecraft.pond.title": "Pond",
|
||||
"painting.minecraft.prairie_ride.author": "Sarah Boeving",
|
||||
"painting.minecraft.prairie_ride.title": "Prairie Ride",
|
||||
"painting.minecraft.sunflowers.author": "Kristoffer Zetterstrand",
|
||||
"painting.minecraft.sunflowers.title": "Sunflowers",
|
||||
"painting.minecraft.tides.author": "Kristoffer Zetterstrand",
|
||||
"painting.minecraft.tides.title": "Tides",
|
||||
"painting.minecraft.unpacked.author": "Sarah Boeving",
|
||||
"painting.minecraft.unpacked.title": "Unpacked",
|
||||
"subtitles.block.trial_spawner.ambient_ominous": "Ominous crackling",
|
||||
"subtitles.block.trial_spawner.ominous_activate": "Omen engulfs Trial Spawner",
|
||||
"subtitles.block.vault.reject_rewarded_player": "Vault rejects already rewarded player"
|
||||
},
|
||||
"1.20.5": {
|
||||
"advancements.adventure.blowback.description": "Kill a Breeze with a deflected Breeze-shot Wind Charge",
|
||||
"advancements.adventure.blowback.title": "Blowback",
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
projectVersion=5.0.0-SNAPSHOT
|
||||
projectVersion=5.0.0
|
||||
|
||||
# Smile emoji
|
||||
mcVersions=1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10
|
||||
mcVersionRange=1.10-1.20.6
|
||||
mcVersions=1.21,1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10
|
||||
mcVersionRange=1.10-1.21
|
||||
waterfallVersion=1.20
|
||||
velocityVersion=3.3
|
||||
@@ -3,7 +3,7 @@ metadata.format.version = "1.1"
|
||||
[versions]
|
||||
|
||||
# ViaVersion
|
||||
viaver = "5.0.0-SNAPSHOT"
|
||||
viaver = "5.0.0"
|
||||
|
||||
# Common provided
|
||||
netty = "4.0.20.Final"
|
||||
|
||||
@@ -4,6 +4,7 @@ rootProject.name = "viabackwards-parent"
|
||||
|
||||
dependencyResolutionManagement {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
maven("https://repo.viaversion.com")
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
mavenCentral()
|
||||
|
||||
+17
-3
@@ -25,16 +25,22 @@ import com.viaversion.viabackwards.template.protocol.rewriter.BlockItemPacketRew
|
||||
import com.viaversion.viabackwards.template.protocol.rewriter.EntityPacketRewriter1_99;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
|
||||
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
|
||||
import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.Protocol1_20_3To1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundConfigurationPackets1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPacket1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundConfigurationPackets1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter.ReadType;
|
||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
|
||||
import static com.viaversion.viaversion.util.ProtocolUtil.packetTypeMap;
|
||||
|
||||
// Placeholders to replace (in the entire package):
|
||||
// Protocol1_98To_99, EntityPacketRewriter1_99, BlockItemPacketRewriter1_99
|
||||
// Protocol1_20_5To1_20_3 (the ViaVersion protocol class the mappings depend on)
|
||||
@@ -70,7 +76,7 @@ public final class Protocol1_98To1_99 extends BackwardsProtocol<ClientboundPacke
|
||||
soundRewriter.registerStopSound(ClientboundPackets1_20_5.STOP_SOUND);
|
||||
|
||||
new StatisticsRewriter<>(this).register(ClientboundPackets1_20_5.AWARD_STATS);
|
||||
//new AttributeRewriter<>(this).register1_20_5(ClientboundPackets1_20_5.ENTITY_PROPERTIES);
|
||||
//new AttributeRewriter<>(this).register1_21(ClientboundPackets1_20_5.ENTITY_PROPERTIES);
|
||||
|
||||
// Registers translatable mappings (missing a whole bunch still)
|
||||
//translatableRewriter.registerOpenWindow(ClientboundPackets1_20_5.OPEN_WINDOW); // Handled by registerOpenWindow in item rewriters
|
||||
@@ -107,7 +113,7 @@ public final class Protocol1_98To1_99 extends BackwardsProtocol<ClientboundPacke
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableRewriter<ClientboundPacket1_20_5> getTranslatableRewriter() {
|
||||
public TranslatableRewriter<ClientboundPacket1_20_5> getComponentRewriter() {
|
||||
return translatableRewriter;
|
||||
}
|
||||
|
||||
@@ -116,5 +122,13 @@ public final class Protocol1_98To1_99 extends BackwardsProtocol<ClientboundPacke
|
||||
return tagRewriter;
|
||||
}
|
||||
|
||||
// createPacketTypesProvider
|
||||
@Override
|
||||
protected PacketTypesProvider<ClientboundPacket1_20_5, ClientboundPacket1_20_5, ServerboundPacket1_20_5, ServerboundPacket1_20_5> createPacketTypesProvider() {
|
||||
return new SimplePacketTypesProvider<>(
|
||||
packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_20_5.class, ClientboundConfigurationPackets1_20_5.class),
|
||||
packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_20_5.class, ClientboundConfigurationPackets1_20_5.class),
|
||||
packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class),
|
||||
packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class)
|
||||
);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -43,7 +43,7 @@ public final class BlockItemPacketRewriter1_99 extends BackwardsStructuredItemRe
|
||||
blockRewriter.registerBlockEvent(ClientboundPackets1_20_5.BLOCK_EVENT);
|
||||
blockRewriter.registerBlockUpdate(ClientboundPackets1_20_5.BLOCK_UPDATE);
|
||||
blockRewriter.registerSectionBlocksUpdate1_20(ClientboundPackets1_20_5.SECTION_BLOCKS_UPDATE);
|
||||
blockRewriter.registerLevelEvent(ClientboundPackets1_20_5.LEVEL_EVENT, 1010, 2001);
|
||||
blockRewriter.registerLevelEvent1_21(ClientboundPackets1_20_5.LEVEL_EVENT, 2001);
|
||||
blockRewriter.registerLevelChunk1_19(ClientboundPackets1_20_5.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_20_2::new);
|
||||
blockRewriter.registerBlockEntityData(ClientboundPackets1_20_5.BLOCK_ENTITY_DATA);
|
||||
|
||||
|
||||
+15
-19
@@ -19,15 +19,16 @@ package com.viaversion.viabackwards.template.protocol.rewriter;
|
||||
|
||||
import com.viaversion.viabackwards.api.rewriters.EntityRewriter;
|
||||
import com.viaversion.viabackwards.template.protocol.Protocol1_98To1_99;
|
||||
import com.viaversion.viaversion.api.minecraft.RegistryEntry;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundConfigurationPackets1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPacket1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
|
||||
// Replace if needed
|
||||
// Types1_OLD
|
||||
@@ -45,13 +46,10 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPa
|
||||
registerRemoveEntities(ClientboundPackets1_20_5.REMOVE_ENTITIES);
|
||||
|
||||
// TODO Item and sound id changes in registries, probably others as well
|
||||
protocol.registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_5.REGISTRY_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
protected void register() {
|
||||
map(Types.STRING); // Registry
|
||||
map(Types.REGISTRY_ENTRY_ARRAY); // Data
|
||||
handler(registryDataHandler1_20_5()); // Caches dimensions to access data like height later and tracks the amount of biomes sent for chunk data
|
||||
}
|
||||
protocol.registerClientbound(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA, wrapper -> {
|
||||
final String registryKey = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING));
|
||||
final RegistryEntry[] entries = wrapper.passthrough(Types.REGISTRY_ENTRY_ARRAY);
|
||||
handleRegistryData1_20_5(wrapper.user(), registryKey, entries); // Caches dimensions to access data like height later and tracks the amount of biomes sent for chunk data
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_20_5.LOGIN, new PacketHandlers() {
|
||||
@@ -72,27 +70,24 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPa
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_20_5.RESPAWN, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT); // Dimension
|
||||
map(Types.STRING); // World
|
||||
handler(worldDataTrackerHandlerByKey1_20_5(0)); // Tracks world height and name for chunk data and entity (un)tracking
|
||||
}
|
||||
protocol.registerClientbound(ClientboundPackets1_20_5.RESPAWN, wrapper -> {
|
||||
final int dimensionId = wrapper.passthrough(Types.VAR_INT);
|
||||
final String world = wrapper.passthrough(Types.STRING);
|
||||
trackWorldDataByKey1_20_5(wrapper.user(), dimensionId, world); // Tracks world height and name for chunk data and entity (un)tracking
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
/*filter().handler((event, meta) -> {
|
||||
int id = meta.metaType().typeId();
|
||||
/*filter().handler((event, data) -> {
|
||||
int id = data.dataType().typeId();
|
||||
if (id >= ac) {
|
||||
return;
|
||||
} else if (id >= ab) {
|
||||
id--;
|
||||
}
|
||||
|
||||
meta.setMetaType(Types1_20_5.META_TYPES.byId(id));
|
||||
data.setDataType(Types1_20_5.ENTITY_DATA_TYPES.byId(id));
|
||||
});*/
|
||||
|
||||
registerMetaTypeHandler1_20_3(
|
||||
@@ -100,7 +95,8 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPa
|
||||
Types1_20_5.ENTITY_DATA_TYPES.blockStateType,
|
||||
Types1_20_5.ENTITY_DATA_TYPES.optionalBlockStateType,
|
||||
Types1_20_5.ENTITY_DATA_TYPES.particleType,
|
||||
null, Types1_20_5.ENTITY_DATA_TYPES.componentType,
|
||||
Types1_20_5.ENTITY_DATA_TYPES.particlesType,
|
||||
Types1_20_5.ENTITY_DATA_TYPES.componentType,
|
||||
Types1_20_5.ENTITY_DATA_TYPES.optionalComponentType
|
||||
);
|
||||
registerBlockStateHandler(EntityTypes1_20_5.ABSTRACT_MINECART, 11);
|
||||
|
||||
Reference in new issue
Block a user