Use VV 1.11 EntityIdRewriter

This commit is contained in:
KennyTV 2020-02-05 20:38:03 +01:00
parent c560373be3
commit 0f1f9328ae
2 changed files with 7 additions and 154 deletions

View File

@ -1,150 +0,0 @@
/*
* Copyright (c) 2016 Matsv
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package nl.matsv.viabackwards.protocol.protocol1_10to1_11;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.Tag;
/*
Copied from ViaVersion
*/
public class EntityTypeNames {
private static final BiMap<String, String> NEW_TO_OLD_NAMES = HashBiMap.create();
static {
add("AreaEffectCloud", "minecraft:area_effect_cloud");
add("ArmorStand", "minecraft:armor_stand");
add("Arrow", "minecraft:arrow");
add("Bat", "minecraft:bat");
add("Blaze", "minecraft:blaze");
add("Boat", "minecraft:boat");
add("CaveSpider", "minecraft:cave_spider");
add("Chicken", "minecraft:chicken");
add("Cow", "minecraft:cow");
add("Creeper", "minecraft:creeper");
add("Donkey", "minecraft:donkey");
add("DragonFireball", "minecraft:dragon_fireball");
add("ElderGuardian", "minecraft:elder_guardian");
add("EnderCrystal", "minecraft:ender_crystal");
add("EnderDragon", "minecraft:ender_dragon");
add("Enderman", "minecraft:enderman");
add("Endermite", "minecraft:endermite");
add("EntityHorse", "minecraft:horse");
add("EyeOfEnderSignal", "minecraft:eye_of_ender_signal");
add("FallingSand", "minecraft:falling_block");
add("Fireball", "minecraft:fireball");
add("FireworksRocketEntity", "minecraft:fireworks_rocket");
add("Ghast", "minecraft:ghast");
add("Giant", "minecraft:giant");
add("Guardian", "minecraft:guardian");
add("Husk", "minecraft:husk");
add("Item", "minecraft:item");
add("ItemFrame", "minecraft:item_frame");
add("LavaSlime", "minecraft:magma_cube");
add("LeashKnot", "minecraft:leash_knot");
add("MinecartChest", "minecraft:chest_minecart");
add("MinecartCommandBlock", "minecraft:commandblock_minecart");
add("MinecartFurnace", "minecraft:furnace_minecart");
add("MinecartHopper", "minecraft:hopper_minecart");
add("MinecartRideable", "minecraft:minecart");
add("MinecartSpawner", "minecraft:spawner_minecart");
add("MinecartTNT", "minecraft:tnt_minecart");
add("Mule", "minecraft:mule");
add("MushroomCow", "minecraft:mooshroom");
add("Ozelot", "minecraft:ocelot");
add("Painting", "minecraft:painting");
add("Pig", "minecraft:pig");
add("PigZombie", "minecraft:zombie_pigman");
add("PolarBear", "minecraft:polar_bear");
add("PrimedTnt", "minecraft:tnt");
add("Rabbit", "minecraft:rabbit");
add("Sheep", "minecraft:sheep");
add("Shulker", "minecraft:shulker");
add("ShulkerBullet", "minecraft:shulker_bullet");
add("Silverfish", "minecraft:silverfish");
add("Skeleton", "minecraft:skeleton");
add("SkeletonHorse", "minecraft:skeleton_horse");
add("Slime", "minecraft:slime");
add("SmallFireball", "minecraft:small_fireball");
add("Snowball", "minecraft:snowball");
add("SnowMan", "minecraft:snowman");
add("SpectralArrow", "minecraft:spectral_arrow");
add("Spider", "minecraft:spider");
add("Squid", "minecraft:squid");
add("Stray", "minecraft:stray");
add("ThrownEgg", "minecraft:egg");
add("ThrownEnderpearl", "minecraft:ender_pearl");
add("ThrownExpBottle", "minecraft:xp_bottle");
add("ThrownPotion", "minecraft:potion");
add("Villager", "minecraft:villager");
add("VillagerGolem", "minecraft:villager_golem");
add("Witch", "minecraft:witch");
add("WitherBoss", "minecraft:wither");
add("WitherSkeleton", "minecraft:wither_skeleton");
add("WitherSkull", "minecraft:wither_skull");
add("Wolf", "minecraft:wolf");
add("XPOrb", "minecraft:xp_orb");
add("Zombie", "minecraft:zombie");
add("ZombieHorse", "minecraft:zombie_horse");
add("ZombieVillager", "minecraft:zombie_villager");
}
// Other way around (-:
private static void add(String oldName, String newName) {
NEW_TO_OLD_NAMES.put(newName, oldName);
}
public static void toClient(CompoundTag tag) {
Tag idTag = tag.get("id");
if (idTag instanceof StringTag) {
StringTag id = (StringTag) idTag;
String value = NEW_TO_OLD_NAMES.get(id.getValue());
if (value != null) {
id.setValue(value);
}
}
}
public static void toClientSpawner(CompoundTag tag) {
Tag spawnDataTag;
if (tag != null && (spawnDataTag = tag.get("SpawnData")) != null) {
CompoundTag spawnData = (CompoundTag) spawnDataTag;
if (spawnData != null) {
toClient(spawnData);
}
}
}
public static void toClientItem(Item item) {
if (hasEntityTag(item)) {
CompoundTag entityTag = item.getTag().get("EntityTag");
toClient(entityTag);
}
}
private static boolean hasEntityTag(Item item) {
if (item != null && item.getIdentifier() == 383) { // Monster Egg
CompoundTag tag = item.getTag();
if (tag != null) {
Tag entityTag = tag.get("EntityTag");
if (entityTag instanceof CompoundTag) {
return ((CompoundTag) entityTag).get("id") instanceof StringTag;
}
}
}
return false;
}
}

View File

@ -15,7 +15,6 @@ import nl.matsv.viabackwards.api.data.MappedLegacyBlockItem;
import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.api.rewriters.LegacyBlockItemRewriter;
import nl.matsv.viabackwards.api.rewriters.LegacyEnchantmentRewriter;
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.EntityTypeNames;
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11;
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage;
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.storage.WindowTracker;
@ -31,6 +30,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_11to1_10.EntityIdRewriter;
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
@ -268,7 +268,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
// Handler Spawners
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 1) {
CompoundTag tag = wrapper.get(Type.NBT, 0);
EntityTypeNames.toClientSpawner(tag);
EntityIdRewriter.toClientSpawner(tag, true);
}
}
});
@ -354,7 +354,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
// Handle spawner block entity (map to itself with custom handler)
MappedLegacyBlockItem data = replacementData.computeIfAbsent(52, s -> new MappedLegacyBlockItem(52, (short) -1, null, false));
data.setBlockEntityHandler((b, tag) -> {
EntityTypeNames.toClientSpawner(tag);
EntityIdRewriter.toClientSpawner(tag, true);
return tag;
});
@ -374,7 +374,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
if (tag == null) return item;
// Rewrite spawn eggs (id checks are done in the method itself)
EntityTypeNames.toClientItem(item);
EntityIdRewriter.toClientItem(item, true);
if (tag.get("ench") instanceof ListTag) {
enchantmentRewriter.rewriteEnchantmentsToClient(tag, false);
@ -393,6 +393,9 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
CompoundTag tag = item.getTag();
if (tag == null) return item;
// Rewrite spawn eggs (id checks are done in the method itself)
EntityIdRewriter.toServerItem(item, true);
if (tag.contains(nbtTagName + "|ench")) {
enchantmentRewriter.rewriteEnchantmentsToServer(tag, false);
}