3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-08 17:20:24 +01:00

Rewrite item nbt attributes

Dieser Commit ist enthalten in:
KennyTV 2020-07-02 15:57:34 +02:00
Ursprung 4f392ba361
Commit 5ce1e850c8
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
4 geänderte Dateien mit 66 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -50,7 +50,7 @@ public class Protocol1_16_2To1_16_1 extends Protocol<ClientboundPackets1_16, Cli
boolean open = wrapper.read(Type.BOOLEAN); boolean open = wrapper.read(Type.BOOLEAN);
boolean filter = wrapper.read(Type.BOOLEAN); boolean filter = wrapper.read(Type.BOOLEAN);
wrapper.write(Type.VAR_INT, 1); // Settings wrapper.write(Type.VAR_INT, 1); // Settings
wrapper.write(Type.BOOLEAN, open); wrapper.write(Type.BOOLEAN, recipeType == 0); // Crafting
wrapper.write(Type.BOOLEAN, filter); wrapper.write(Type.BOOLEAN, filter);
wrapper.write(Type.BOOLEAN, recipeType == 1); // Furnace wrapper.write(Type.BOOLEAN, recipeType == 1); // Furnace
wrapper.write(Type.BOOLEAN, filter); wrapper.write(Type.BOOLEAN, filter);

Datei anzeigen

@ -6,9 +6,9 @@ import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_14; import us.myles.ViaVersion.api.type.types.version.Types1_14;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1; import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.metadata.MetadataRewriter1_16_2To1_16_1; import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.metadata.MetadataRewriter1_16_2To1_16_1;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.storage.EntityTracker1_16_2;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.storage.EntityTracker1_16;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class EntityPackets { public class EntityPackets {
@ -28,9 +28,9 @@ public class EntityPackets {
map(Type.INT); // Entity ID map(Type.INT); // Entity ID
handler(wrapper -> { handler(wrapper -> {
short gamemode = wrapper.read(Type.UNSIGNED_BYTE); short gamemode = wrapper.read(Type.UNSIGNED_BYTE);
boolean hardcore = (gamemode & 0x08) != 0; wrapper.write(Type.BOOLEAN, (gamemode & 0x08) != 0); // Hardcore
gamemode &= ~0x08; gamemode &= ~0x08;
wrapper.write(Type.BOOLEAN, hardcore); // Hardcore
wrapper.write(Type.UNSIGNED_BYTE, gamemode); wrapper.write(Type.UNSIGNED_BYTE, gamemode);
}); });
map(Type.BYTE); // Previous Gamemode map(Type.BYTE); // Previous Gamemode
@ -45,7 +45,7 @@ public class EntityPackets {
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class); ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
String dimension = wrapper.get(Type.STRING, 0); String dimension = wrapper.get(Type.STRING, 0);
clientChunks.setEnvironment(dimension); clientChunks.setEnvironment(dimension);
wrapper.user().get(EntityTracker1_16.class).addEntity(wrapper.get(Type.INT, 0), Entity1_16_2Types.EntityType.PLAYER); wrapper.user().get(EntityTracker1_16_2.class).addEntity(wrapper.get(Type.INT, 0), Entity1_16_2Types.EntityType.PLAYER);
}); });
} }
}); });

Datei anzeigen

@ -1,17 +1,16 @@
package us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data; package us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.Mappings; import us.myles.ViaVersion.api.data.Mappings;
import us.myles.ViaVersion.util.Int2IntBiMap; import us.myles.ViaVersion.util.Int2IntBiMap;
import java.util.HashMap;
import java.util.Map;
public class MappingData { public class MappingData {
public static Int2IntBiMap oldToNewItems = new Int2IntBiMap(); public static Int2IntBiMap oldToNewItems = new Int2IntBiMap();
public static Map<String, String> attributeMappings = new HashMap<>(); public static BiMap<String, String> attributeMappings = HashBiMap.create();
public static Mappings blockMappings; public static Mappings blockMappings;
public static Mappings blockStateMappings; public static Mappings blockStateMappings;
public static Mappings soundMappings; public static Mappings soundMappings;

Datei anzeigen

@ -2,6 +2,8 @@ package us.myles.ViaVersion.protocols.protocol1_16to1_15_2.packets;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag; import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.LongTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag; import com.github.steveice10.opennbt.tag.builtin.Tag;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
@ -105,6 +107,7 @@ public class InventoryPackets {
} }
} }
oldToNewAttributes(item);
item.setIdentifier(getNewItemId(item.getIdentifier())); item.setIdentifier(getNewItemId(item.getIdentifier()));
} }
@ -125,6 +128,61 @@ public class InventoryPackets {
} }
} }
} }
newToOldAttributes(item);
}
public static void oldToNewAttributes(Item item) {
if (item.getTag() == null) return;
ListTag attributes = item.getTag().get("AttributeModifiers");
if (attributes == null) return;
for (Tag tag : attributes) {
CompoundTag attribute = (CompoundTag) tag;
rewriteAttributeName(attribute, "AttributeName", false);
rewriteAttributeName(attribute, "Name", false);
Tag leastTag = attribute.get("UUIDLeast");
if (leastTag != null) {
Tag mostTag = attribute.get("UUIDMost");
int[] uuidIntArray = UUIDIntArrayType.bitsToIntArray(((Number) leastTag.getValue()).longValue(), ((Number) mostTag.getValue()).longValue());
attribute.put(new IntArrayTag("UUID", uuidIntArray));
}
}
}
public static void newToOldAttributes(Item item) {
if (item.getTag() == null) return;
ListTag attributes = item.getTag().get("AttributeModifiers");
if (attributes == null) return;
for (Tag tag : attributes) {
CompoundTag attribute = (CompoundTag) tag;
rewriteAttributeName(attribute, "AttributeName", true);
rewriteAttributeName(attribute, "Name", true);
IntArrayTag uuidTag = attribute.get("UUID");
if (uuidTag != null) {
UUID uuid = UUIDIntArrayType.uuidFromIntArray(uuidTag.getValue());
attribute.put(new LongTag("UUIDLeast", uuid.getLeastSignificantBits()));
attribute.put(new LongTag("UUIDMost", uuid.getMostSignificantBits()));
}
}
}
public static void rewriteAttributeName(CompoundTag compoundTag, String entryName, boolean inverse) {
StringTag attributeNameTag = compoundTag.get("AttributeName");
if (attributeNameTag == null) return;
String attributeName = attributeNameTag.getValue();
if (inverse && !attributeName.startsWith("minecraft:")) {
attributeName = "minecraft:" + attributeName;
}
String mappedAttribute = (inverse ? MappingData.attributeMappings.inverse() : MappingData.attributeMappings).get(attributeName);
if (mappedAttribute == null) return;
attributeNameTag.setValue(mappedAttribute);
} }
public static int getNewItemId(int id) { public static int getNewItemId(int id) {