Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-08 17:20:24 +01:00
Do not create unnecessary tag
Dieser Commit ist enthalten in:
Ursprung
7cd1563805
Commit
6d996a93c8
@ -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"));
|
||||||
|
@ -263,36 +263,33 @@ 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 != null) {
|
||||||
|
// Invert shield color id
|
||||||
|
if (item.getId() == 442) {
|
||||||
if (tag.get("BlockEntityTag") instanceof CompoundTag) {
|
if (tag.get("BlockEntityTag") instanceof CompoundTag) {
|
||||||
CompoundTag blockEntityTag = tag.get("BlockEntityTag");
|
CompoundTag blockEntityTag = tag.get("BlockEntityTag");
|
||||||
if (blockEntityTag.get("Base") instanceof IntTag) {
|
if (blockEntityTag.get("Base") instanceof IntTag) {
|
||||||
IntTag base = blockEntityTag.get("Base");
|
IntTag base = blockEntityTag.get("Base");
|
||||||
base.setValue(15 - base.getValue()); // invert color id
|
base.setValue(15 - base.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display Name now uses JSON
|
// Display Name now uses JSON
|
||||||
if (tag.get("display") instanceof CompoundTag) {
|
if (tag.get("display") instanceof CompoundTag) {
|
||||||
if (((CompoundTag) tag.get("display")).get("Name") instanceof StringTag) {
|
if (((CompoundTag) tag.get("display")).get("Name") instanceof StringTag) {
|
||||||
@ -304,7 +301,6 @@ public class InventoryPackets {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ench is now Enchantments and now uses identifiers
|
// ench is now Enchantments and now uses identifiers
|
||||||
if (tag.get("ench") instanceof ListTag) {
|
if (tag.get("ench") instanceof ListTag) {
|
||||||
ListTag ench = tag.get("ench");
|
ListTag ench = tag.get("ench");
|
||||||
@ -314,7 +310,7 @@ public class InventoryPackets {
|
|||||||
CompoundTag enchantmentEntry = new CompoundTag("");
|
CompoundTag enchantmentEntry = new CompoundTag("");
|
||||||
enchantmentEntry.put(new StringTag("id",
|
enchantmentEntry.put(new StringTag("id",
|
||||||
MappingData.oldEnchantmentsIds.get(
|
MappingData.oldEnchantmentsIds.get(
|
||||||
(Short) ((CompoundTag) enchEntry).get("id").getValue()
|
(short) ((CompoundTag) enchEntry).get("id").getValue()
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
enchantmentEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchEntry).get("lvl").getValue()));
|
enchantmentEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchEntry).get("lvl").getValue()));
|
||||||
@ -324,6 +320,7 @@ public class InventoryPackets {
|
|||||||
tag.remove("ench");
|
tag.remove("ench");
|
||||||
tag.put(enchantments);
|
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);
|
||||||
|
@ -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",
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren