3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 00:22:51 +01:00

Do not create unnecessary tag

Dieser Commit ist enthalten in:
creeper123123321 2018-07-17 17:40:39 -03:00
Ursprung 7cd1563805
Commit 6d996a93c8
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 0AC57D54786721D1
3 geänderte Dateien mit 50 neuen und 50 gelöschten Zeilen

Datei anzeigen

@ -15,8 +15,7 @@ import java.util.Map;
public class MappingData { public class MappingData {
public static Map<Integer, Integer> oldToNewBlocks = new HashMap<>(); public static Map<Integer, Integer> oldToNewBlocks = new HashMap<>();
public static Map<Integer, Integer> oldToNewItems = new HashMap<>(); public static BiMap<Integer, Integer> oldToNewItems = HashBiMap.create();
public static Map<Integer, Integer> newToOldItems = new HashMap<>();
public static Map<String, Integer[]> blockTags = new HashMap<>(); public static Map<String, Integer[]> blockTags = new HashMap<>();
public static Map<String, Integer[]> itemTags = new HashMap<>(); public static Map<String, Integer[]> itemTags = new HashMap<>();
public static Map<String, Integer[]> fluidTags = new HashMap<>(); public static Map<String, Integer[]> fluidTags = new HashMap<>();
@ -32,8 +31,6 @@ public class MappingData {
mapIdentifiers(oldToNewBlocks, mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks")); mapIdentifiers(oldToNewBlocks, mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks"));
System.out.println("Loading item mapping..."); System.out.println("Loading item mapping...");
mapIdentifiers(oldToNewItems, mapping1_12.getAsJsonObject("items"), mapping1_13.getAsJsonObject("items")); mapIdentifiers(oldToNewItems, mapping1_12.getAsJsonObject("items"), mapping1_13.getAsJsonObject("items"));
System.out.println("Loading new to old item mapping...");
mapIdentifiers(newToOldItems, mapping1_13.getAsJsonObject("items"), mapping1_12.getAsJsonObject("items"));
System.out.println("Loading new tags..."); System.out.println("Loading new tags...");
loadTags(blockTags, mapping1_13.getAsJsonObject("block_tags")); loadTags(blockTags, mapping1_13.getAsJsonObject("block_tags"));
loadTags(itemTags, mapping1_13.getAsJsonObject("item_tags")); loadTags(itemTags, mapping1_13.getAsJsonObject("item_tags"));

Datei anzeigen

@ -263,66 +263,63 @@ public class InventoryPackets {
// TODO Rewrite identifiers // TODO Rewrite identifiers
public static void toClient(Item item) { public static void toClient(Item item) {
if (item == null) return; if (item == null) return;
// create tag
CompoundTag tag = item.getTag(); CompoundTag tag = item.getTag();
if (tag == null) {
item.setTag(tag = new CompoundTag("tag"));
}
// Save original id // Save original id
int originalId = (item.getId() << 16 | item.getData() & 0xFFFF); int originalId = (item.getId() << 16 | item.getData() & 0xFFFF);
tag.put(new IntTag(NBT_TAG_NAME, originalId));
// NBT changes // NBT Additions
if (isDamageable(item.getId())) { if (isDamageable(item.getId())) {
if (tag == null) item.setTag(tag = new CompoundTag("tag"));
tag.put(new IntTag("Damage", item.getData())); tag.put(new IntTag("Damage", item.getData()));
} }
if (item.getId() == 358) { // map if (item.getId() == 358) { // map
if (tag == null) item.setTag(tag = new CompoundTag("tag"));
tag.put(new IntTag("map", item.getData())); tag.put(new IntTag("map", item.getData()));
} }
if (item.getId() == 442) { // shield // NBT Changes
if (tag.get("BlockEntityTag") instanceof CompoundTag) { if (tag != null) {
CompoundTag blockEntityTag = tag.get("BlockEntityTag"); // Invert shield color id
if (blockEntityTag.get("Base") instanceof IntTag) { if (item.getId() == 442) {
IntTag base = blockEntityTag.get("Base"); if (tag.get("BlockEntityTag") instanceof CompoundTag) {
base.setValue(15 - base.getValue()); // invert color id CompoundTag blockEntityTag = tag.get("BlockEntityTag");
if (blockEntityTag.get("Base") instanceof IntTag) {
IntTag base = blockEntityTag.get("Base");
base.setValue(15 - base.getValue());
}
} }
} }
} // Display Name now uses JSON
if (tag.get("display") instanceof CompoundTag) {
// Display Name now uses JSON if (((CompoundTag) tag.get("display")).get("Name") instanceof StringTag) {
if (tag.get("display") instanceof CompoundTag) { StringTag name = ((CompoundTag) tag.get("display")).get("Name");
if (((CompoundTag) tag.get("display")).get("Name") instanceof StringTag) { name.setValue(
StringTag name = ((CompoundTag) tag.get("display")).get("Name"); ProtocolSnapshotTo1_12_2.legacyTextToJson(
name.setValue( name.getValue()
ProtocolSnapshotTo1_12_2.legacyTextToJson(
name.getValue()
)
);
}
}
// ench is now Enchantments and now uses identifiers
if (tag.get("ench") instanceof ListTag) {
ListTag ench = tag.get("ench");
ListTag enchantments = new ListTag("Enchantments", CompoundTag.class);
for (Tag enchEntry : ench) {
if (enchEntry instanceof CompoundTag) {
CompoundTag enchantmentEntry = new CompoundTag("");
enchantmentEntry.put(new StringTag("id",
MappingData.oldEnchantmentsIds.get(
(Short) ((CompoundTag) enchEntry).get("id").getValue()
) )
)); );
enchantmentEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchEntry).get("lvl").getValue()));
enchantments.add(enchantmentEntry);
} }
} }
tag.remove("ench"); // ench is now Enchantments and now uses identifiers
tag.put(enchantments); if (tag.get("ench") instanceof ListTag) {
ListTag ench = tag.get("ench");
ListTag enchantments = new ListTag("Enchantments", CompoundTag.class);
for (Tag enchEntry : ench) {
if (enchEntry instanceof CompoundTag) {
CompoundTag enchantmentEntry = new CompoundTag("");
enchantmentEntry.put(new StringTag("id",
MappingData.oldEnchantmentsIds.get(
(short) ((CompoundTag) enchEntry).get("id").getValue()
)
));
enchantmentEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchEntry).get("lvl").getValue()));
enchantments.add(enchantmentEntry);
}
}
tag.remove("ench");
tag.put(enchantments);
}
} }
int rawId = (item.getId() << 4 | item.getData() & 0xF); int rawId = (item.getId() << 4 | item.getData() & 0xF);
@ -345,7 +342,13 @@ public class InventoryPackets {
} }
if (!MappingData.oldToNewItems.containsKey(rawId)) { if (!MappingData.oldToNewItems.containsKey(rawId)) {
if (MappingData.oldToNewItems.containsKey(rawId & ~0xF)) { if (!isDamageable(item.getId()) && item.getId() != 358) { // Map
if (tag == null) item.setTag(tag = new CompoundTag("tag"));
tag.put(new IntTag(NBT_TAG_NAME, originalId)); // Data will be lost, saving original id
}
if (item.getId() == 31 && item.getData() == 0) { // Shrub was removed
rawId = MappingData.oldToNewItems.get(512); // Dead Bush
} else if (MappingData.oldToNewItems.containsKey(rawId & ~0xF)) {
rawId &= ~0xF; // Remove data rawId &= ~0xF; // Remove data
} else { } else {
System.out.println("FAILED TO GET 1.13 ITEM FOR " + item.getId()); // TODO: Make this nicer etc, perhaps fix issues with mapping :T System.out.println("FAILED TO GET 1.13 ITEM FOR " + item.getId()); // TODO: Make this nicer etc, perhaps fix issues with mapping :T
@ -378,7 +381,7 @@ public class InventoryPackets {
} }
if (rawId == null) { if (rawId == null) {
Integer oldId = MappingData.newToOldItems.get((int) item.getId()); Integer oldId = MappingData.oldToNewItems.inverse().get((int) item.getId());
if (oldId != null) { if (oldId != null) {
// Handle spawn eggs // Handle spawn eggs
Optional<String> eggEntityId = SpawnEggRewriter.getEntityId(oldId); Optional<String> eggEntityId = SpawnEggRewriter.getEntityId(oldId);

Datei anzeigen

@ -204,7 +204,7 @@
"476": "minecraft:sticky_piston[extended=true,facing=west]", "476": "minecraft:sticky_piston[extended=true,facing=west]",
"477": "minecraft:sticky_piston[extended=true,facing=east]", "477": "minecraft:sticky_piston[extended=true,facing=east]",
"480": "minecraft:cobweb", "480": "minecraft:cobweb",
"496": "minecraft:dead_bush", //"496": "minecraft:dead_bush", RIP Dead Bush
"497": "minecraft:grass", "497": "minecraft:grass",
"498": "minecraft:fern", "498": "minecraft:fern",
"512": "minecraft:dead_bush", "512": "minecraft:dead_bush",