From 6de1ba9f30dfc908877dbe2d7f987f90637fc808 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Mon, 8 Jun 2020 22:22:50 +0200 Subject: [PATCH] Move to proper FU usage --- .../viabackwards/api/data/VBItemMappings.java | 8 ++++---- .../api/rewriters/EntityRewriterBase.java | 16 +++++++++++----- .../api/rewriters/LegacyBlockItemRewriter.java | 10 +++++----- .../api/rewriters/LegacySoundRewriter.java | 12 +++++------- .../protocol1_10to1_11/PotionSplashHandler.java | 7 ++++--- .../packets/BlockItemPackets1_11.java | 2 +- .../data/MapColorMapping.java | 7 ++++--- .../block_entity_handlers/FlowerPotHandler.java | 6 +++--- .../data/EntityTypeMapping.java | 13 ++++++++----- .../packets/BlockItemPackets1_13.java | 12 ++++++------ .../storage/BackwardsBlockStorage.java | 7 +++---- .../Protocol1_13_2To1_14.java | 4 ++-- .../packets/BlockItemPackets1_14.java | 8 ++++---- .../Protocol1_14_4To1_15.java | 4 ++-- .../packets/BlockItemPackets1_15.java | 8 ++++---- .../Protocol1_15_2To1_16.java | 6 ++---- .../packets/BlockItemPackets1_16.java | 8 ++++---- 17 files changed, 72 insertions(+), 66 deletions(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/api/data/VBItemMappings.java b/core/src/main/java/nl/matsv/viabackwards/api/data/VBItemMappings.java index 192f1d6b..a8dd67a2 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/data/VBItemMappings.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/data/VBItemMappings.java @@ -4,8 +4,8 @@ import nl.matsv.viabackwards.ViaBackwards; import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.MappingDataLoader; -import us.myles.ViaVersion.util.fastutil.CollectionUtil; -import us.myles.ViaVersion.util.fastutil.IntObjectMap; +import us.myles.viaversion.libs.fastutil.ints.Int2ObjectMap; +import us.myles.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap; import us.myles.viaversion.libs.gson.JsonElement; import us.myles.viaversion.libs.gson.JsonObject; @@ -17,7 +17,7 @@ import java.util.Map; */ public class VBItemMappings { - private final IntObjectMap itemMapping; + private final Int2ObjectMap itemMapping; public VBItemMappings(JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping) { Map itemMapping = new HashMap<>(); @@ -46,7 +46,7 @@ public class VBItemMappings { itemMapping.put(id, new MappedItem(mappedId, name)); } - this.itemMapping = CollectionUtil.createIntObjectMap(itemMapping); + this.itemMapping = new Int2ObjectOpenHashMap<>(itemMapping, 1F); } @Nullable diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriterBase.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriterBase.java index f114f9e4..33618c1a 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriterBase.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriterBase.java @@ -23,8 +23,8 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.exception.CancelException; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -import us.myles.ViaVersion.util.fastutil.CollectionUtil; -import us.myles.ViaVersion.util.fastutil.IntMap; +import us.myles.viaversion.libs.fastutil.ints.Int2IntMap; +import us.myles.viaversion.libs.fastutil.ints.Int2IntOpenHashMap; import java.util.ArrayList; import java.util.Comparator; @@ -45,7 +45,7 @@ public abstract class EntityRewriterBase extends Re private final List metaHandlers = new ArrayList<>(); private final MetaType displayNameMetaType; private final int displayNameIndex; - protected IntMap typeMapping; + protected Int2IntMap typeMapping; EntityRewriterBase(T protocol) { this(protocol, MetaType1_9.String, 2); @@ -101,7 +101,10 @@ public abstract class EntityRewriterBase extends Re * @param new type class */ public & EntityType> void mapTypes(EntityType[] oldTypes, Class newTypeClass) { - if (typeMapping == null) typeMapping = CollectionUtil.createIntMap(oldTypes.length); + if (typeMapping == null) { + typeMapping = new Int2IntOpenHashMap(oldTypes.length, 1F); + typeMapping.defaultReturnValue(-1); + } for (EntityType oldType : oldTypes) { try { T newType = Enum.valueOf(newTypeClass, oldType.name()); @@ -124,7 +127,10 @@ public abstract class EntityRewriterBase extends Re } private void mapEntityDirect(int oldType, int newType) { - if (typeMapping == null) typeMapping = CollectionUtil.createIntMap(); + if (typeMapping == null) { + typeMapping = new Int2IntOpenHashMap(); + typeMapping.defaultReturnValue(-1); + } typeMapping.put(oldType, newType); } diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyBlockItemRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyBlockItemRewriter.java index 983579a4..2c9ff2ab 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyBlockItemRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyBlockItemRewriter.java @@ -22,8 +22,8 @@ import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.rewriters.IdRewriteFunction; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; -import us.myles.ViaVersion.util.fastutil.CollectionUtil; -import us.myles.ViaVersion.util.fastutil.IntObjectMap; +import us.myles.viaversion.libs.fastutil.ints.Int2ObjectMap; +import us.myles.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap; import us.myles.viaversion.libs.gson.JsonElement; import us.myles.viaversion.libs.gson.JsonObject; import us.myles.viaversion.libs.gson.JsonPrimitive; @@ -37,13 +37,13 @@ import java.util.Map; public abstract class LegacyBlockItemRewriter extends ItemRewriterBase { - private static final Map> LEGACY_MAPPINGS = new HashMap<>(); - protected final IntObjectMap replacementData; + private static final Map> LEGACY_MAPPINGS = new HashMap<>(); + protected final Int2ObjectMap replacementData; static { JsonObject jsonObject = VBMappingDataLoader.loadFromDataDir("legacy-mappings.json"); for (Map.Entry entry : jsonObject.entrySet()) { - IntObjectMap mappings = CollectionUtil.createIntObjectMap(8); + Int2ObjectMap mappings = new Int2ObjectOpenHashMap<>(8); LEGACY_MAPPINGS.put(entry.getKey(), mappings); for (Map.Entry dataEntry : entry.getValue().getAsJsonObject().entrySet()) { JsonObject object = dataEntry.getValue().getAsJsonObject(); diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacySoundRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacySoundRewriter.java index 84bc788f..157d03c8 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacySoundRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacySoundRewriter.java @@ -11,13 +11,11 @@ package nl.matsv.viabackwards.api.rewriters; import nl.matsv.viabackwards.api.BackwardsProtocol; -import us.myles.ViaVersion.util.fastutil.CollectionUtil; -import us.myles.ViaVersion.util.fastutil.IntObjectMap; - -import java.util.Map; +import us.myles.viaversion.libs.fastutil.ints.Int2ObjectMap; +import us.myles.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap; public abstract class LegacySoundRewriter extends Rewriter { - protected final IntObjectMap soundRewrites = CollectionUtil.createIntObjectMap(64); + protected final Int2ObjectMap soundRewrites = new Int2ObjectOpenHashMap<>(64); protected LegacySoundRewriter(T protocol) { super(protocol); @@ -44,8 +42,8 @@ public abstract class LegacySoundRewriter extends R SoundData data = soundRewrites.get(soundId); if (data != null) return data.getReplacementSound(); - for (Map.Entry entry : soundRewrites.getMap().entrySet()) { - if (soundId > entry.getKey()) { + for (Int2ObjectMap.Entry entry : soundRewrites.int2ObjectEntrySet()) { + if (soundId > entry.getIntKey()) { if (entry.getValue().isAdded()) { newSoundId--; } else { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/PotionSplashHandler.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/PotionSplashHandler.java index 677759cc..3caf1f80 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/PotionSplashHandler.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/PotionSplashHandler.java @@ -1,13 +1,14 @@ package nl.matsv.viabackwards.protocol.protocol1_10to1_11; -import us.myles.ViaVersion.util.fastutil.CollectionUtil; -import us.myles.ViaVersion.util.fastutil.IntMap; +import us.myles.viaversion.libs.fastutil.ints.Int2IntMap; +import us.myles.viaversion.libs.fastutil.ints.Int2IntOpenHashMap; public class PotionSplashHandler { - private static final IntMap DATA = CollectionUtil.createIntMap(14); + private static final Int2IntMap DATA = new Int2IntOpenHashMap(14, 1F); static { + DATA.defaultReturnValue(-1); DATA.put(2039713, 5); // night vision DATA.put(8356754, 7); // invisibility DATA.put(2293580, 9); // jump boost diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java index 905cae70..bcd0426d 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java @@ -339,7 +339,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter new MappedLegacyBlockItem(52, (short) -1, null, false)); + MappedLegacyBlockItem data = replacementData.computeIfAbsent(52, s -> new MappedLegacyBlockItem(52, (short) -1, null, false)); data.setBlockEntityHandler((b, tag) -> { EntityIdRewriter.toClientSpawner(tag, true); return tag; diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/data/MapColorMapping.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/data/MapColorMapping.java index 23aa0d3c..e7dea632 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/data/MapColorMapping.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/data/MapColorMapping.java @@ -1,12 +1,13 @@ package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data; -import us.myles.ViaVersion.util.fastutil.CollectionUtil; -import us.myles.ViaVersion.util.fastutil.IntMap; +import us.myles.viaversion.libs.fastutil.ints.Int2IntMap; +import us.myles.viaversion.libs.fastutil.ints.Int2IntOpenHashMap; public class MapColorMapping { - private static final IntMap MAPPING = CollectionUtil.createIntMap(64); + private static final Int2IntMap MAPPING = new Int2IntOpenHashMap(64, 1F); static { + MAPPING.defaultReturnValue(-1); MAPPING.put(144, 59); // (148, 124, 114) -> (148, 124, 114) MAPPING.put(145, 56); // (180, 153, 139) -> (180, 153, 139) MAPPING.put(146, 56); // (209, 177, 161) -> (209, 177, 161) diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java index 3d4dc362..24c5d57b 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java @@ -13,15 +13,15 @@ package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handler import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider; import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.util.fastutil.CollectionUtil; -import us.myles.ViaVersion.util.fastutil.IntObjectMap; +import us.myles.viaversion.libs.fastutil.ints.Int2ObjectMap; +import us.myles.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; import us.myles.viaversion.libs.opennbt.tag.builtin.IntTag; import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag; public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler { - private static final IntObjectMap> FLOWERS = CollectionUtil.createIntObjectMap(22); + private static final Int2ObjectMap> FLOWERS = new Int2ObjectOpenHashMap<>(22, 1F); private static final Pair AIR = new Pair<>("minecraft:air", (byte) 0); static { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/EntityTypeMapping.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/EntityTypeMapping.java index 0d195dae..4b388ca6 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/EntityTypeMapping.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/EntityTypeMapping.java @@ -1,20 +1,23 @@ package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.EntityTypeRewriter; -import us.myles.ViaVersion.util.fastutil.CollectionUtil; -import us.myles.ViaVersion.util.fastutil.IntMap; +import us.myles.viaversion.libs.fastutil.ints.Int2IntMap; +import us.myles.viaversion.libs.fastutil.ints.Int2IntOpenHashMap; import java.lang.reflect.Field; public class EntityTypeMapping { - private static final IntMap TYPES = CollectionUtil.createIntMap(); + private static final Int2IntMap TYPES = new Int2IntOpenHashMap(); static { + TYPES.defaultReturnValue(-1); try { Field field = EntityTypeRewriter.class.getDeclaredField("ENTITY_TYPES"); field.setAccessible(true); - IntMap entityTypes = (IntMap) field.get(null); - entityTypes.getMap().forEach((type1_12, type1_13) -> EntityTypeMapping.TYPES.put(type1_13, type1_12)); + Int2IntMap entityTypes = (Int2IntMap) field.get(null); + for (Int2IntMap.Entry entry : entityTypes.int2IntEntrySet()) { + EntityTypeMapping.TYPES.put(entry.getIntValue(), entry.getIntKey()); + } } catch (NoSuchFieldException | IllegalAccessException ex) { ex.printStackTrace(); } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java index db8e054e..9fc79264 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -101,8 +101,8 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It @Override public void handle(PacketWrapper wrapper) throws Exception { int itemId = wrapper.read(Type.VAR_INT); - Integer oldId = MappingData.oldToNewItems.inverse().get(itemId); - if (oldId != null) { + int oldId = MappingData.oldToNewItems.inverse().get(itemId); + if (oldId != -1) { Optional eggEntityId = SpawnEggRewriter.getEntityId(oldId); if (eggEntityId.isPresent()) { itemId = 383 << 16; @@ -413,12 +413,12 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It int id = wrapper.get(Type.INT, 0); int data = wrapper.get(Type.INT, 1); if (id == 1010) { // Play record - wrapper.set(Type.INT, 1, data = MappingData.oldToNewItems.inverse().get(data) >> 4); + wrapper.set(Type.INT, 1, MappingData.oldToNewItems.inverse().get(data) >> 4); } else if (id == 2001) { // Block break + block break sound data = toOldId(data); int blockId = data >> 4; int blockData = data & 0xF; - wrapper.set(Type.INT, 1, data = (blockId & 0xFFF) | (blockData << 12)); + wrapper.set(Type.INT, 1, (blockId & 0xFFF) | (blockData << 12)); } } }); @@ -543,8 +543,8 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It // No custom mapping found, look at VV mappings if (item.getIdentifier() == originalId) { - Integer oldId = MappingData.oldToNewItems.inverse().get(item.getIdentifier()); - if (oldId != null) { + int oldId = MappingData.oldToNewItems.inverse().get(item.getIdentifier()); + if (oldId != -1) { rawId = itemIdToRaw(oldId, item, tag); } else if (item.getIdentifier() == 362) { // base/colorless shulker box rawId = 0xe50000; // purple shulker box diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java index 33f380e9..d735c733 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java @@ -13,16 +13,15 @@ package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage; import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.minecraft.Position; -import us.myles.ViaVersion.util.fastutil.CollectionUtil; -import us.myles.ViaVersion.util.fastutil.IntSet; +import us.myles.viaversion.libs.fastutil.ints.IntOpenHashSet; +import us.myles.viaversion.libs.fastutil.ints.IntSet; -import java.util.HashSet; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; public class BackwardsBlockStorage extends StoredObject { // This BlockStorage is very exclusive (; - private static final IntSet WHITELIST = CollectionUtil.createIntSet(779); + private static final IntSet WHITELIST = new IntOpenHashSet(779); static { // Flower pots diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java index 8c19bcfb..c80f934a 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java @@ -122,8 +122,8 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol BackwardsMappings.blockMappings.getNewId(id), id -> { - Integer oldId = MappingData.oldToNewItems.inverse().get(id); - return oldId != null ? oldId : -1; - }, entityPackets::getOldEntityId).register(ClientboundPackets1_16.TAGS); + new TagRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), id -> + MappingData.oldToNewItems.inverse().get(id), entityPackets::getOldEntityId).register(ClientboundPackets1_16.TAGS); cancelIncoming(ServerboundPackets1_14.UPDATE_JIGSAW_BLOCK); } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java index 80d495fb..4433afd3 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java @@ -274,8 +274,8 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It } public static int getNewItemId(int id) { - Integer newId = MappingData.oldToNewItems.get(id); - if (newId == null) { + int newId = MappingData.oldToNewItems.get(id); + if (newId == -1) { ViaBackwards.getPlatform().getLogger().warning("Missing 1.16 item for 1.15 item " + id); return 1; } @@ -283,8 +283,8 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It } public static int getOldItemId(int id) { - Integer oldId = MappingData.oldToNewItems.inverse().get(id); - if (oldId == null) { + int oldId = MappingData.oldToNewItems.inverse().get(id); + if (oldId == -1) { ViaBackwards.getPlatform().getLogger().warning("Missing 1.15 item for 1.16 item " + id); return 1; }