From 30e10bb6450fc9e72d23feedf1e4ba26e12c5bc5 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Mon, 8 Jun 2020 12:27:34 +0200 Subject: [PATCH 1/9] Create soft wrapper for FU IntSet and Int2IntMap --- common/pom.xml | 8 + .../api/rewriters/MetadataRewriter.java | 8 +- .../blockconnections/ConnectionData.java | 4 +- .../FlowerConnectionHandler.java | 10 +- .../RedstoneConnectionHandler.java | 13 +- .../data/EntityTypeRewriter.java | 107 ----------- .../MetadataRewriter1_13To1_12_2.java | 8 +- .../packets/WorldPackets.java | 24 +-- .../storage/BlockConnectionStorage.java | 23 ++- .../storage/BlockStorage.java | 29 +-- .../data/EntityTypeRewriter.java | 109 ----------- .../data/MappingData.java | 14 +- .../MetadataRewriter1_14To1_13_2.java | 8 +- .../packets/EntityPackets.java | 3 +- .../protocol1_9to1_8/ItemRewriter.java | 10 +- .../protocol1_9to1_8/sounds/Effect.java | 15 +- .../util/fastutil/CollectionUtil.java | 173 ++++++++++++++++++ .../ViaVersion/util/fastutil/IntMap.java | 35 ++++ .../ViaVersion/util/fastutil/IntSet.java | 22 +++ 19 files changed, 324 insertions(+), 299 deletions(-) delete mode 100644 common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java delete mode 100644 common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/EntityTypeRewriter.java create mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/CollectionUtil.java create mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/IntMap.java create mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/IntSet.java diff --git a/common/pom.xml b/common/pom.xml index 4874d16c3..4d79ce92a 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -19,5 +19,13 @@ 1.18 compile + + + + it.unimi.dsi + fastutil + 8.3.1 + provided + diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java index de6db2ebd..07b3c5599 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java @@ -12,6 +12,8 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.storage.EntityTracker; import us.myles.ViaVersion.api.type.Type; 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 java.util.ArrayList; import java.util.Collections; @@ -23,7 +25,7 @@ import java.util.logging.Logger; public abstract class MetadataRewriter { private final Class entityTrackerClass; private final Protocol protocol; - private Map typeMapping; + private IntMap typeMapping; protected MetadataRewriter(Protocol protocol, Class entityTrackerClass) { this.protocol = protocol; @@ -182,7 +184,7 @@ public abstract class MetadataRewriter { } public & EntityType> void mapTypes(EntityType[] oldTypes, Class newTypeClass) { - if (typeMapping == null) typeMapping = new HashMap<>(oldTypes.length); + if (typeMapping == null) typeMapping = CollectionUtil.createIntMap(oldTypes.length); for (EntityType oldType : oldTypes) { try { T newType = Enum.valueOf(newTypeClass, oldType.name()); @@ -197,7 +199,7 @@ public abstract class MetadataRewriter { } public void mapType(EntityType oldType, EntityType newType) { - if (typeMapping == null) typeMapping = new HashMap<>(); + if (typeMapping == null) typeMapping = CollectionUtil.createIntMap(); typeMapping.put(oldType.getId(), newType.getId()); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java index 54932df94..4716d3dd4 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java @@ -16,6 +16,8 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.PacketBlockConnectionProvider; +import us.myles.ViaVersion.util.fastutil.CollectionUtil; +import us.myles.ViaVersion.util.fastutil.IntSet; import java.util.*; import java.util.Map.Entry; @@ -27,7 +29,7 @@ public class ConnectionData { static Map keyToId = new HashMap<>(); static Map connectionHandlerMap = new HashMap<>(); static Map blockConnectionData = new HashMap<>(); - static Set occludingStates = new HashSet<>(); + static IntSet occludingStates = CollectionUtil.createIntSet(377); public static void update(UserConnection user, Position position) { for (BlockFace face : BlockFace.values()) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/FlowerConnectionHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/FlowerConnectionHandler.java index 2f181262e..14eac24c9 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/FlowerConnectionHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/FlowerConnectionHandler.java @@ -4,15 +4,15 @@ import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.minecraft.BlockFace; import us.myles.ViaVersion.api.minecraft.Position; +import us.myles.ViaVersion.util.fastutil.CollectionUtil; +import us.myles.ViaVersion.util.fastutil.IntMap; -import java.util.HashMap; import java.util.HashSet; -import java.util.Map; import java.util.Set; public class FlowerConnectionHandler extends ConnectionHandler { - private static final Map flowers = new HashMap<>(); + private static final IntMap flowers = CollectionUtil.createIntMap(); static ConnectionData.ConnectorInitAction init() { final Set baseFlower = new HashSet<>(); @@ -38,8 +38,8 @@ public class FlowerConnectionHandler extends ConnectionHandler { @Override public int connect(UserConnection user, Position position, int blockState) { int blockBelowId = getBlockData(user, position.getRelative(BlockFace.BOTTOM)); - Integer connectBelow = flowers.get(blockBelowId); - if (connectBelow != null) { + int connectBelow = flowers.get(blockBelowId); + if (connectBelow != -1) { int blockAboveId = getBlockData(user, position.getRelative(BlockFace.TOP)); if (Via.getConfig().isStemWhenBlockAbove()) { if (blockAboveId == 0) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java index bfb3ef5ac..a09528880 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java @@ -3,16 +3,16 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.minecraft.BlockFace; import us.myles.ViaVersion.api.minecraft.Position; +import us.myles.ViaVersion.util.fastutil.CollectionUtil; +import us.myles.ViaVersion.util.fastutil.IntMap; -import java.util.HashMap; import java.util.HashSet; -import java.util.Map; import java.util.Set; public class RedstoneConnectionHandler extends ConnectionHandler { private static final Set redstone = new HashSet<>(); - private static final Map connectedBlockStates = new HashMap<>(); - private static final Map powerMappings = new HashMap<>(); + private static final IntMap connectedBlockStates = CollectionUtil.createIntMap(1296); + private static final IntMap powerMappings = CollectionUtil.createIntMap(1296); static ConnectionData.ConnectorInitAction init() { final RedstoneConnectionHandler connectionHandler = new RedstoneConnectionHandler(); @@ -22,7 +22,7 @@ public class RedstoneConnectionHandler extends ConnectionHandler { redstone.add(blockData.getSavedBlockStateId()); ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), connectionHandler); connectedBlockStates.put(getStates(blockData), blockData.getSavedBlockStateId()); - powerMappings.put(blockData.getSavedBlockStateId(), Integer.valueOf(blockData.getValue("power"))); + powerMappings.put(blockData.getSavedBlockStateId(), Integer.parseInt(blockData.getValue("power"))); }; } @@ -57,8 +57,7 @@ public class RedstoneConnectionHandler extends ConnectionHandler { b |= connects(user, position, BlockFace.SOUTH) << 4; b |= connects(user, position, BlockFace.WEST) << 6; b |= powerMappings.get(blockState) << 8; - final Integer newBlockState = connectedBlockStates.get(b); - return newBlockState == null ? blockState : newBlockState; + return connectedBlockStates.getOrDefault(b, blockState); } private int connects(UserConnection user, Position position, BlockFace side) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java deleted file mode 100644 index 0573c2c72..000000000 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java +++ /dev/null @@ -1,107 +0,0 @@ -package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data; - - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -public class EntityTypeRewriter { - private static final Map entityTypes = new HashMap<>(); - - static { - registerEntity(1, 32); // item - ajl - registerEntity(2, 22); // xp_orb - abx - registerEntity(3, 0); // area_effect_cloud - abp - registerEntity(4, 15); // elder_guardian - aju - registerEntity(5, 84); // wither_skeleton - aku - registerEntity(6, 71); // stray - akq - registerEntity(7, 74); // egg - alz - registerEntity(8, 35); // leash_knot - ajb - registerEntity(9, 49); // painting - ajd - registerEntity(10, 2); // arrow - all - registerEntity(11, 67); // snowball - alw - registerEntity(12, 34); // fireball - alq - registerEntity(13, 65); // small_fireball - alv - registerEntity(14, 75); // ender_pearl - ama - registerEntity(15, 23); // eye_of_ender_signal - alo - registerEntity(16, 77); // potion - amc - registerEntity(17, 76); // xp_bottle - amb - registerEntity(18, 33); // item_frame - aja - registerEntity(19, 85); // wither_skull - ame - registerEntity(20, 55); // tnt - ajm - registerEntity(21, 24); // falling_block - ajk - registerEntity(22, 25); // fireworks_rocket - alp - registerEntity(23, 30); // husk - akc - registerEntity(24, 68); // spectral_arrow - alx - registerEntity(25, 60); // shulker_bullet - alu - registerEntity(26, 13); // dragon_fireball - alm - registerEntity(27, 89); // zombie_villager - akw - registerEntity(28, 63); // skeleton_horse - aht - registerEntity(29, 88); // zombie_horse - ahv - registerEntity(30, 1); // armor_stand - aiy - registerEntity(31, 11); // donkey - aho - registerEntity(32, 46); // mule - ahs - registerEntity(33, 20); // evocation_fangs - aln - registerEntity(34, 21); // evocation_illager - ajy - registerEntity(35, 78); // vex - akr - registerEntity(36, 81); // vindication_illager - aks - registerEntity(37, 31); // illusion_illager - akd - registerEntity(40, 41); // commandblock_minecart - aml - registerEntity(41, 5); // boat - ami - registerEntity(42, 39); // minecart - amj - registerEntity(43, 40); // chest_minecart - amk - registerEntity(44, 42); // furnace_minecart - amm - registerEntity(45, 45); // tnt_minecart - amp - registerEntity(46, 43); // hopper_minecart - amn - registerEntity(47, 44); // spawner_minecart - amo - registerEntity(50, 10); // creeper - ajs - registerEntity(51, 62); // skeleton - akm - registerEntity(52, 69); // spider - akp - registerEntity(53, 27); // giant - aka - registerEntity(54, 87); // zombie - akv - registerEntity(55, 64); // slime - akn - registerEntity(56, 26); // ghast - ajz - registerEntity(57, 53); // zombie_pigman - akh - registerEntity(58, 18); // enderman - ajv - registerEntity(59, 6); // cave_spider - ajr - registerEntity(60, 61); // silverfish - akl - registerEntity(61, 4); // blaze - ajq - registerEntity(62, 38); // magma_cube - ake - registerEntity(63, 17); // ender_dragon - aic - registerEntity(64, 83); // wither - aiw - registerEntity(65, 3); // bat - agl - registerEntity(66, 82); // witch - akt - registerEntity(67, 19); // endermite - ajw - registerEntity(68, 28); // guardian - akb - registerEntity(69, 59); // shulker - akk - registerEntity(200, 16); // ender_crystal - aib - registerEntity(90, 51); // pig - agy - registerEntity(91, 58); // sheep - ahd - registerEntity(92, 9); // cow - ags - registerEntity(93, 7); // chicken - agq - registerEntity(94, 70); // squid - ahg - registerEntity(95, 86); // wolf - ahl - registerEntity(96, 47); // mooshroom - agv - registerEntity(97, 66); // snowman - ahf - registerEntity(98, 48); // ocelot - agw - registerEntity(99, 80); // villager_golem - ahj - registerEntity(100, 29); // horse - ahp - registerEntity(101, 56); // rabbit - ahb - registerEntity(102, 54); // polar_bear - agz - registerEntity(103, 36); // llama - ahr - registerEntity(104, 37); // llama_spit - alr - registerEntity(105, 50); // parrot - agx - registerEntity(120, 79); // villager - ala - - // OBJECTS - // Couldn't find any object id change with mapped values - } - - private static void registerEntity(int type1_12, int type1_13) { - entityTypes.put(type1_12, type1_13); - } - - public static Optional getNewId(int type1_12) { - return Optional.ofNullable(entityTypes.get(type1_12)); - } -} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java index db9709547..78ef07c8d 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java @@ -1,6 +1,7 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.metadata; import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.entities.Entity1_12Types; import us.myles.ViaVersion.api.entities.Entity1_13Types; import us.myles.ViaVersion.api.entities.EntityType; import us.myles.ViaVersion.api.minecraft.item.Item; @@ -10,7 +11,6 @@ import us.myles.ViaVersion.api.rewriters.MetadataRewriter; import us.myles.ViaVersion.api.type.types.Particle; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; -import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.EntityTypeRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets; @@ -23,6 +23,7 @@ public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter { public MetadataRewriter1_13To1_12_2(Protocol1_13To1_12_2 protocol) { super(protocol, EntityTracker1_13.class); + mapTypes(Entity1_12Types.EntityType.values(), Entity1_13Types.EntityType.class); } @Override @@ -100,11 +101,6 @@ public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter { // TODO: Boat has changed } - @Override - public int getNewEntityId(final int oldId) { - return EntityTypeRewriter.getNewId(oldId).orElse(oldId); - } - @Override protected EntityType getTypeFromId(int type) { return Entity1_13Types.getTypeFromId(type, false); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java index 4e33f4abc..1ffc37a6b 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java @@ -26,32 +26,32 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.BlockStorage; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type; 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.util.fastutil.CollectionUtil; +import us.myles.ViaVersion.util.fastutil.IntSet; -import java.util.HashSet; import java.util.List; import java.util.Optional; -import java.util.Set; public class WorldPackets { - private static final Set validBiomes = new HashSet<>(); + private static final IntSet VALID_BIOMES = CollectionUtil.createIntSet(70); static { // Client will crash if it receives a invalid biome id for (int i = 0; i < 50; i++) { - validBiomes.add(i); + VALID_BIOMES.add(i); } - validBiomes.add(127); + VALID_BIOMES.add(127); for (int i = 129; i <= 134; i++) { - validBiomes.add(i); + VALID_BIOMES.add(i); } - validBiomes.add(140); - validBiomes.add(149); - validBiomes.add(151); + VALID_BIOMES.add(140); + VALID_BIOMES.add(149); + VALID_BIOMES.add(151); for (int i = 155; i <= 158; i++) { - validBiomes.add(i); + VALID_BIOMES.add(i); } for (int i = 160; i <= 167; i++) { - validBiomes.add(i); + VALID_BIOMES.add(i); } } @@ -407,7 +407,7 @@ public class WorldPackets { int latestBiomeWarn = Integer.MIN_VALUE; for (int i = 0; i < 256; i++) { int biome = chunk.getBiomeData()[i]; - if (!validBiomes.contains(biome)) { + if (!VALID_BIOMES.contains(biome)) { if (biome != 255 // is it generated naturally? *shrug* && latestBiomeWarn != biome) { if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java index 56ccd68fd..85de84490 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java @@ -11,25 +11,29 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; public class BlockConnectionStorage extends StoredObject { - private final Map> blockStorage = createLongObjectMap(); - - private static final Map reverseBlockMappings; + private static final short[] REVERSE_BLOCK_MAPPINGS = new short[8581]; private static Constructor fastUtilLongObjectHashMap; + private final Map> blockStorage = createLongObjectMap(); + static { try { fastUtilLongObjectHashMap = Class.forName("it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap").getConstructor(); Via.getPlatform().getLogger().info("Using FastUtil Long2ObjectOpenHashMap for block connections"); } catch (ClassNotFoundException | NoSuchMethodException ignored) { } - reverseBlockMappings = new HashMap<>(); + + Arrays.fill(REVERSE_BLOCK_MAPPINGS, (short) -1); for (int i = 0; i < 4096; i++) { int newBlock = MappingData.blockMappings.getNewId(i); - if (newBlock != -1) reverseBlockMappings.put((short) newBlock, (short) i); + if (newBlock != -1) { + REVERSE_BLOCK_MAPPINGS[newBlock] = (short) i; + } } } @@ -38,15 +42,18 @@ public class BlockConnectionStorage extends StoredObject { } public void store(int x, int y, int z, int blockState) { - Short mapping = reverseBlockMappings.get((short) blockState); - if (mapping == null) return; + short mapping = REVERSE_BLOCK_MAPPINGS[blockState]; + if (mapping == -1) return; + blockState = mapping; long pair = getChunkSectionIndex(x, y, z); Pair map = getChunkSection(pair, (blockState & 0xF) != 0); int blockIndex = encodeBlockPos(x, y, z); map.getKey()[blockIndex] = (byte) (blockState >> 4); NibbleArray nibbleArray = map.getValue(); - if (nibbleArray != null) nibbleArray.set(blockIndex, blockState); + if (nibbleArray != null) { + nibbleArray.set(blockIndex, blockState); + } } public int get(int x, int y, int z) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java index dfdbf1b7c..94e9fcaa9 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java @@ -3,36 +3,39 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.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 java.util.HashSet; import java.util.Map; -import java.util.Set; import java.util.concurrent.ConcurrentHashMap; public class BlockStorage extends StoredObject { - private static final Set whitelist = new HashSet<>(); + private static final IntSet WHITELIST = CollectionUtil.createIntSet(46); private final Map blocks = new ConcurrentHashMap<>(); static { // Flower pots - whitelist.add(5266); + WHITELIST.add(5266); // Add those red beds - for (int i = 0; i < 16; i++) - whitelist.add(972 + i); + for (int i = 0; i < 16; i++) { + WHITELIST.add(972 + i); + } // Add the white banners - for (int i = 0; i < 20; i++) - whitelist.add(6854 + i); + for (int i = 0; i < 20; i++) { + WHITELIST.add(6854 + i); + } // Add the white wall banners for (int i = 0; i < 4; i++) { - whitelist.add(7110 + i); + WHITELIST.add(7110 + i); } // Skeleton skulls - for (int i = 0; i < 5; i++) - whitelist.add(5447 + i); + for (int i = 0; i < 5; i++) { + WHITELIST.add(5447 + i); + } } public BlockStorage(UserConnection user) { @@ -44,14 +47,14 @@ public class BlockStorage extends StoredObject { } public void store(Position position, int block, int replacementId) { - if (!whitelist.contains(block)) + if (!WHITELIST.contains(block)) return; blocks.put(position, new ReplacementData(block, replacementId)); } public boolean isWelcome(int block) { - return whitelist.contains(block); + return WHITELIST.contains(block); } public boolean contains(Position position) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/EntityTypeRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/EntityTypeRewriter.java deleted file mode 100644 index 32529384a..000000000 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/EntityTypeRewriter.java +++ /dev/null @@ -1,109 +0,0 @@ -package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -public class EntityTypeRewriter { - private static final Map entityTypes = new HashMap<>(); - - static { - regEnt(6, 7); // cave_spider - regEnt(7, 8); // chicken - regEnt(8, 9); // cod - regEnt(9, 10); // cow - regEnt(10, 11); // creeper - regEnt(11, 12); // donkey - regEnt(12, 13); // dolphin - regEnt(13, 14); // dragon_fireball - regEnt(14, 15); // drowned - regEnt(15, 16); // elder_guardian - regEnt(16, 17); // end_crystal - regEnt(17, 18); // ender_dragon - regEnt(18, 19); // enderman - regEnt(19, 20); // endermite - regEnt(20, 21); // evoker_fangs - regEnt(21, 22); // evoker - regEnt(22, 23); // experience_orb - regEnt(23, 24); // eye_of_ender - regEnt(24, 25); // falling_block - regEnt(25, 26); // firework_rocket - regEnt(26, 28); // ghast - regEnt(27, 29); // giant - regEnt(28, 30); // guardian - regEnt(29, 31); // horse - regEnt(30, 32); // husk - regEnt(31, 33); // illusioner - regEnt(32, 34); // item - regEnt(33, 35); // item_frame - regEnt(34, 36); // fireball - regEnt(35, 37); // leash_knot - regEnt(36, 38); // llama - regEnt(37, 39); // llama_spit - regEnt(38, 40); // magma_cube - regEnt(39, 41); // minecart - regEnt(40, 42); // chest_minecart - regEnt(41, 43); // command_block_minecart - regEnt(42, 44); // furnace_minecart - regEnt(43, 45); // hopper_minecart - regEnt(44, 46); // spawner_minecart - regEnt(45, 47); // tnt_minecart - regEnt(46, 48); // mule - regEnt(47, 49); // mooshroom - regEnt(48, 6); // ocelot -> cat TODO Remap untamed ocelot to ocelot? - regEnt(49, 51); // painting - regEnt(50, 53); // parrot - regEnt(51, 54); // pig - regEnt(52, 55); // pufferfish - regEnt(53, 56); // zombie_pigman - regEnt(54, 57); // polar_bear - regEnt(55, 58); // tnt - regEnt(56, 59); // rabbit - regEnt(57, 60); // salmon - regEnt(58, 61); // sheep - regEnt(59, 62); // shulker - regEnt(60, 63); // shulker_bullet - regEnt(61, 64); // silverfish - regEnt(62, 65); // skeleton - regEnt(63, 66); // skeleton_horse - regEnt(64, 67); // slime - regEnt(65, 68); // small_fireball - regEnt(66, 69); // snowgolem - regEnt(67, 70); // snowball - regEnt(68, 71); // spectral_arrow - regEnt(69, 72); // spider - regEnt(70, 73); // squid - regEnt(71, 74); // stray - regEnt(72, 76); // tropical_fish - regEnt(73, 77); // turtle - regEnt(74, 78); // egg - regEnt(75, 79); // ender_pearl - regEnt(76, 80); // experience_bottle - regEnt(77, 81); // potion - regEnt(78, 83); // vex - regEnt(79, 84); // villager - regEnt(80, 85); // iron_golem - regEnt(81, 86); // vindicator - regEnt(82, 89); // witch - regEnt(83, 90); // wither - regEnt(84, 91); // wither_skeleton - regEnt(85, 92); // wither_skull - regEnt(86, 93); // wolf - regEnt(87, 94); // zombie - regEnt(88, 95); // zombie_horse - regEnt(89, 96); // zombie_villager - regEnt(90, 97); // phantom - regEnt(91, 99); // lightning_bolt - regEnt(92, 100); // player - regEnt(93, 101); // fishing_bobber - regEnt(94, 82); // trident - } - - private static void regEnt(int type1_13, int type1_14) { - entityTypes.put(type1_13, type1_14); - } - - public static Optional getNewId(int type1_13) { - return Optional.ofNullable(entityTypes.get(type1_13)); - } -} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java index 261793a45..eec379699 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java @@ -8,19 +8,19 @@ import com.google.gson.JsonObject; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.Mappings; +import us.myles.ViaVersion.util.fastutil.CollectionUtil; +import us.myles.ViaVersion.util.fastutil.IntSet; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; -import java.util.Set; public class MappingData { public static final BiMap oldToNewItems = HashBiMap.create(); public static Mappings blockStateMappings; public static Mappings blockMappings; public static Mappings soundMappings; - public static Set motionBlocking; - public static Set nonFullBlocks; + public static IntSet motionBlocking; + public static IntSet nonFullBlocks; public static void init() { Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 mappings..."); @@ -40,19 +40,19 @@ public class MappingData { JsonObject heightMapData = MappingDataLoader.loadData("heightMapData-1.14.json"); JsonArray motionBlocking = heightMapData.getAsJsonArray("MOTION_BLOCKING"); - us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData.motionBlocking = new HashSet<>(motionBlocking.size()); + MappingData.motionBlocking = CollectionUtil.createIntSet(motionBlocking.size()); for (JsonElement blockState : motionBlocking) { String key = blockState.getAsString(); Integer id = blockStateMap.get(key); if (id == null) { Via.getPlatform().getLogger().warning("Unknown blockstate " + key + " :("); } else { - us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData.motionBlocking.add(id); + MappingData.motionBlocking.add(id); } } if (Via.getConfig().isNonFullBlockLightFix()) { - nonFullBlocks = new HashSet<>(); + nonFullBlocks = CollectionUtil.createIntSet(1611); for (Map.Entry blockstates : mapping1_13_2.getAsJsonObject("blockstates").entrySet()) { final String state = blockstates.getValue().getAsString(); if (state.contains("_slab") || state.contains("_stairs") || state.contains("_wall[")) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/metadata/MetadataRewriter1_14To1_13_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/metadata/MetadataRewriter1_14To1_13_2.java index a4a334f67..fe3e69975 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/metadata/MetadataRewriter1_14To1_13_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/metadata/MetadataRewriter1_14To1_13_2.java @@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.metadata; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.entities.Entity1_13Types; import us.myles.ViaVersion.api.entities.Entity1_14Types; import us.myles.ViaVersion.api.entities.EntityType; import us.myles.ViaVersion.api.minecraft.VillagerData; @@ -13,7 +14,6 @@ import us.myles.ViaVersion.api.rewriters.MetadataRewriter; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.Particle; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2; -import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.EntityTypeRewriter; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14; @@ -23,6 +23,7 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter { public MetadataRewriter1_14To1_13_2(Protocol1_14To1_13_2 protocol) { super(protocol, EntityTracker1_14.class); + mapTypes(Entity1_13Types.EntityType.values(), Entity1_14Types.EntityType.class); } @Override @@ -168,11 +169,6 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter { } } - @Override - public int getNewEntityId(final int oldId) { - return EntityTypeRewriter.getNewId(oldId).orElse(oldId); - } - @Override protected EntityType getTypeFromId(int type) { return Entity1_14Types.getTypeFromId(type); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java index b3de6fe43..e81c7e5f8 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java @@ -14,7 +14,6 @@ import us.myles.ViaVersion.api.type.types.version.Types1_14; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2; -import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.EntityTypeRewriter; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.metadata.MetadataRewriter1_14To1_13_2; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14; @@ -50,7 +49,7 @@ public class EntityPackets { int typeId = wrapper.get(Type.VAR_INT, 1); Entity1_13Types.EntityType type1_13 = Entity1_13Types.getTypeFromId(typeId, true); - typeId = EntityTypeRewriter.getNewId(type1_13.getId()).orElse(type1_13.getId()); + typeId = metadataRewriter.getNewEntityId(type1_13.getId()); Entity1_14Types.EntityType type1_14 = Entity1_14Types.getTypeFromId(typeId); if (type1_14 != null) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java index d69e1407e..659a3ac02 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java @@ -5,6 +5,8 @@ import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.Tag; import us.myles.ViaVersion.api.minecraft.item.Item; +import us.myles.ViaVersion.util.fastutil.CollectionUtil; +import us.myles.ViaVersion.util.fastutil.IntMap; import java.util.Collections; import java.util.HashMap; @@ -17,7 +19,7 @@ public class ItemRewriter { private static final Map POTION_NAME_TO_ID = new HashMap<>(); private static final Map POTION_ID_TO_NAME = new HashMap<>(); - private static final Map POTION_INDEX = new HashMap<>(); + private static final IntMap POTION_INDEX = CollectionUtil.createIntMap(36); static { /* Entities */ @@ -381,13 +383,13 @@ public class ItemRewriter { oldID -= 8192; } - Integer index = POTION_INDEX.get(oldID); - if (index != null) { + int index = POTION_INDEX.get(oldID); + if (index != -1) { return index; } oldID = POTION_NAME_TO_ID.get(potionNameFromDamage((short) oldID)); - return (index = POTION_INDEX.get(oldID)) != null ? index : 0; + return (index = POTION_INDEX.get(oldID)) != -1 ? index : 0; } private static void registerEntity(Integer id, String name) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/Effect.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/Effect.java index 632e7e298..dd0a5a115 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/Effect.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/Effect.java @@ -1,14 +1,13 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds; -import java.util.HashMap; -import java.util.Map; +import us.myles.ViaVersion.util.fastutil.CollectionUtil; +import us.myles.ViaVersion.util.fastutil.IntMap; public class Effect { - private static final Map effects; + private static final IntMap EFFECTS = CollectionUtil.createIntMap(17); static { - effects = new HashMap<>(); addRewrite(1005, 1010); //Play music disc addRewrite(1003, 1005); //Iron door open addRewrite(1006, 1011); //Iron door close @@ -26,19 +25,17 @@ public class Effect { addRewrite(1020, 1029); //Anvil break addRewrite(1021, 1030); //Anvil use addRewrite(1022, 1031); //Anvil land - } public static int getNewId(int id) { - Integer newId = effects.get(id); - return newId != null ? newId : id; + return EFFECTS.getOrDefault(id, id); } public static boolean contains(int oldId) { - return effects.containsKey(oldId); + return EFFECTS.containsKey(oldId); } private static void addRewrite(int oldId, int newId) { - effects.put(oldId, newId); + EFFECTS.put(oldId, newId); } } diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/CollectionUtil.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/CollectionUtil.java new file mode 100644 index 000000000..fa5e7605e --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/util/fastutil/CollectionUtil.java @@ -0,0 +1,173 @@ +package us.myles.ViaVersion.util.fastutil; + +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * Utility class to possibly wrap FastUtil collections for faster access. + * These should only be used for high access and low/no change collections, since resizing FastUtil collections is expensive. + */ +public class CollectionUtil { + private static final boolean FAST_UTIL = hasFastUtil(); + + private static boolean hasFastUtil() { + try { + Class.forName("Int2IntMap"); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } + + /** + * Creates a new FastUtil collection from the given map if present, else simply wraps the original. + * + * @param originalMap map to be reflected + * @return wrapped int map + */ + public static IntMap createIntMap(Map originalMap) { + return FAST_UTIL ? new WrappedFUIntMap(new Int2IntOpenHashMap(originalMap)) : new WrappedIntMap(originalMap); + } + + /** + * Creates a new FastUtil collection if present, else simply wraps a normal HashMap. + * + * @param size expected size of the collection + * @return wrapped int map + */ + public static IntMap createIntMap(int size) { + return FAST_UTIL ? new WrappedFUIntMap(new Int2IntOpenHashMap(size)) : new WrappedIntMap(new HashMap<>(size)); + } + + public static IntMap createIntMap() { + return FAST_UTIL ? new WrappedFUIntMap(new Int2IntOpenHashMap()) : new WrappedIntMap(new HashMap<>()); + } + + /** + * Creates a new FastUtil collection from the given set if present, else simply wraps the original. + * + * @param originalSet set to be reflected + * @return wrapped int set + */ + public static IntSet createIntSet(Set originalSet) { + return FAST_UTIL ? new WrappedFUIntSet(new IntOpenHashSet(originalSet)) : new WrappedIntSet(originalSet); + } + + /** + * Creates a new FastUtil collection if present, else simply wraps a normal HashSet. + * + * @param size expected size of the collection + * @return wrapped int set + */ + public static IntSet createIntSet(int size) { + return FAST_UTIL ? new WrappedFUIntSet(new IntOpenHashSet(size)) : new WrappedIntSet(new HashSet<>(size)); + } + + private static final class WrappedFUIntMap implements IntMap { + private final Int2IntMap map; + + private WrappedFUIntMap(Int2IntMap map) { + this.map = map; + } + + @Override + public int getOrDefault(int key, int def) { + return map.getOrDefault(key, def); + } + + @Override + public boolean containsKey(int key) { + return map.containsKey(key); + } + + @Override + public int put(int key, int value) { + return map.put(key, value); + } + + @Override + public int remove(int key) { + return map.remove(key); + } + } + + private static final class WrappedIntMap implements IntMap { + private final Map map; + + private WrappedIntMap(Map map) { + this.map = map; + } + + @Override + public int getOrDefault(int key, int def) { + return map.getOrDefault(key, def); + } + + @Override + public boolean containsKey(int key) { + return map.containsKey(key); + } + + @Override + public int put(int key, int value) { + return map.put(key, value); + } + + @Override + public int remove(int key) { + return map.remove(key); + } + } + + private static final class WrappedFUIntSet implements IntSet { + private final it.unimi.dsi.fastutil.ints.IntSet set; + + private WrappedFUIntSet(it.unimi.dsi.fastutil.ints.IntSet set) { + this.set = set; + } + + @Override + public boolean contains(int key) { + return set.contains(key); + } + + @Override + public boolean add(int key) { + return set.add(key); + } + + @Override + public boolean remove(int key) { + return set.remove(key); + } + } + + private static final class WrappedIntSet implements IntSet { + private final Set set; + + private WrappedIntSet(Set set) { + this.set = set; + } + + @Override + public boolean contains(int key) { + return set.contains(key); + } + + @Override + public boolean add(int key) { + return set.add(key); + } + + @Override + public boolean remove(int key) { + return set.remove(key); + } + } +} diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntMap.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntMap.java new file mode 100644 index 000000000..060b25c8b --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntMap.java @@ -0,0 +1,35 @@ +package us.myles.ViaVersion.util.fastutil; + +/** + * Very simple wrapping interface to either be implemented by a HashMap or FastUtil's OpenHashMap. + */ +public interface IntMap { + + /** + * @return value if present, -1 otherwise + * @see java.util.HashMap#get(Object) + */ + default int get(int key) { + return getOrDefault(key, -1); + } + + /** + * @see java.util.HashMap#getOrDefault(Object, Object) (Object) + */ + int getOrDefault(int key, int def); + + /** + * @see java.util.HashMap#containsKey(Object) + */ + boolean containsKey(int key); + + /** + * @see java.util.HashMap#put(Object, Object) + */ + int put(int key, int value); + + /** + * @see java.util.HashMap#remove(Object) + */ + int remove(int key); +} diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntSet.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntSet.java new file mode 100644 index 000000000..74ec51cb9 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntSet.java @@ -0,0 +1,22 @@ +package us.myles.ViaVersion.util.fastutil; + +/** + * Very simple wrapping interface to either be implemented by a HashSet or FastUtil's OpenHashSet. + */ +public interface IntSet { + + /** + * @see java.util.HashSet#contains(Object) + */ + boolean contains(int key); + + /** + * @see java.util.HashSet#add(Object) + */ + boolean add(int key); + + /** + * @see java.util.HashSet#remove(Object) + */ + boolean remove(int key); +} From 1ad559212eed25d0fc49ea8d2a7a3be9071e1516 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Mon, 8 Jun 2020 13:49:26 +0200 Subject: [PATCH 2/9] Create soft wrapper for FU Int2ObjectMap --- .../api/entities/Entity1_13Types.java | 5 +- .../api/protocol/ProtocolRegistry.java | 19 ++- .../api/rewriters/MetadataRewriter.java | 2 +- .../blockconnections/ConnectionData.java | 21 ++- .../data/BlockIdData.java | 10 +- .../data/EntityTypeRewriter.java | 102 +++++++++++++ .../MetadataRewriter1_13To1_12_2.java | 8 +- .../storage/BlockConnectionStorage.java | 2 +- .../protocol1_9to1_8/metadata/MetaIndex.java | 3 +- .../util/fastutil/CollectionUtil.java | 144 ++++-------------- .../ViaVersion/util/fastutil/IntMap.java | 2 +- .../util/fastutil/IntObjectMap.java | 51 +++++++ .../util/fastutil/WrappedFUIntMap.java | 38 +++++ .../util/fastutil/WrappedFUIntObjectMap.java | 48 ++++++ .../util/fastutil/WrappedFUIntSet.java | 32 ++++ .../util/fastutil/WrappedIntMap.java | 37 +++++ .../util/fastutil/WrappedIntObjectMap.java | 46 ++++++ .../util/fastutil/WrappedIntSet.java | 31 ++++ 18 files changed, 465 insertions(+), 136 deletions(-) create mode 100644 common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java create mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/IntObjectMap.java create mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntMap.java create mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntObjectMap.java create mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntSet.java create mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntMap.java create mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntObjectMap.java create mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntSet.java diff --git a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_13Types.java b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_13Types.java index 591918921..1ede8e5e8 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_13Types.java +++ b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_13Types.java @@ -91,12 +91,11 @@ public class Entity1_13Types { // Fish ABSTRACT_FISHES(-1, ABSTRACT_CREATURE), // agb - COD_MOB(8, ABSTRACT_FISHES), // agf + COD(8, ABSTRACT_FISHES), // agf PUFFERFISH(52, ABSTRACT_FISHES), // agn SALMON(57, ABSTRACT_FISHES), // agp TROPICAL_FISH(72, ABSTRACT_FISHES), // agu - // Monsters ABSTRACT_MONSTER(-1, ABSTRACT_CREATURE), // ajs BLAZE(4, ABSTRACT_MONSTER), // ajd @@ -248,7 +247,7 @@ public class Entity1_13Types { ENDER_PEARL(65, EntityType.ENDER_PEARL), WITHER_SKULL(66, EntityType.WITHER_SKULL), SHULKER_BULLET(67, EntityType.SHULKER_BULLET), - LIAMA_SPIT(68, EntityType.LLAMA_SPIT), + LLAMA_SPIT(68, EntityType.LLAMA_SPIT), FALLING_BLOCK(70, EntityType.FALLING_BLOCK), ITEM_FRAME(71, EntityType.ITEM_FRAME), EYE_OF_ENDER(72, EntityType.EYE_OF_ENDER), diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java index 50331e45c..4d7929359 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java @@ -31,6 +31,8 @@ import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1To1_9; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.Protocol1_9_3To1_9_1_2; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_9_1.Protocol1_9To1_9_1; +import us.myles.ViaVersion.util.fastutil.CollectionUtil; +import us.myles.ViaVersion.util.fastutil.IntObjectMap; import java.util.ArrayList; import java.util.Arrays; @@ -52,7 +54,7 @@ public class ProtocolRegistry { public static final Protocol BASE_PROTOCOL = new BaseProtocol(); public static int SERVER_PROTOCOL = -1; // Input Version -> Output Version & Protocol (Allows fast lookup) - private static final Map> registryMap = new ConcurrentHashMap<>(); + private static final IntObjectMap> registryMap = CollectionUtil.createIntObjectMap(32); private static final Map, Protocol> protocols = new HashMap<>(); private static final Map, List>> pathCache = new ConcurrentHashMap<>(); private static final Set supportedVersions = new HashSet<>(); @@ -135,7 +137,12 @@ public class ProtocolRegistry { protocols.put(protocol.getClass(), protocol); for (int version : supported) { - Map protocolMap = registryMap.computeIfAbsent(version, k -> new HashMap<>()); + IntObjectMap protocolMap = registryMap.get(version); + if (protocolMap == null) { + protocolMap = CollectionUtil.createIntObjectMap(1); + registryMap.put(version, protocolMap); + } + protocolMap.put(output, protocol); } @@ -204,7 +211,7 @@ public class ProtocolRegistry { * @return True if there is a useful pipe */ public static boolean isWorkingPipe() { - for (Map maps : registryMap.values()) { + for (IntObjectMap maps : registryMap.getMap().values()) { if (maps.containsKey(SERVER_PROTOCOL)) return true; } return false; // No destination for protocol @@ -234,20 +241,22 @@ public class ProtocolRegistry { if (current.size() > 50) return null; // Fail safe, protocol too complicated. // First check if there is any protocols for this - Map inputMap = registryMap.get(clientVersion); + IntObjectMap inputMap = registryMap.get(clientVersion); if (inputMap == null) { return null; // Not supported } + // Next check there isn't an obvious path Protocol protocol = inputMap.get(serverVersion); if (protocol != null) { current.add(new Pair<>(serverVersion, protocol)); return current; // Easy solution } + // There might be a more advanced solution... So we'll see if any of the others can get us there List> shortest = null; - for (Map.Entry entry : inputMap.entrySet()) { + for (Map.Entry entry : inputMap.getMap().entrySet()) { // Ensure it wasn't caught by the other loop if (!entry.getKey().equals(serverVersion)) { Pair pair = new Pair<>(entry.getKey(), entry.getValue()); diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java index 07b3c5599..1590a4eb8 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java @@ -192,7 +192,7 @@ public abstract class MetadataRewriter { } catch (IllegalArgumentException notFound) { if (!typeMapping.containsKey(oldType.getId())) { Via.getPlatform().getLogger().warning("Could not find new entity type for " + oldType + "! " + - "Old type: " + oldType.getClass().getSimpleName() + " New type: " + newTypeClass.getSimpleName()); + "Old type: " + oldType.getClass().getEnclosingClass().getSimpleName() + ", new type: " + newTypeClass.getEnclosingClass().getSimpleName()); } } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java index 4716d3dd4..a491b76ea 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java @@ -17,18 +17,23 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.PacketBlockConnectionProvider; import us.myles.ViaVersion.util.fastutil.CollectionUtil; +import us.myles.ViaVersion.util.fastutil.IntObjectMap; import us.myles.ViaVersion.util.fastutil.IntSet; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; import java.util.Map.Entry; public class ConnectionData { private static final BlockChangeRecord[] A = new BlockChangeRecord[0]; public static BlockConnectionProvider blockConnectionProvider; - static Map idToKey = new HashMap<>(); - static Map keyToId = new HashMap<>(); - static Map connectionHandlerMap = new HashMap<>(); - static Map blockConnectionData = new HashMap<>(); + static IntObjectMap idToKey = CollectionUtil.createIntObjectMap(8581); + static Map keyToId = new HashMap<>(8581); + static IntObjectMap connectionHandlerMap = CollectionUtil.createIntObjectMap(1); + static IntObjectMap blockConnectionData = CollectionUtil.createIntObjectMap(1); static IntSet occludingStates = CollectionUtil.createIntSet(377); public static void update(UserConnection user, Position position) { @@ -196,17 +201,21 @@ public class ConnectionData { public static void init() { if (!Via.getConfig().isServersideBlockConnections()) return; + Via.getPlatform().getLogger().info("Loading block connection mappings ..."); JsonObject mapping1_13 = MappingDataLoader.loadData("mapping-1.13.json", true); JsonObject blocks1_13 = mapping1_13.getAsJsonObject("blocks"); for (Entry blockState : blocks1_13.entrySet()) { - Integer id = Integer.parseInt(blockState.getKey()); + int id = Integer.parseInt(blockState.getKey()); String key = blockState.getValue().getAsString(); idToKey.put(id, key); keyToId.put(key, id); } + connectionHandlerMap = CollectionUtil.createIntObjectMap(3650); + if (!Via.getConfig().isReduceBlockStorageMemory()) { + blockConnectionData = CollectionUtil.createIntObjectMap(1146); JsonObject mappingBlockConnections = MappingDataLoader.loadData("blockConnections.json"); for (Entry entry : mappingBlockConnections.entrySet()) { int id = keyToId.get(entry.getKey()); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/BlockIdData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/BlockIdData.java index 40585d9bd..49e2ae9ff 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/BlockIdData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/BlockIdData.java @@ -3,6 +3,8 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data; import com.google.common.collect.ObjectArrays; import com.google.gson.reflect.TypeToken; import us.myles.ViaVersion.util.GsonUtil; +import us.myles.ViaVersion.util.fastutil.CollectionUtil; +import us.myles.ViaVersion.util.fastutil.IntObjectMap; import java.io.IOException; import java.io.InputStream; @@ -13,14 +15,14 @@ import java.util.Map; public class BlockIdData { public static Map blockIdMapping; public static Map fallbackReverseMapping; - public static Map numberIdToString; + public static IntObjectMap numberIdToString; public static void init() { InputStream stream = MappingData.class.getClassLoader() .getResourceAsStream("assets/viaversion/data/blockIds1.12to1.13.json"); InputStreamReader reader = new InputStreamReader(stream); try { - blockIdMapping = new HashMap<>((Map) GsonUtil.getGson().fromJson( + blockIdMapping = new HashMap<>(GsonUtil.getGson().fromJson( reader, new TypeToken>() { }.getType() @@ -45,11 +47,11 @@ public class BlockIdData { .getResourceAsStream("assets/viaversion/data/blockNumberToString1.12.json"); InputStreamReader blockR = new InputStreamReader(blockS); try { - numberIdToString = new HashMap<>((Map) GsonUtil.getGson().fromJson( + numberIdToString = CollectionUtil.createIntObjectMap(new HashMap<>(GsonUtil.getGson().fromJson( blockR, new TypeToken>() { }.getType() - )); + ))); } finally { try { blockR.close(); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java new file mode 100644 index 000000000..bb58d6bb7 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java @@ -0,0 +1,102 @@ +package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data; + +import us.myles.ViaVersion.util.fastutil.CollectionUtil; +import us.myles.ViaVersion.util.fastutil.IntMap; + +public class EntityTypeRewriter { + private static final IntMap ENTITY_TYPES = CollectionUtil.createIntMap(93); + + static { + registerEntity(1, 32); // item - ajl + registerEntity(2, 22); // xp_orb - abx + registerEntity(3, 0); // area_effect_cloud - abp + registerEntity(4, 15); // elder_guardian - aju + registerEntity(5, 84); // wither_skeleton - aku + registerEntity(6, 71); // stray - akq + registerEntity(7, 74); // egg - alz + registerEntity(8, 35); // leash_knot - ajb + registerEntity(9, 49); // painting - ajd + registerEntity(10, 2); // arrow - all + registerEntity(11, 67); // snowball - alw + registerEntity(12, 34); // fireball - alq + registerEntity(13, 65); // small_fireball - alv + registerEntity(14, 75); // ender_pearl - ama + registerEntity(15, 23); // eye_of_ender_signal - alo + registerEntity(16, 77); // potion - amc + registerEntity(17, 76); // xp_bottle - amb + registerEntity(18, 33); // item_frame - aja + registerEntity(19, 85); // wither_skull - ame + registerEntity(20, 55); // tnt - ajm + registerEntity(21, 24); // falling_block - ajk + registerEntity(22, 25); // fireworks_rocket - alp + registerEntity(23, 30); // husk - akc + registerEntity(24, 68); // spectral_arrow - alx + registerEntity(25, 60); // shulker_bullet - alu + registerEntity(26, 13); // dragon_fireball - alm + registerEntity(27, 89); // zombie_villager - akw + registerEntity(28, 63); // skeleton_horse - aht + registerEntity(29, 88); // zombie_horse - ahv + registerEntity(30, 1); // armor_stand - aiy + registerEntity(31, 11); // donkey - aho + registerEntity(32, 46); // mule - ahs + registerEntity(33, 20); // evocation_fangs - aln + registerEntity(34, 21); // evocation_illager - ajy + registerEntity(35, 78); // vex - akr + registerEntity(36, 81); // vindication_illager - aks + registerEntity(37, 31); // illusion_illager - akd + registerEntity(40, 41); // commandblock_minecart - aml + registerEntity(41, 5); // boat - ami + registerEntity(42, 39); // minecart - amj + registerEntity(43, 40); // chest_minecart - amk + registerEntity(44, 42); // furnace_minecart - amm + registerEntity(45, 45); // tnt_minecart - amp + registerEntity(46, 43); // hopper_minecart - amn + registerEntity(47, 44); // spawner_minecart - amo + registerEntity(50, 10); // creeper - ajs + registerEntity(51, 62); // skeleton - akm + registerEntity(52, 69); // spider - akp + registerEntity(53, 27); // giant - aka + registerEntity(54, 87); // zombie - akv + registerEntity(55, 64); // slime - akn + registerEntity(56, 26); // ghast - ajz + registerEntity(57, 53); // zombie_pigman - akh + registerEntity(58, 18); // enderman - ajv + registerEntity(59, 6); // cave_spider - ajr + registerEntity(60, 61); // silverfish - akl + registerEntity(61, 4); // blaze - ajq + registerEntity(62, 38); // magma_cube - ake + registerEntity(63, 17); // ender_dragon - aic + registerEntity(64, 83); // wither - aiw + registerEntity(65, 3); // bat - agl + registerEntity(66, 82); // witch - akt + registerEntity(67, 19); // endermite - ajw + registerEntity(68, 28); // guardian - akb + registerEntity(69, 59); // shulker - akk + registerEntity(200, 16); // ender_crystal - aib + registerEntity(90, 51); // pig - agy + registerEntity(91, 58); // sheep - ahd + registerEntity(92, 9); // cow - ags + registerEntity(93, 7); // chicken - agq + registerEntity(94, 70); // squid - ahg + registerEntity(95, 86); // wolf - ahl + registerEntity(96, 47); // mooshroom - agv + registerEntity(97, 66); // snowman - ahf + registerEntity(98, 48); // ocelot - agw + registerEntity(99, 80); // villager_golem - ahj + registerEntity(100, 29); // horse - ahp + registerEntity(101, 56); // rabbit - ahb + registerEntity(102, 54); // polar_bear - agz + registerEntity(103, 36); // llama - ahr + registerEntity(104, 37); // llama_spit - alr + registerEntity(105, 50); // parrot - agx + registerEntity(120, 79); // villager - ala + } + + private static void registerEntity(int type1_12, int type1_13) { + ENTITY_TYPES.put(type1_12, type1_13); + } + + public static int getNewId(int type1_12) { + return ENTITY_TYPES.getOrDefault(type1_12, type1_12); + } +} \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java index 78ef07c8d..ad234da35 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java @@ -1,7 +1,6 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.metadata; import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.api.entities.Entity1_12Types; import us.myles.ViaVersion.api.entities.Entity1_13Types; import us.myles.ViaVersion.api.entities.EntityType; import us.myles.ViaVersion.api.minecraft.item.Item; @@ -11,6 +10,7 @@ import us.myles.ViaVersion.api.rewriters.MetadataRewriter; import us.myles.ViaVersion.api.type.types.Particle; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.EntityTypeRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets; @@ -23,7 +23,6 @@ public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter { public MetadataRewriter1_13To1_12_2(Protocol1_13To1_12_2 protocol) { super(protocol, EntityTracker1_13.class); - mapTypes(Entity1_12Types.EntityType.values(), Entity1_13Types.EntityType.class); } @Override @@ -101,6 +100,11 @@ public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter { // TODO: Boat has changed } + @Override + public int getNewEntityId(final int oldId) { + return EntityTypeRewriter.getNewId(oldId); + } + @Override protected EntityType getTypeFromId(int type) { return Entity1_13Types.getTypeFromId(type, false); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java index 85de84490..5b3c90eff 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java @@ -16,7 +16,7 @@ import java.util.HashMap; import java.util.Map; public class BlockConnectionStorage extends StoredObject { - private static final short[] REVERSE_BLOCK_MAPPINGS = new short[8581]; + private static final short[] REVERSE_BLOCK_MAPPINGS = new short[8582]; private static Constructor fastUtilLongObjectHashMap; private final Map> blockStorage = createLongObjectMap(); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetaIndex.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetaIndex.java index 1f05bc09b..2c5c19c2a 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetaIndex.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetaIndex.java @@ -210,5 +210,4 @@ public enum MetaIndex { return null; } -} - +} \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/CollectionUtil.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/CollectionUtil.java index fa5e7605e..6feebb24e 100644 --- a/common/src/main/java/us/myles/ViaVersion/util/fastutil/CollectionUtil.java +++ b/common/src/main/java/us/myles/ViaVersion/util/fastutil/CollectionUtil.java @@ -1,11 +1,8 @@ package us.myles.ViaVersion.util.fastutil; -import it.unimi.dsi.fastutil.ints.Int2IntMap; -import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; -import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import com.google.common.base.Preconditions; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -14,9 +11,9 @@ import java.util.Set; * These should only be used for high access and low/no change collections, since resizing FastUtil collections is expensive. */ public class CollectionUtil { - private static final boolean FAST_UTIL = hasFastUtil(); + private static final boolean FAST_UTIL = checkForFastUtil(); - private static boolean hasFastUtil() { + private static boolean checkForFastUtil() { try { Class.forName("Int2IntMap"); return true; @@ -32,7 +29,8 @@ public class CollectionUtil { * @return wrapped int map */ public static IntMap createIntMap(Map originalMap) { - return FAST_UTIL ? new WrappedFUIntMap(new Int2IntOpenHashMap(originalMap)) : new WrappedIntMap(originalMap); + Preconditions.checkNotNull(originalMap); + return FAST_UTIL ? new WrappedFUIntMap(originalMap) : new WrappedIntMap(originalMap); } /** @@ -42,11 +40,32 @@ public class CollectionUtil { * @return wrapped int map */ public static IntMap createIntMap(int size) { - return FAST_UTIL ? new WrappedFUIntMap(new Int2IntOpenHashMap(size)) : new WrappedIntMap(new HashMap<>(size)); + return FAST_UTIL ? new WrappedFUIntMap(size) : new WrappedIntMap(size); } public static IntMap createIntMap() { - return FAST_UTIL ? new WrappedFUIntMap(new Int2IntOpenHashMap()) : new WrappedIntMap(new HashMap<>()); + return FAST_UTIL ? new WrappedFUIntMap(16) : new WrappedIntMap(new HashMap<>()); + } + + /** + * Creates a new FastUtil collection from the given map if present, else simply wraps the original. + * + * @param originalMap map to be reflected + * @return wrapped int map + */ + public static IntObjectMap createIntObjectMap(Map originalMap) { + Preconditions.checkNotNull(originalMap); + return FAST_UTIL ? new WrappedFUIntObjectMap<>(originalMap) : new WrappedIntObjectMap<>(originalMap); + } + + /** + * Creates a new FastUtil collection if present, else simply wraps a normal HashMap. + * + * @param size expected size of the collection + * @return wrapped int map + */ + public static IntObjectMap createIntObjectMap(int size) { + return FAST_UTIL ? new WrappedFUIntObjectMap<>(size) : new WrappedIntObjectMap<>(size); } /** @@ -56,7 +75,8 @@ public class CollectionUtil { * @return wrapped int set */ public static IntSet createIntSet(Set originalSet) { - return FAST_UTIL ? new WrappedFUIntSet(new IntOpenHashSet(originalSet)) : new WrappedIntSet(originalSet); + Preconditions.checkNotNull(originalSet); + return FAST_UTIL ? new WrappedFUIntSet(originalSet) : new WrappedIntSet(originalSet); } /** @@ -66,108 +86,10 @@ public class CollectionUtil { * @return wrapped int set */ public static IntSet createIntSet(int size) { - return FAST_UTIL ? new WrappedFUIntSet(new IntOpenHashSet(size)) : new WrappedIntSet(new HashSet<>(size)); + return FAST_UTIL ? new WrappedFUIntSet(size) : new WrappedIntSet(size); } - private static final class WrappedFUIntMap implements IntMap { - private final Int2IntMap map; - - private WrappedFUIntMap(Int2IntMap map) { - this.map = map; - } - - @Override - public int getOrDefault(int key, int def) { - return map.getOrDefault(key, def); - } - - @Override - public boolean containsKey(int key) { - return map.containsKey(key); - } - - @Override - public int put(int key, int value) { - return map.put(key, value); - } - - @Override - public int remove(int key) { - return map.remove(key); - } - } - - private static final class WrappedIntMap implements IntMap { - private final Map map; - - private WrappedIntMap(Map map) { - this.map = map; - } - - @Override - public int getOrDefault(int key, int def) { - return map.getOrDefault(key, def); - } - - @Override - public boolean containsKey(int key) { - return map.containsKey(key); - } - - @Override - public int put(int key, int value) { - return map.put(key, value); - } - - @Override - public int remove(int key) { - return map.remove(key); - } - } - - private static final class WrappedFUIntSet implements IntSet { - private final it.unimi.dsi.fastutil.ints.IntSet set; - - private WrappedFUIntSet(it.unimi.dsi.fastutil.ints.IntSet set) { - this.set = set; - } - - @Override - public boolean contains(int key) { - return set.contains(key); - } - - @Override - public boolean add(int key) { - return set.add(key); - } - - @Override - public boolean remove(int key) { - return set.remove(key); - } - } - - private static final class WrappedIntSet implements IntSet { - private final Set set; - - private WrappedIntSet(Set set) { - this.set = set; - } - - @Override - public boolean contains(int key) { - return set.contains(key); - } - - @Override - public boolean add(int key) { - return set.add(key); - } - - @Override - public boolean remove(int key) { - return set.remove(key); - } + public static boolean hasFastUtil() { + return FAST_UTIL; } } diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntMap.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntMap.java index 060b25c8b..54237aaed 100644 --- a/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntMap.java +++ b/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntMap.java @@ -14,7 +14,7 @@ public interface IntMap { } /** - * @see java.util.HashMap#getOrDefault(Object, Object) (Object) + * @see java.util.HashMap#getOrDefault(Object, Object) */ int getOrDefault(int key, int def); diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntObjectMap.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntObjectMap.java new file mode 100644 index 000000000..e7095151a --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntObjectMap.java @@ -0,0 +1,51 @@ +package us.myles.ViaVersion.util.fastutil; + +import org.jetbrains.annotations.Nullable; + +import java.util.Map; + +/** + * Very simple wrapping interface to either be implemented by a HashMap or FastUtil's OpenHashMap. + * + * @param Object value type + */ +public interface IntObjectMap { + + /** + * @see java.util.HashMap#get(Object) + */ + @Nullable + V get(int key); + + /** + * @see java.util.HashMap#getOrDefault(Object, Object) + */ + @Nullable + V getOrDefault(int key, V def); + + /** + * @see java.util.HashMap#containsKey(Object) + */ + boolean containsKey(int key); + + /** + * @see java.util.HashMap#put(Object, Object) + */ + @Nullable + V put(int key, V value); + + /** + * @see java.util.HashMap#remove(Object) + */ + @Nullable + V remove(int key); + + /** + * Returns the underlying map for usage of not implemented methods of this class. + * + * @return original map + * @deprecated will cause wrapping if it is a FastUtil collection + */ + @Deprecated + Map getMap(); +} diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntMap.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntMap.java new file mode 100644 index 000000000..349719378 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntMap.java @@ -0,0 +1,38 @@ +package us.myles.ViaVersion.util.fastutil; + +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; + +import java.util.Map; + +final class WrappedFUIntMap implements IntMap { + private final Int2IntMap map; + + WrappedFUIntMap(Map originalMap) { + this.map = new Int2IntOpenHashMap(originalMap); + } + + WrappedFUIntMap(int size) { + this.map = new Int2IntOpenHashMap(size); + } + + @Override + public int getOrDefault(int key, int def) { + return map.getOrDefault(key, def); + } + + @Override + public boolean containsKey(int key) { + return map.containsKey(key); + } + + @Override + public int put(int key, int value) { + return map.put(key, value); + } + + @Override + public int remove(int key) { + return map.remove(key); + } +} \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntObjectMap.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntObjectMap.java new file mode 100644 index 000000000..175aeb50c --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntObjectMap.java @@ -0,0 +1,48 @@ +package us.myles.ViaVersion.util.fastutil; + +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; + +import java.util.Map; + +final class WrappedFUIntObjectMap implements IntObjectMap { + private final Int2ObjectMap map; + + WrappedFUIntObjectMap(Map originalMap) { + this.map = new Int2ObjectOpenHashMap<>(originalMap); + } + + WrappedFUIntObjectMap(int size) { + this.map = new Int2ObjectOpenHashMap(size); + } + + @Override + public V get(int key) { + return map.get(key); + } + + @Override + public V getOrDefault(int key, V def) { + return map.getOrDefault(key, def); + } + + @Override + public boolean containsKey(int key) { + return map.containsKey(key); + } + + @Override + public V put(int key, V value) { + return map.put(key, value); + } + + @Override + public V remove(int key) { + return map.remove(key); + } + + @Override + public Map getMap() { + return map; + } +} \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntSet.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntSet.java new file mode 100644 index 000000000..315ee6b17 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntSet.java @@ -0,0 +1,32 @@ +package us.myles.ViaVersion.util.fastutil; + +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; + +import java.util.Set; + +final class WrappedFUIntSet implements IntSet { + private final it.unimi.dsi.fastutil.ints.IntSet set; + + WrappedFUIntSet(Set originalSet) { + this.set = new IntOpenHashSet(originalSet); + } + + WrappedFUIntSet(int size) { + this.set = new IntOpenHashSet(size); + } + + @Override + public boolean contains(int key) { + return set.contains(key); + } + + @Override + public boolean add(int key) { + return set.add(key); + } + + @Override + public boolean remove(int key) { + return set.remove(key); + } +} \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntMap.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntMap.java new file mode 100644 index 000000000..54c0af8cf --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntMap.java @@ -0,0 +1,37 @@ +package us.myles.ViaVersion.util.fastutil; + +import java.util.HashMap; +import java.util.Map; + +final class WrappedIntMap implements IntMap { + private final Map map; + + WrappedIntMap(Map originalMap) { + this.map = originalMap; + } + + WrappedIntMap(int size) { + this.map = new HashMap<>(size); + } + + @Override + public int getOrDefault(int key, int def) { + return map.getOrDefault(key, def); + } + + @Override + public boolean containsKey(int key) { + return map.containsKey(key); + } + + @Override + public int put(int key, int value) { + Integer oldValue = map.put(key, value); + return oldValue != null ? oldValue : -1; + } + + @Override + public int remove(int key) { + return map.remove(key); + } +} diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntObjectMap.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntObjectMap.java new file mode 100644 index 000000000..34e6ac61c --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntObjectMap.java @@ -0,0 +1,46 @@ +package us.myles.ViaVersion.util.fastutil; + +import java.util.HashMap; +import java.util.Map; + +final class WrappedIntObjectMap implements IntObjectMap { + private final Map map; + + WrappedIntObjectMap(Map originalMap) { + this.map = originalMap; + } + + WrappedIntObjectMap(int size) { + this.map = new HashMap<>(size); + } + + @Override + public V get(int key) { + return map.get(key); + } + + @Override + public V getOrDefault(int key, V def) { + return map.getOrDefault(key, def); + } + + @Override + public boolean containsKey(int key) { + return map.containsKey(key); + } + + @Override + public V put(int key, V value) { + return map.put(key, value); + } + + @Override + public V remove(int key) { + return map.remove(key); + } + + @Override + public Map getMap() { + return map; + } +} \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntSet.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntSet.java new file mode 100644 index 000000000..1730e195c --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntSet.java @@ -0,0 +1,31 @@ +package us.myles.ViaVersion.util.fastutil; + +import java.util.HashSet; +import java.util.Set; + +final class WrappedIntSet implements IntSet { + private final Set set; + + WrappedIntSet(Set originalSet) { + this.set = originalSet; + } + + WrappedIntSet(int size) { + this.set = new HashSet<>(size); + } + + @Override + public boolean contains(int key) { + return set.contains(key); + } + + @Override + public boolean add(int key) { + return set.add(key); + } + + @Override + public boolean remove(int key) { + return set.remove(key); + } +} From 623cdaf881ec653d3bf4419f6242cb6a514eff36 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Mon, 8 Jun 2020 14:23:11 +0200 Subject: [PATCH 3/9] Getter for original map in IntMap --- .../blockconnections/ConnectionData.java | 4 ++-- .../us/myles/ViaVersion/util/fastutil/IntMap.java | 11 +++++++++++ .../ViaVersion/util/fastutil/WrappedFUIntMap.java | 5 +++++ .../myles/ViaVersion/util/fastutil/WrappedIntMap.java | 8 +++++++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java index a491b76ea..5aa77d1a4 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java @@ -30,8 +30,8 @@ import java.util.Map.Entry; public class ConnectionData { private static final BlockChangeRecord[] A = new BlockChangeRecord[0]; public static BlockConnectionProvider blockConnectionProvider; - static IntObjectMap idToKey = CollectionUtil.createIntObjectMap(8581); - static Map keyToId = new HashMap<>(8581); + static IntObjectMap idToKey = CollectionUtil.createIntObjectMap(8582); + static Map keyToId = new HashMap<>(8582); static IntObjectMap connectionHandlerMap = CollectionUtil.createIntObjectMap(1); static IntObjectMap blockConnectionData = CollectionUtil.createIntObjectMap(1); static IntSet occludingStates = CollectionUtil.createIntSet(377); diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntMap.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntMap.java index 54237aaed..9498e7360 100644 --- a/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntMap.java +++ b/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntMap.java @@ -1,5 +1,7 @@ package us.myles.ViaVersion.util.fastutil; +import java.util.Map; + /** * Very simple wrapping interface to either be implemented by a HashMap or FastUtil's OpenHashMap. */ @@ -32,4 +34,13 @@ public interface IntMap { * @see java.util.HashMap#remove(Object) */ int remove(int key); + + /** + * Returns the underlying map for usage of not implemented methods of this class. + * + * @return original map + * @deprecated will cause wrapping if it is a FastUtil collection + */ + @Deprecated + Map getMap(); } diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntMap.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntMap.java index 349719378..fd10fa3a4 100644 --- a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntMap.java +++ b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntMap.java @@ -35,4 +35,9 @@ final class WrappedFUIntMap implements IntMap { public int remove(int key) { return map.remove(key); } + + @Override + public Map getMap() { + return map; + } } \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntMap.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntMap.java index 54c0af8cf..483a1f9d3 100644 --- a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntMap.java +++ b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntMap.java @@ -32,6 +32,12 @@ final class WrappedIntMap implements IntMap { @Override public int remove(int key) { - return map.remove(key); + Integer removed = map.remove(key); + return removed != null ? removed : -1; + } + + @Override + public Map getMap() { + return map; } } From 39cb8fd554c4963adb1baf6db1d011df796d8403 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Mon, 8 Jun 2020 15:58:10 +0200 Subject: [PATCH 4/9] Fix FU check --- .../java/us/myles/ViaVersion/util/fastutil/CollectionUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/CollectionUtil.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/CollectionUtil.java index 6feebb24e..b4164a01b 100644 --- a/common/src/main/java/us/myles/ViaVersion/util/fastutil/CollectionUtil.java +++ b/common/src/main/java/us/myles/ViaVersion/util/fastutil/CollectionUtil.java @@ -15,7 +15,7 @@ public class CollectionUtil { private static boolean checkForFastUtil() { try { - Class.forName("Int2IntMap"); + Class.forName("it.unimi.dsi.fastutil.ints.Int2IntMap"); return true; } catch (ClassNotFoundException e) { return false; From 8188ae09f59a5f52543d8bc66d576f43822d17bd Mon Sep 17 00:00:00 2001 From: KennyTV Date: Mon, 8 Jun 2020 22:23:24 +0200 Subject: [PATCH 5/9] Use proper FU classes, shade dumbed down version --- common/pom.xml | 4 +- .../api/protocol/ProtocolRegistry.java | 51 +++++----- .../api/rewriters/MetadataRewriter.java | 10 +- .../blockconnections/ConnectionData.java | 19 ++-- .../FlowerConnectionHandler.java | 5 +- .../RedstoneConnectionHandler.java | 7 +- .../data/BlockIdData.java | 10 +- .../data/EntityTypeRewriter.java | 5 +- .../packets/WorldPackets.java | 6 +- .../storage/BlockStorage.java | 6 +- .../data/MappingData.java | 8 +- .../protocol1_9to1_8/ItemRewriter.java | 12 +-- .../protocol1_9to1_8/sounds/Effect.java | 6 +- .../util/fastutil/CollectionUtil.java | 95 ------------------- .../ViaVersion/util/fastutil/IntMap.java | 46 --------- .../util/fastutil/IntObjectMap.java | 51 ---------- .../ViaVersion/util/fastutil/IntSet.java | 22 ----- .../util/fastutil/WrappedFUIntMap.java | 43 --------- .../util/fastutil/WrappedFUIntObjectMap.java | 48 ---------- .../util/fastutil/WrappedFUIntSet.java | 32 ------- .../util/fastutil/WrappedIntMap.java | 43 --------- .../util/fastutil/WrappedIntObjectMap.java | 46 --------- .../util/fastutil/WrappedIntSet.java | 31 ------ jar/pom.xml | 37 ++++++++ 24 files changed, 110 insertions(+), 533 deletions(-) delete mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/CollectionUtil.java delete mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/IntMap.java delete mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/IntObjectMap.java delete mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/IntSet.java delete mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntMap.java delete mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntObjectMap.java delete mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntSet.java delete mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntMap.java delete mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntObjectMap.java delete mode 100644 common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntSet.java diff --git a/common/pom.xml b/common/pom.xml index 4d79ce92a..d190028ee 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -20,12 +20,12 @@ compile - + it.unimi.dsi fastutil 8.3.1 - provided + compile diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java index 4d7929359..1880d3ad6 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java @@ -2,6 +2,8 @@ package us.myles.ViaVersion.api.protocol; import com.google.common.collect.Lists; import com.google.common.collect.Range; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Via; @@ -31,8 +33,6 @@ import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1To1_9; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.Protocol1_9_3To1_9_1_2; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_9_1.Protocol1_9To1_9_1; -import us.myles.ViaVersion.util.fastutil.CollectionUtil; -import us.myles.ViaVersion.util.fastutil.IntObjectMap; import java.util.ArrayList; import java.util.Arrays; @@ -54,7 +54,7 @@ public class ProtocolRegistry { public static final Protocol BASE_PROTOCOL = new BaseProtocol(); public static int SERVER_PROTOCOL = -1; // Input Version -> Output Version & Protocol (Allows fast lookup) - private static final IntObjectMap> registryMap = CollectionUtil.createIntObjectMap(32); + private static final Int2ObjectMap> registryMap = new Int2ObjectOpenHashMap<>(32); private static final Map, Protocol> protocols = new HashMap<>(); private static final Map, List>> pathCache = new ConcurrentHashMap<>(); private static final Set supportedVersions = new HashSet<>(); @@ -128,7 +128,7 @@ public class ProtocolRegistry { * @param supported Supported client versions. * @param output The output server version it converts to. */ - public static void registerProtocol(Protocol protocol, List supported, Integer output) { + public static void registerProtocol(Protocol protocol, List supported, int output) { // Clear cache as this may make new routes. if (!pathCache.isEmpty()) { pathCache.clear(); @@ -137,9 +137,9 @@ public class ProtocolRegistry { protocols.put(protocol.getClass(), protocol); for (int version : supported) { - IntObjectMap protocolMap = registryMap.get(version); + Int2ObjectMap protocolMap = registryMap.get(version); if (protocolMap == null) { - protocolMap = CollectionUtil.createIntObjectMap(1); + protocolMap = new Int2ObjectOpenHashMap<>(1); registryMap.put(version, protocolMap); } @@ -211,8 +211,8 @@ public class ProtocolRegistry { * @return True if there is a useful pipe */ public static boolean isWorkingPipe() { - for (IntObjectMap maps : registryMap.getMap().values()) { - if (maps.containsKey(SERVER_PROTOCOL)) return true; + for (Int2ObjectMap map : registryMap.values()) { + if (map.containsKey(SERVER_PROTOCOL)) return true; } return false; // No destination for protocol } @@ -241,7 +241,7 @@ public class ProtocolRegistry { if (current.size() > 50) return null; // Fail safe, protocol too complicated. // First check if there is any protocols for this - IntObjectMap inputMap = registryMap.get(clientVersion); + Int2ObjectMap inputMap = registryMap.get(clientVersion); if (inputMap == null) { return null; // Not supported } @@ -255,24 +255,23 @@ public class ProtocolRegistry { // There might be a more advanced solution... So we'll see if any of the others can get us there List> shortest = null; - - for (Map.Entry entry : inputMap.getMap().entrySet()) { + for (Int2ObjectMap.Entry entry : inputMap.int2ObjectEntrySet()) { // Ensure it wasn't caught by the other loop - if (!entry.getKey().equals(serverVersion)) { - Pair pair = new Pair<>(entry.getKey(), entry.getValue()); - // Ensure no recursion - if (!current.contains(pair)) { - // Create a copy - List> newCurrent = new ArrayList<>(current); - newCurrent.add(pair); - // Calculate the rest of the protocol using the current - newCurrent = getProtocolPath(newCurrent, entry.getKey(), serverVersion); - if (newCurrent != null) { - // If it's shorter then choose it - if (shortest == null || shortest.size() > newCurrent.size()) { - shortest = newCurrent; - } - } + if (entry.getIntKey() == (serverVersion)) continue; + + Pair pair = new Pair<>(entry.getIntKey(), entry.getValue()); + // Ensure no recursion + if (current.contains(pair)) continue; + + // Create a copy + List> newCurrent = new ArrayList<>(current); + newCurrent.add(pair); + // Calculate the rest of the protocol using the current + newCurrent = getProtocolPath(newCurrent, entry.getKey(), serverVersion); + if (newCurrent != null) { + // If it's shorter then choose it + if (shortest == null || shortest.size() > newCurrent.size()) { + shortest = newCurrent; } } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java index 1590a4eb8..d32532f54 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java @@ -1,5 +1,7 @@ package us.myles.ViaVersion.api.rewriters; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; @@ -12,8 +14,6 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.storage.EntityTracker; import us.myles.ViaVersion.api.type.Type; 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 java.util.ArrayList; import java.util.Collections; @@ -25,7 +25,7 @@ import java.util.logging.Logger; public abstract class MetadataRewriter { private final Class entityTrackerClass; private final Protocol protocol; - private IntMap typeMapping; + private Int2IntMap typeMapping; protected MetadataRewriter(Protocol protocol, Class entityTrackerClass) { this.protocol = protocol; @@ -184,7 +184,7 @@ public abstract class MetadataRewriter { } public & EntityType> void mapTypes(EntityType[] oldTypes, Class newTypeClass) { - if (typeMapping == null) typeMapping = CollectionUtil.createIntMap(oldTypes.length); + if (typeMapping == null) typeMapping = new Int2IntOpenHashMap(oldTypes.length); for (EntityType oldType : oldTypes) { try { T newType = Enum.valueOf(newTypeClass, oldType.name()); @@ -199,7 +199,7 @@ public abstract class MetadataRewriter { } public void mapType(EntityType oldType, EntityType newType) { - if (typeMapping == null) typeMapping = CollectionUtil.createIntMap(); + if (typeMapping == null) typeMapping = new Int2IntOpenHashMap(); typeMapping.put(oldType.getId(), newType.getId()); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java index 5aa77d1a4..c2f8ac3a4 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java @@ -3,6 +3,10 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.MappingDataLoader; @@ -16,9 +20,6 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.PacketBlockConnectionProvider; -import us.myles.ViaVersion.util.fastutil.CollectionUtil; -import us.myles.ViaVersion.util.fastutil.IntObjectMap; -import us.myles.ViaVersion.util.fastutil.IntSet; import java.util.ArrayList; import java.util.HashMap; @@ -30,11 +31,11 @@ import java.util.Map.Entry; public class ConnectionData { private static final BlockChangeRecord[] A = new BlockChangeRecord[0]; public static BlockConnectionProvider blockConnectionProvider; - static IntObjectMap idToKey = CollectionUtil.createIntObjectMap(8582); + static Int2ObjectMap idToKey = new Int2ObjectOpenHashMap<>(8582); static Map keyToId = new HashMap<>(8582); - static IntObjectMap connectionHandlerMap = CollectionUtil.createIntObjectMap(1); - static IntObjectMap blockConnectionData = CollectionUtil.createIntObjectMap(1); - static IntSet occludingStates = CollectionUtil.createIntSet(377); + static Int2ObjectMap connectionHandlerMap = new Int2ObjectOpenHashMap<>(1); + static Int2ObjectMap blockConnectionData = new Int2ObjectOpenHashMap<>(1); + static IntSet occludingStates = new IntOpenHashSet(377); public static void update(UserConnection user, Position position) { for (BlockFace face : BlockFace.values()) { @@ -212,10 +213,10 @@ public class ConnectionData { keyToId.put(key, id); } - connectionHandlerMap = CollectionUtil.createIntObjectMap(3650); + connectionHandlerMap = new Int2ObjectOpenHashMap<>(3650); if (!Via.getConfig().isReduceBlockStorageMemory()) { - blockConnectionData = CollectionUtil.createIntObjectMap(1146); + blockConnectionData = new Int2ObjectOpenHashMap<>(1146); JsonObject mappingBlockConnections = MappingDataLoader.loadData("blockConnections.json"); for (Entry entry : mappingBlockConnections.entrySet()) { int id = keyToId.get(entry.getKey()); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/FlowerConnectionHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/FlowerConnectionHandler.java index 14eac24c9..801a7d63d 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/FlowerConnectionHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/FlowerConnectionHandler.java @@ -1,18 +1,17 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.minecraft.BlockFace; import us.myles.ViaVersion.api.minecraft.Position; -import us.myles.ViaVersion.util.fastutil.CollectionUtil; -import us.myles.ViaVersion.util.fastutil.IntMap; import java.util.HashSet; import java.util.Set; public class FlowerConnectionHandler extends ConnectionHandler { - private static final IntMap flowers = CollectionUtil.createIntMap(); + private static final Int2IntOpenHashMap flowers = new Int2IntOpenHashMap(); static ConnectionData.ConnectorInitAction init() { final Set baseFlower = new HashSet<>(); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java index a09528880..918691470 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java @@ -1,18 +1,17 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.minecraft.BlockFace; import us.myles.ViaVersion.api.minecraft.Position; -import us.myles.ViaVersion.util.fastutil.CollectionUtil; -import us.myles.ViaVersion.util.fastutil.IntMap; import java.util.HashSet; import java.util.Set; public class RedstoneConnectionHandler extends ConnectionHandler { private static final Set redstone = new HashSet<>(); - private static final IntMap connectedBlockStates = CollectionUtil.createIntMap(1296); - private static final IntMap powerMappings = CollectionUtil.createIntMap(1296); + private static final Int2IntOpenHashMap connectedBlockStates = new Int2IntOpenHashMap(1296); + private static final Int2IntOpenHashMap powerMappings = new Int2IntOpenHashMap(1296); static ConnectionData.ConnectorInitAction init() { final RedstoneConnectionHandler connectionHandler = new RedstoneConnectionHandler(); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/BlockIdData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/BlockIdData.java index 49e2ae9ff..b1e547384 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/BlockIdData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/BlockIdData.java @@ -2,9 +2,9 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data; import com.google.common.collect.ObjectArrays; import com.google.gson.reflect.TypeToken; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import us.myles.ViaVersion.util.GsonUtil; -import us.myles.ViaVersion.util.fastutil.CollectionUtil; -import us.myles.ViaVersion.util.fastutil.IntObjectMap; import java.io.IOException; import java.io.InputStream; @@ -15,7 +15,7 @@ import java.util.Map; public class BlockIdData { public static Map blockIdMapping; public static Map fallbackReverseMapping; - public static IntObjectMap numberIdToString; + public static Int2ObjectMap numberIdToString; public static void init() { InputStream stream = MappingData.class.getClassLoader() @@ -47,11 +47,11 @@ public class BlockIdData { .getResourceAsStream("assets/viaversion/data/blockNumberToString1.12.json"); InputStreamReader blockR = new InputStreamReader(blockS); try { - numberIdToString = CollectionUtil.createIntObjectMap(new HashMap<>(GsonUtil.getGson().fromJson( + numberIdToString = new Int2ObjectOpenHashMap<>(GsonUtil.getGson().fromJson( blockR, new TypeToken>() { }.getType() - ))); + )); } finally { try { blockR.close(); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java index bb58d6bb7..856472b5e 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java @@ -1,10 +1,9 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data; -import us.myles.ViaVersion.util.fastutil.CollectionUtil; -import us.myles.ViaVersion.util.fastutil.IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; public class EntityTypeRewriter { - private static final IntMap ENTITY_TYPES = CollectionUtil.createIntMap(93); + private static final Int2IntOpenHashMap ENTITY_TYPES = new Int2IntOpenHashMap(93); static { registerEntity(1, 32); // item - ajl diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java index 1ffc37a6b..d57925314 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java @@ -1,6 +1,8 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; @@ -26,14 +28,12 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.BlockStorage; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type; 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.util.fastutil.CollectionUtil; -import us.myles.ViaVersion.util.fastutil.IntSet; import java.util.List; import java.util.Optional; public class WorldPackets { - private static final IntSet VALID_BIOMES = CollectionUtil.createIntSet(70); + private static final IntSet VALID_BIOMES = new IntOpenHashSet(70); static { // Client will crash if it receives a invalid biome id diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java index 94e9fcaa9..4f032b8c9 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java @@ -1,16 +1,16 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; 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 java.util.Map; import java.util.concurrent.ConcurrentHashMap; public class BlockStorage extends StoredObject { - private static final IntSet WHITELIST = CollectionUtil.createIntSet(46); + private static final IntSet WHITELIST = new IntOpenHashSet(46); private final Map blocks = new ConcurrentHashMap<>(); static { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java index eec379699..202edeb12 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java @@ -5,11 +5,11 @@ import com.google.common.collect.HashBiMap; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.Mappings; -import us.myles.ViaVersion.util.fastutil.CollectionUtil; -import us.myles.ViaVersion.util.fastutil.IntSet; import java.util.HashMap; import java.util.Map; @@ -40,7 +40,7 @@ public class MappingData { JsonObject heightMapData = MappingDataLoader.loadData("heightMapData-1.14.json"); JsonArray motionBlocking = heightMapData.getAsJsonArray("MOTION_BLOCKING"); - MappingData.motionBlocking = CollectionUtil.createIntSet(motionBlocking.size()); + MappingData.motionBlocking = new IntOpenHashSet(motionBlocking.size()); for (JsonElement blockState : motionBlocking) { String key = blockState.getAsString(); Integer id = blockStateMap.get(key); @@ -52,7 +52,7 @@ public class MappingData { } if (Via.getConfig().isNonFullBlockLightFix()) { - nonFullBlocks = CollectionUtil.createIntSet(1611); + nonFullBlocks = new IntOpenHashSet(1611); for (Map.Entry blockstates : mapping1_13_2.getAsJsonObject("blockstates").entrySet()) { final String state = blockstates.getValue().getAsString(); if (state.contains("_slab") || state.contains("_stairs") || state.contains("_wall[")) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java index 659a3ac02..2aa6d4ef3 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java @@ -4,9 +4,9 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.Tag; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import us.myles.ViaVersion.api.minecraft.item.Item; -import us.myles.ViaVersion.util.fastutil.CollectionUtil; -import us.myles.ViaVersion.util.fastutil.IntMap; import java.util.Collections; import java.util.HashMap; @@ -19,7 +19,7 @@ public class ItemRewriter { private static final Map POTION_NAME_TO_ID = new HashMap<>(); private static final Map POTION_ID_TO_NAME = new HashMap<>(); - private static final IntMap POTION_INDEX = CollectionUtil.createIntMap(36); + private static final Int2IntMap POTION_INDEX = new Int2IntOpenHashMap(36); static { /* Entities */ @@ -220,7 +220,7 @@ public class ItemRewriter { return str; } // hacky but it works :) - str = "\u00A7r" + str; + str = "§r" + str; return str; } @@ -392,12 +392,12 @@ public class ItemRewriter { return (index = POTION_INDEX.get(oldID)) != -1 ? index : 0; } - private static void registerEntity(Integer id, String name) { + private static void registerEntity(int id, String name) { ENTTIY_ID_TO_NAME.put(id, name); ENTTIY_NAME_TO_ID.put(name, id); } - private static void registerPotion(Integer id, String name) { + private static void registerPotion(int id, String name) { POTION_INDEX.put(id, POTION_ID_TO_NAME.size()); POTION_ID_TO_NAME.put(id, name); POTION_NAME_TO_ID.put(name, id); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/Effect.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/Effect.java index dd0a5a115..4884f6c1c 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/Effect.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/Effect.java @@ -1,11 +1,11 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds; -import us.myles.ViaVersion.util.fastutil.CollectionUtil; -import us.myles.ViaVersion.util.fastutil.IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; public class Effect { - private static final IntMap EFFECTS = CollectionUtil.createIntMap(17); + private static final Int2IntMap EFFECTS = new Int2IntOpenHashMap(17); static { addRewrite(1005, 1010); //Play music disc diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/CollectionUtil.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/CollectionUtil.java deleted file mode 100644 index b4164a01b..000000000 --- a/common/src/main/java/us/myles/ViaVersion/util/fastutil/CollectionUtil.java +++ /dev/null @@ -1,95 +0,0 @@ -package us.myles.ViaVersion.util.fastutil; - -import com.google.common.base.Preconditions; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -/** - * Utility class to possibly wrap FastUtil collections for faster access. - * These should only be used for high access and low/no change collections, since resizing FastUtil collections is expensive. - */ -public class CollectionUtil { - private static final boolean FAST_UTIL = checkForFastUtil(); - - private static boolean checkForFastUtil() { - try { - Class.forName("it.unimi.dsi.fastutil.ints.Int2IntMap"); - return true; - } catch (ClassNotFoundException e) { - return false; - } - } - - /** - * Creates a new FastUtil collection from the given map if present, else simply wraps the original. - * - * @param originalMap map to be reflected - * @return wrapped int map - */ - public static IntMap createIntMap(Map originalMap) { - Preconditions.checkNotNull(originalMap); - return FAST_UTIL ? new WrappedFUIntMap(originalMap) : new WrappedIntMap(originalMap); - } - - /** - * Creates a new FastUtil collection if present, else simply wraps a normal HashMap. - * - * @param size expected size of the collection - * @return wrapped int map - */ - public static IntMap createIntMap(int size) { - return FAST_UTIL ? new WrappedFUIntMap(size) : new WrappedIntMap(size); - } - - public static IntMap createIntMap() { - return FAST_UTIL ? new WrappedFUIntMap(16) : new WrappedIntMap(new HashMap<>()); - } - - /** - * Creates a new FastUtil collection from the given map if present, else simply wraps the original. - * - * @param originalMap map to be reflected - * @return wrapped int map - */ - public static IntObjectMap createIntObjectMap(Map originalMap) { - Preconditions.checkNotNull(originalMap); - return FAST_UTIL ? new WrappedFUIntObjectMap<>(originalMap) : new WrappedIntObjectMap<>(originalMap); - } - - /** - * Creates a new FastUtil collection if present, else simply wraps a normal HashMap. - * - * @param size expected size of the collection - * @return wrapped int map - */ - public static IntObjectMap createIntObjectMap(int size) { - return FAST_UTIL ? new WrappedFUIntObjectMap<>(size) : new WrappedIntObjectMap<>(size); - } - - /** - * Creates a new FastUtil collection from the given set if present, else simply wraps the original. - * - * @param originalSet set to be reflected - * @return wrapped int set - */ - public static IntSet createIntSet(Set originalSet) { - Preconditions.checkNotNull(originalSet); - return FAST_UTIL ? new WrappedFUIntSet(originalSet) : new WrappedIntSet(originalSet); - } - - /** - * Creates a new FastUtil collection if present, else simply wraps a normal HashSet. - * - * @param size expected size of the collection - * @return wrapped int set - */ - public static IntSet createIntSet(int size) { - return FAST_UTIL ? new WrappedFUIntSet(size) : new WrappedIntSet(size); - } - - public static boolean hasFastUtil() { - return FAST_UTIL; - } -} diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntMap.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntMap.java deleted file mode 100644 index 9498e7360..000000000 --- a/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntMap.java +++ /dev/null @@ -1,46 +0,0 @@ -package us.myles.ViaVersion.util.fastutil; - -import java.util.Map; - -/** - * Very simple wrapping interface to either be implemented by a HashMap or FastUtil's OpenHashMap. - */ -public interface IntMap { - - /** - * @return value if present, -1 otherwise - * @see java.util.HashMap#get(Object) - */ - default int get(int key) { - return getOrDefault(key, -1); - } - - /** - * @see java.util.HashMap#getOrDefault(Object, Object) - */ - int getOrDefault(int key, int def); - - /** - * @see java.util.HashMap#containsKey(Object) - */ - boolean containsKey(int key); - - /** - * @see java.util.HashMap#put(Object, Object) - */ - int put(int key, int value); - - /** - * @see java.util.HashMap#remove(Object) - */ - int remove(int key); - - /** - * Returns the underlying map for usage of not implemented methods of this class. - * - * @return original map - * @deprecated will cause wrapping if it is a FastUtil collection - */ - @Deprecated - Map getMap(); -} diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntObjectMap.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntObjectMap.java deleted file mode 100644 index e7095151a..000000000 --- a/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntObjectMap.java +++ /dev/null @@ -1,51 +0,0 @@ -package us.myles.ViaVersion.util.fastutil; - -import org.jetbrains.annotations.Nullable; - -import java.util.Map; - -/** - * Very simple wrapping interface to either be implemented by a HashMap or FastUtil's OpenHashMap. - * - * @param Object value type - */ -public interface IntObjectMap { - - /** - * @see java.util.HashMap#get(Object) - */ - @Nullable - V get(int key); - - /** - * @see java.util.HashMap#getOrDefault(Object, Object) - */ - @Nullable - V getOrDefault(int key, V def); - - /** - * @see java.util.HashMap#containsKey(Object) - */ - boolean containsKey(int key); - - /** - * @see java.util.HashMap#put(Object, Object) - */ - @Nullable - V put(int key, V value); - - /** - * @see java.util.HashMap#remove(Object) - */ - @Nullable - V remove(int key); - - /** - * Returns the underlying map for usage of not implemented methods of this class. - * - * @return original map - * @deprecated will cause wrapping if it is a FastUtil collection - */ - @Deprecated - Map getMap(); -} diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntSet.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntSet.java deleted file mode 100644 index 74ec51cb9..000000000 --- a/common/src/main/java/us/myles/ViaVersion/util/fastutil/IntSet.java +++ /dev/null @@ -1,22 +0,0 @@ -package us.myles.ViaVersion.util.fastutil; - -/** - * Very simple wrapping interface to either be implemented by a HashSet or FastUtil's OpenHashSet. - */ -public interface IntSet { - - /** - * @see java.util.HashSet#contains(Object) - */ - boolean contains(int key); - - /** - * @see java.util.HashSet#add(Object) - */ - boolean add(int key); - - /** - * @see java.util.HashSet#remove(Object) - */ - boolean remove(int key); -} diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntMap.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntMap.java deleted file mode 100644 index fd10fa3a4..000000000 --- a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntMap.java +++ /dev/null @@ -1,43 +0,0 @@ -package us.myles.ViaVersion.util.fastutil; - -import it.unimi.dsi.fastutil.ints.Int2IntMap; -import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; - -import java.util.Map; - -final class WrappedFUIntMap implements IntMap { - private final Int2IntMap map; - - WrappedFUIntMap(Map originalMap) { - this.map = new Int2IntOpenHashMap(originalMap); - } - - WrappedFUIntMap(int size) { - this.map = new Int2IntOpenHashMap(size); - } - - @Override - public int getOrDefault(int key, int def) { - return map.getOrDefault(key, def); - } - - @Override - public boolean containsKey(int key) { - return map.containsKey(key); - } - - @Override - public int put(int key, int value) { - return map.put(key, value); - } - - @Override - public int remove(int key) { - return map.remove(key); - } - - @Override - public Map getMap() { - return map; - } -} \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntObjectMap.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntObjectMap.java deleted file mode 100644 index 175aeb50c..000000000 --- a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntObjectMap.java +++ /dev/null @@ -1,48 +0,0 @@ -package us.myles.ViaVersion.util.fastutil; - -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; - -import java.util.Map; - -final class WrappedFUIntObjectMap implements IntObjectMap { - private final Int2ObjectMap map; - - WrappedFUIntObjectMap(Map originalMap) { - this.map = new Int2ObjectOpenHashMap<>(originalMap); - } - - WrappedFUIntObjectMap(int size) { - this.map = new Int2ObjectOpenHashMap(size); - } - - @Override - public V get(int key) { - return map.get(key); - } - - @Override - public V getOrDefault(int key, V def) { - return map.getOrDefault(key, def); - } - - @Override - public boolean containsKey(int key) { - return map.containsKey(key); - } - - @Override - public V put(int key, V value) { - return map.put(key, value); - } - - @Override - public V remove(int key) { - return map.remove(key); - } - - @Override - public Map getMap() { - return map; - } -} \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntSet.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntSet.java deleted file mode 100644 index 315ee6b17..000000000 --- a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedFUIntSet.java +++ /dev/null @@ -1,32 +0,0 @@ -package us.myles.ViaVersion.util.fastutil; - -import it.unimi.dsi.fastutil.ints.IntOpenHashSet; - -import java.util.Set; - -final class WrappedFUIntSet implements IntSet { - private final it.unimi.dsi.fastutil.ints.IntSet set; - - WrappedFUIntSet(Set originalSet) { - this.set = new IntOpenHashSet(originalSet); - } - - WrappedFUIntSet(int size) { - this.set = new IntOpenHashSet(size); - } - - @Override - public boolean contains(int key) { - return set.contains(key); - } - - @Override - public boolean add(int key) { - return set.add(key); - } - - @Override - public boolean remove(int key) { - return set.remove(key); - } -} \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntMap.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntMap.java deleted file mode 100644 index 483a1f9d3..000000000 --- a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntMap.java +++ /dev/null @@ -1,43 +0,0 @@ -package us.myles.ViaVersion.util.fastutil; - -import java.util.HashMap; -import java.util.Map; - -final class WrappedIntMap implements IntMap { - private final Map map; - - WrappedIntMap(Map originalMap) { - this.map = originalMap; - } - - WrappedIntMap(int size) { - this.map = new HashMap<>(size); - } - - @Override - public int getOrDefault(int key, int def) { - return map.getOrDefault(key, def); - } - - @Override - public boolean containsKey(int key) { - return map.containsKey(key); - } - - @Override - public int put(int key, int value) { - Integer oldValue = map.put(key, value); - return oldValue != null ? oldValue : -1; - } - - @Override - public int remove(int key) { - Integer removed = map.remove(key); - return removed != null ? removed : -1; - } - - @Override - public Map getMap() { - return map; - } -} diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntObjectMap.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntObjectMap.java deleted file mode 100644 index 34e6ac61c..000000000 --- a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntObjectMap.java +++ /dev/null @@ -1,46 +0,0 @@ -package us.myles.ViaVersion.util.fastutil; - -import java.util.HashMap; -import java.util.Map; - -final class WrappedIntObjectMap implements IntObjectMap { - private final Map map; - - WrappedIntObjectMap(Map originalMap) { - this.map = originalMap; - } - - WrappedIntObjectMap(int size) { - this.map = new HashMap<>(size); - } - - @Override - public V get(int key) { - return map.get(key); - } - - @Override - public V getOrDefault(int key, V def) { - return map.getOrDefault(key, def); - } - - @Override - public boolean containsKey(int key) { - return map.containsKey(key); - } - - @Override - public V put(int key, V value) { - return map.put(key, value); - } - - @Override - public V remove(int key) { - return map.remove(key); - } - - @Override - public Map getMap() { - return map; - } -} \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntSet.java b/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntSet.java deleted file mode 100644 index 1730e195c..000000000 --- a/common/src/main/java/us/myles/ViaVersion/util/fastutil/WrappedIntSet.java +++ /dev/null @@ -1,31 +0,0 @@ -package us.myles.ViaVersion.util.fastutil; - -import java.util.HashSet; -import java.util.Set; - -final class WrappedIntSet implements IntSet { - private final Set set; - - WrappedIntSet(Set originalSet) { - this.set = originalSet; - } - - WrappedIntSet(int size) { - this.set = new HashSet<>(size); - } - - @Override - public boolean contains(int key) { - return set.contains(key); - } - - @Override - public boolean add(int key) { - return set.add(key); - } - - @Override - public boolean remove(int key) { - return set.remove(key); - } -} diff --git a/jar/pom.xml b/jar/pom.xml index 621d022fe..9ec8fe221 100644 --- a/jar/pom.xml +++ b/jar/pom.xml @@ -73,7 +73,44 @@ false false + + + it.unimi.dsi:fastutil + + + it/unimi/dsi/fastutil/ints/* + it/unimi/dsi/fastutil/objects/* + it/unimi/dsi/fastutil/*.class + + + + it/unimi/dsi/fastutil/*/*Reference* + it/unimi/dsi/fastutil/*/*Boolean* + it/unimi/dsi/fastutil/*/*Byte* + it/unimi/dsi/fastutil/*/*Short* + it/unimi/dsi/fastutil/*/*Float* + it/unimi/dsi/fastutil/*/*Double* + it/unimi/dsi/fastutil/*/*Long* + it/unimi/dsi/fastutil/*/*Char* + + it/unimi/dsi/fastutil/*/*Custom* + it/unimi/dsi/fastutil/*/*Linked* + it/unimi/dsi/fastutil/*/*Sorted* + it/unimi/dsi/fastutil/*/*Tree* + it/unimi/dsi/fastutil/*/*Heap* + it/unimi/dsi/fastutil/*/*Queue* + + it/unimi/dsi/fastutil/*/*Big* + it/unimi/dsi/fastutil/*/*Synchronized* + it/unimi/dsi/fastutil/*/*Unmodifiable* + + + + + it.unimi.dsi.fastutil + us.myles.viaversion.libs.fastutil + com.github.steveice10.opennbt us.myles.viaversion.libs.opennbt From 6167c3b526f762e691f8c459170148796017161c Mon Sep 17 00:00:00 2001 From: KennyTV Date: Mon, 8 Jun 2020 23:01:55 +0200 Subject: [PATCH 6/9] Set default return values --- .../ViaVersion/api/protocol/ProtocolRegistry.java | 7 +------ .../ViaVersion/api/rewriters/MetadataRewriter.java | 10 ++++++++-- .../blockconnections/FlowerConnectionHandler.java | 5 +++-- .../blockconnections/RedstoneConnectionHandler.java | 5 +++-- .../protocol1_13to1_12_2/data/EntityTypeRewriter.java | 4 +++- .../protocol1_14to1_13_2/data/MappingData.java | 2 +- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java index 1880d3ad6..87ffe49b0 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java @@ -137,12 +137,7 @@ public class ProtocolRegistry { protocols.put(protocol.getClass(), protocol); for (int version : supported) { - Int2ObjectMap protocolMap = registryMap.get(version); - if (protocolMap == null) { - protocolMap = new Int2ObjectOpenHashMap<>(1); - registryMap.put(version, protocolMap); - } - + Int2ObjectMap protocolMap = registryMap.computeIfAbsent(version, s -> new Int2ObjectOpenHashMap<>(1)); protocolMap.put(output, protocol); } diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java index d32532f54..edf6106d6 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java @@ -184,7 +184,10 @@ public abstract class MetadataRewriter { } public & EntityType> void mapTypes(EntityType[] oldTypes, Class newTypeClass) { - if (typeMapping == null) typeMapping = new Int2IntOpenHashMap(oldTypes.length); + if (typeMapping == null) { + typeMapping = new Int2IntOpenHashMap(oldTypes.length); + typeMapping.defaultReturnValue(-1); + } for (EntityType oldType : oldTypes) { try { T newType = Enum.valueOf(newTypeClass, oldType.name()); @@ -199,7 +202,10 @@ public abstract class MetadataRewriter { } public void mapType(EntityType oldType, EntityType newType) { - if (typeMapping == null) typeMapping = new Int2IntOpenHashMap(); + if (typeMapping == null) { + typeMapping = new Int2IntOpenHashMap(); + typeMapping.defaultReturnValue(-1); + } typeMapping.put(oldType.getId(), newType.getId()); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/FlowerConnectionHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/FlowerConnectionHandler.java index 801a7d63d..0ede1d469 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/FlowerConnectionHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/FlowerConnectionHandler.java @@ -1,5 +1,6 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections; +import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; @@ -11,7 +12,7 @@ import java.util.Set; public class FlowerConnectionHandler extends ConnectionHandler { - private static final Int2IntOpenHashMap flowers = new Int2IntOpenHashMap(); + private static final Int2IntMap flowers = new Int2IntOpenHashMap(); static ConnectionData.ConnectorInitAction init() { final Set baseFlower = new HashSet<>(); @@ -38,7 +39,7 @@ public class FlowerConnectionHandler extends ConnectionHandler { public int connect(UserConnection user, Position position, int blockState) { int blockBelowId = getBlockData(user, position.getRelative(BlockFace.BOTTOM)); int connectBelow = flowers.get(blockBelowId); - if (connectBelow != -1) { + if (connectBelow != 0) { int blockAboveId = getBlockData(user, position.getRelative(BlockFace.TOP)); if (Via.getConfig().isStemWhenBlockAbove()) { if (blockAboveId == 0) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java index 918691470..4f147800f 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java @@ -1,5 +1,6 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections; +import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.minecraft.BlockFace; @@ -10,8 +11,8 @@ import java.util.Set; public class RedstoneConnectionHandler extends ConnectionHandler { private static final Set redstone = new HashSet<>(); - private static final Int2IntOpenHashMap connectedBlockStates = new Int2IntOpenHashMap(1296); - private static final Int2IntOpenHashMap powerMappings = new Int2IntOpenHashMap(1296); + private static final Int2IntMap connectedBlockStates = new Int2IntOpenHashMap(1296); + private static final Int2IntMap powerMappings = new Int2IntOpenHashMap(1296); static ConnectionData.ConnectorInitAction init() { final RedstoneConnectionHandler connectionHandler = new RedstoneConnectionHandler(); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java index 856472b5e..fa40fc5d7 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java @@ -1,11 +1,13 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data; +import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; public class EntityTypeRewriter { - private static final Int2IntOpenHashMap ENTITY_TYPES = new Int2IntOpenHashMap(93); + private static final Int2IntMap ENTITY_TYPES = new Int2IntOpenHashMap(93); static { + ENTITY_TYPES.defaultReturnValue(-1); registerEntity(1, 32); // item - ajl registerEntity(2, 22); // xp_orb - abx registerEntity(3, 0); // area_effect_cloud - abp diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java index 202edeb12..1399dc418 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java @@ -47,7 +47,7 @@ public class MappingData { if (id == null) { Via.getPlatform().getLogger().warning("Unknown blockstate " + key + " :("); } else { - MappingData.motionBlocking.add(id); + MappingData.motionBlocking.add(id.intValue()); } } From 5bd1ef882eede6a58904c850e86143bdb01b8a56 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Mon, 8 Jun 2020 23:13:47 +0200 Subject: [PATCH 7/9] Set load factor to 1 for deterministically sized collections --- .../ViaVersion/api/rewriters/MetadataRewriter.java | 2 +- .../blockconnections/ConnectionData.java | 12 ++++++------ .../protocol1_13to1_12_2/data/BlockIdData.java | 2 +- .../data/EntityTypeRewriter.java | 2 +- .../protocol1_13to1_12_2/packets/WorldPackets.java | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java index edf6106d6..a9dfb16ef 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java @@ -185,7 +185,7 @@ public abstract class MetadataRewriter { public & EntityType> void mapTypes(EntityType[] oldTypes, Class newTypeClass) { if (typeMapping == null) { - typeMapping = new Int2IntOpenHashMap(oldTypes.length); + typeMapping = new Int2IntOpenHashMap(oldTypes.length, 1F); typeMapping.defaultReturnValue(-1); } for (EntityType oldType : oldTypes) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java index c2f8ac3a4..ca987d257 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java @@ -31,11 +31,11 @@ import java.util.Map.Entry; public class ConnectionData { private static final BlockChangeRecord[] A = new BlockChangeRecord[0]; public static BlockConnectionProvider blockConnectionProvider; - static Int2ObjectMap idToKey = new Int2ObjectOpenHashMap<>(8582); - static Map keyToId = new HashMap<>(8582); + static Int2ObjectMap idToKey = new Int2ObjectOpenHashMap<>(8582, 1F); + static Map keyToId = new HashMap<>(8582, 1F); static Int2ObjectMap connectionHandlerMap = new Int2ObjectOpenHashMap<>(1); static Int2ObjectMap blockConnectionData = new Int2ObjectOpenHashMap<>(1); - static IntSet occludingStates = new IntOpenHashSet(377); + static IntSet occludingStates = new IntOpenHashSet(377, 1F); public static void update(UserConnection user, Position position) { for (BlockFace face : BlockFace.values()) { @@ -213,10 +213,10 @@ public class ConnectionData { keyToId.put(key, id); } - connectionHandlerMap = new Int2ObjectOpenHashMap<>(3650); + connectionHandlerMap = new Int2ObjectOpenHashMap<>(3650, 1F); if (!Via.getConfig().isReduceBlockStorageMemory()) { - blockConnectionData = new Int2ObjectOpenHashMap<>(1146); + blockConnectionData = new Int2ObjectOpenHashMap<>(1146, 1F); JsonObject mappingBlockConnections = MappingDataLoader.loadData("blockConnections.json"); for (Entry entry : mappingBlockConnections.entrySet()) { int id = keyToId.get(entry.getKey()); @@ -243,7 +243,7 @@ public class ConnectionData { JsonObject blockData = MappingDataLoader.loadData("blockData.json"); JsonArray occluding = blockData.getAsJsonArray("occluding"); for (JsonElement jsonElement : occluding) { - occludingStates.add(keyToId.get(jsonElement.getAsString())); + occludingStates.add(keyToId.get(jsonElement.getAsString()).intValue()); } List initActions = new ArrayList<>(); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/BlockIdData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/BlockIdData.java index b1e547384..2e914f432 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/BlockIdData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/BlockIdData.java @@ -26,7 +26,7 @@ public class BlockIdData { reader, new TypeToken>() { }.getType() - )); + ), 1F); fallbackReverseMapping = new HashMap<>(); for (Map.Entry entry : blockIdMapping.entrySet()) { for (String val : entry.getValue()) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java index fa40fc5d7..a6f1f53cc 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java @@ -4,7 +4,7 @@ import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; public class EntityTypeRewriter { - private static final Int2IntMap ENTITY_TYPES = new Int2IntOpenHashMap(93); + private static final Int2IntMap ENTITY_TYPES = new Int2IntOpenHashMap(83, 1F); static { ENTITY_TYPES.defaultReturnValue(-1); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java index d57925314..6537f3453 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java @@ -33,7 +33,7 @@ import java.util.List; import java.util.Optional; public class WorldPackets { - private static final IntSet VALID_BIOMES = new IntOpenHashSet(70); + private static final IntSet VALID_BIOMES = new IntOpenHashSet(70, 1F); static { // Client will crash if it receives a invalid biome id From 5d8084986f6288a34a7d43580cdacaab5e5e980e Mon Sep 17 00:00:00 2001 From: KennyTV Date: Mon, 8 Jun 2020 23:54:24 +0200 Subject: [PATCH 8/9] Put itemmappings into custom Int2IntBiMap --- .../Protocol1_13To1_12_2.java | 4 +- .../data/MappingData.java | 4 +- .../packets/InventoryPackets.java | 6 +- .../data/MappingData.java | 6 +- .../packets/InventoryPackets.java | 8 +- .../data/MappingData.java | 6 +- .../packets/InventoryPackets.java | 8 +- .../data/MappingData.java | 6 +- .../packets/InventoryPackets.java | 8 +- .../myles/ViaVersion/util/Int2IntBiMap.java | 128 ++++++++++++++++++ 10 files changed, 157 insertions(+), 27 deletions(-) create mode 100644 common/src/main/java/us/myles/ViaVersion/util/Int2IntBiMap.java diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java index feb9cef5f..4f345578c 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java @@ -346,8 +346,8 @@ public class Protocol1_13To1_12_2 extends Protocol oldToNewItems = HashBiMap.create(); + public static final Int2IntBiMap oldToNewItems = new Int2IntBiMap(); public static final Map blockTags = new HashMap<>(); public static final Map itemTags = new HashMap<>(); public static final Map fluidTags = new HashMap<>(); @@ -37,6 +38,7 @@ public class MappingData { JsonObject mapping1_12 = MappingDataLoader.loadData("mapping-1.12.json", true); JsonObject mapping1_13 = MappingDataLoader.loadData("mapping-1.13.json", true); + oldToNewItems.defaultReturnValue(-1); blockMappings = new BlockMappingsShortArray(mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks")); MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_12.getAsJsonObject("items"), mapping1_13.getAsJsonObject("items")); loadTags(blockTags, mapping1_13.getAsJsonObject("block_tags")); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java index 07e3b96bc..edd520f5e 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java @@ -435,7 +435,7 @@ public class InventoryPackets { } } - item.setIdentifier(MappingData.oldToNewItems.get(rawId).shortValue()); + item.setIdentifier(MappingData.oldToNewItems.get(rawId)); item.setData((short) 0); } @@ -487,8 +487,8 @@ public class InventoryPackets { } if (rawId == null) { - Integer oldId = MappingData.oldToNewItems.inverse().get(item.getIdentifier()); - if (oldId != null) { + int oldId = MappingData.oldToNewItems.inverse().get(item.getIdentifier()); + if (oldId != -1) { // Handle spawn eggs Optional eggEntityId = SpawnEggRewriter.getEntityId(oldId); if (eggEntityId.isPresent()) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java index 1399dc418..6acf4527e 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java @@ -1,7 +1,5 @@ package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -10,12 +8,13 @@ import it.unimi.dsi.fastutil.ints.IntSet; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.Mappings; +import us.myles.ViaVersion.util.Int2IntBiMap; import java.util.HashMap; import java.util.Map; public class MappingData { - public static final BiMap oldToNewItems = HashBiMap.create(); + public static final Int2IntBiMap oldToNewItems = new Int2IntBiMap(); public static Mappings blockStateMappings; public static Mappings blockMappings; public static Mappings soundMappings; @@ -27,6 +26,7 @@ public class MappingData { JsonObject mapping1_13_2 = MappingDataLoader.loadData("mapping-1.13.2.json", true); JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json", true); + oldToNewItems.defaultReturnValue(-1); blockStateMappings = new Mappings(mapping1_13_2.getAsJsonObject("blockstates"), mapping1_14.getAsJsonObject("blockstates")); blockMappings = new Mappings(mapping1_13_2.getAsJsonObject("blocks"), mapping1_14.getAsJsonObject("blocks")); MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_13_2.getAsJsonObject("items"), mapping1_14.getAsJsonObject("items")); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java index eca326ba4..b2d4a43c6 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java @@ -271,8 +271,8 @@ public class InventoryPackets { } public static int getNewItemId(int id) { - Integer newId = MappingData.oldToNewItems.get(id); - if (newId == null) { + int newId = MappingData.oldToNewItems.get(id); + if (newId == -1) { Via.getPlatform().getLogger().warning("Missing 1.14 item for 1.13.2 item " + id); return 1; } @@ -313,7 +313,7 @@ public class InventoryPackets { } public static int getOldItemId(int id) { - Integer oldId = MappingData.oldToNewItems.inverse().get(id); - return oldId != null ? oldId : 1; + int oldId = MappingData.oldToNewItems.inverse().get(id); + return oldId != -1 ? oldId : 1; } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/data/MappingData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/data/MappingData.java index 057c33425..ae039cd61 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/data/MappingData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/data/MappingData.java @@ -1,14 +1,13 @@ package us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; import com.google.gson.JsonObject; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.Mappings; +import us.myles.ViaVersion.util.Int2IntBiMap; public class MappingData { - public static BiMap oldToNewItems = HashBiMap.create(); + public static Int2IntBiMap oldToNewItems = new Int2IntBiMap(); public static Mappings blockMappings; public static Mappings blockStateMappings; public static Mappings soundMappings; @@ -19,6 +18,7 @@ public class MappingData { JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json", true); JsonObject mapping1_15 = MappingDataLoader.loadData("mapping-1.15.json", true); + oldToNewItems.defaultReturnValue(-1); blockStateMappings = new Mappings(mapping1_14.getAsJsonObject("blockstates"), mapping1_15.getAsJsonObject("blockstates"), diffmapping.getAsJsonObject("blockstates")); blockMappings = new Mappings(mapping1_14.getAsJsonObject("blocks"), mapping1_15.getAsJsonObject("blocks")); MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_14.getAsJsonObject("items"), mapping1_15.getAsJsonObject("items")); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/InventoryPackets.java index 3bc4a619c..a096b7d53 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/InventoryPackets.java @@ -143,8 +143,8 @@ public class InventoryPackets { } public static int getNewItemId(int id) { - Integer newId = MappingData.oldToNewItems.get(id); - if (newId == null) { + int newId = MappingData.oldToNewItems.get(id); + if (newId == -1) { Via.getPlatform().getLogger().warning("Missing 1.15 item for 1.14 item " + id); return 1; } @@ -152,7 +152,7 @@ public class InventoryPackets { } public static int getOldItemId(int id) { - Integer oldId = MappingData.oldToNewItems.inverse().get(id); - return oldId != null ? oldId : 1; + int oldId = MappingData.oldToNewItems.inverse().get(id); + return oldId != -1 ? oldId : 1; } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/data/MappingData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/data/MappingData.java index 962910fbb..410091a76 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/data/MappingData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/data/MappingData.java @@ -1,17 +1,16 @@ 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 us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.Mappings; +import us.myles.ViaVersion.util.Int2IntBiMap; import java.util.HashMap; import java.util.Map; public class MappingData { - public static BiMap oldToNewItems = HashBiMap.create(); + public static Int2IntBiMap oldToNewItems = new Int2IntBiMap(); public static Map attributeMappings = new HashMap<>(); public static Mappings blockMappings; public static Mappings blockStateMappings; @@ -23,6 +22,7 @@ public class MappingData { JsonObject mapping1_15 = MappingDataLoader.loadData("mapping-1.15.json", true); JsonObject mapping1_16 = MappingDataLoader.loadData("mapping-1.16.json", true); + oldToNewItems.defaultReturnValue(-1); blockStateMappings = new Mappings(mapping1_15.getAsJsonObject("blockstates"), mapping1_16.getAsJsonObject("blockstates"), diffmapping.getAsJsonObject("blockstates")); blockMappings = new Mappings(mapping1_15.getAsJsonObject("blocks"), mapping1_16.getAsJsonObject("blocks")); MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_15.getAsJsonObject("items"), mapping1_16.getAsJsonObject("items"), diffmapping.getAsJsonObject("items")); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java index d5cf51d52..02833f7c3 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java @@ -206,8 +206,8 @@ public class InventoryPackets { } public static int getNewItemId(int id) { - Integer newId = MappingData.oldToNewItems.get(id); - if (newId == null) { + int newId = MappingData.oldToNewItems.get(id); + if (newId == -1) { Via.getPlatform().getLogger().warning("Missing 1.16 item for 1.15.2 item " + id); return 1; } @@ -215,7 +215,7 @@ public class InventoryPackets { } public static int getOldItemId(int id) { - Integer oldId = MappingData.oldToNewItems.inverse().get(id); - return oldId != null ? oldId : 1; + int oldId = MappingData.oldToNewItems.inverse().get(id); + return oldId != -1 ? oldId : 1; } } diff --git a/common/src/main/java/us/myles/ViaVersion/util/Int2IntBiMap.java b/common/src/main/java/us/myles/ViaVersion/util/Int2IntBiMap.java new file mode 100644 index 000000000..2398a6230 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/util/Int2IntBiMap.java @@ -0,0 +1,128 @@ +package us.myles.ViaVersion.util; + +import com.google.common.base.Preconditions; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntSet; +import it.unimi.dsi.fastutil.objects.ObjectSet; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + + +/** + * Simple wrapper class for two {@link Int2IntMap}s. + * + * @see #inverse() to get the inversed map + */ +public class Int2IntBiMap implements Int2IntMap { + + private final Int2IntMap map; + private final Int2IntBiMap inverse; + + public Int2IntBiMap() { + this.map = new Int2IntOpenHashMap(); + this.inverse = new Int2IntBiMap(this); + } + + private Int2IntBiMap(Int2IntBiMap inverse) { + this.map = new Int2IntOpenHashMap(); + this.inverse = inverse; + } + + /** + * @return the inverse of this bimap + */ + public Int2IntBiMap inverse() { + return inverse; + } + + /** + * Puts the key and value into the maps. + * + * @param key key + * @param value value + * @return old value if present + * @throws IllegalArgumentException if the value already exists in the map + */ + @Override + public int put(int key, int value) { + if (containsKey(key) && value == get(key)) return value; + + Preconditions.checkArgument(!containsValue(value), "value already present: %s", value); + map.put(key, value); + inverse.map.put(value, key); + return defaultReturnValue(); + } + + @Override + public boolean remove(int key, int value) { + map.remove(key, value); + return inverse.map.remove(key, value); + } + + @Override + public int get(int key) { + return map.get(key); + } + + @Override + public void clear() { + map.clear(); + inverse.map.clear(); + } + + @Override + public int size() { + return map.size(); + } + + @Override + public boolean isEmpty() { + return map.isEmpty(); + } + + @Override + @Deprecated + public void putAll(@NotNull Map m) { + throw new UnsupportedOperationException(); + } + + @Override + public void defaultReturnValue(int rv) { + map.defaultReturnValue(rv); + inverse.map.defaultReturnValue(rv); + } + + @Override + public int defaultReturnValue() { + return map.defaultReturnValue(); + } + + @Override + public ObjectSet int2IntEntrySet() { + return map.int2IntEntrySet(); + } + + @Override + @NotNull + public IntSet keySet() { + return map.keySet(); + } + + @Override + @NotNull + public IntSet values() { + return inverse.map.keySet(); + } + + @Override + public boolean containsKey(int key) { + return map.containsKey(key); + } + + @Override + public boolean containsValue(int value) { + return inverse.map.containsKey(value); + } +} From f408a5d4c6f11cf9f7dbbba5414e2e0e6c63996e Mon Sep 17 00:00:00 2001 From: KennyTV Date: Tue, 9 Jun 2020 08:38:22 +0200 Subject: [PATCH 9/9] Add last load factors --- .../us/myles/ViaVersion/api/protocol/ProtocolRegistry.java | 2 +- .../protocols/protocol1_13to1_12_2/storage/BlockStorage.java | 2 +- .../protocols/protocol1_14to1_13_2/data/MappingData.java | 4 ++-- .../ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java | 2 +- .../ViaVersion/protocols/protocol1_9to1_8/sounds/Effect.java | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java index 87ffe49b0..4553bd6d2 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java @@ -137,7 +137,7 @@ public class ProtocolRegistry { protocols.put(protocol.getClass(), protocol); for (int version : supported) { - Int2ObjectMap protocolMap = registryMap.computeIfAbsent(version, s -> new Int2ObjectOpenHashMap<>(1)); + Int2ObjectMap protocolMap = registryMap.computeIfAbsent(version, s -> new Int2ObjectOpenHashMap<>(2)); protocolMap.put(output, protocol); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java index 4f032b8c9..91728d621 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java @@ -10,7 +10,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; public class BlockStorage extends StoredObject { - private static final IntSet WHITELIST = new IntOpenHashSet(46); + private static final IntSet WHITELIST = new IntOpenHashSet(46, 1F); private final Map blocks = new ConcurrentHashMap<>(); static { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java index 6acf4527e..2bcf0a6e5 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/MappingData.java @@ -40,7 +40,7 @@ public class MappingData { JsonObject heightMapData = MappingDataLoader.loadData("heightMapData-1.14.json"); JsonArray motionBlocking = heightMapData.getAsJsonArray("MOTION_BLOCKING"); - MappingData.motionBlocking = new IntOpenHashSet(motionBlocking.size()); + MappingData.motionBlocking = new IntOpenHashSet(motionBlocking.size(), 1F); for (JsonElement blockState : motionBlocking) { String key = blockState.getAsString(); Integer id = blockStateMap.get(key); @@ -52,7 +52,7 @@ public class MappingData { } if (Via.getConfig().isNonFullBlockLightFix()) { - nonFullBlocks = new IntOpenHashSet(1611); + nonFullBlocks = new IntOpenHashSet(1611, 1F); for (Map.Entry blockstates : mapping1_13_2.getAsJsonObject("blockstates").entrySet()) { final String state = blockstates.getValue().getAsString(); if (state.contains("_slab") || state.contains("_stairs") || state.contains("_wall[")) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java index 2aa6d4ef3..b86e10dc7 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java @@ -19,7 +19,7 @@ public class ItemRewriter { private static final Map POTION_NAME_TO_ID = new HashMap<>(); private static final Map POTION_ID_TO_NAME = new HashMap<>(); - private static final Int2IntMap POTION_INDEX = new Int2IntOpenHashMap(36); + private static final Int2IntMap POTION_INDEX = new Int2IntOpenHashMap(36, 1F); static { /* Entities */ diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/Effect.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/Effect.java index 4884f6c1c..bcb3fe542 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/Effect.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/Effect.java @@ -5,7 +5,7 @@ import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; public class Effect { - private static final Int2IntMap EFFECTS = new Int2IntOpenHashMap(17); + private static final Int2IntMap EFFECTS = new Int2IntOpenHashMap(17, 1F); static { addRewrite(1005, 1010); //Play music disc