From 8188ae09f59a5f52543d8bc66d576f43822d17bd Mon Sep 17 00:00:00 2001 From: KennyTV Date: Mon, 8 Jun 2020 22:23:24 +0200 Subject: [PATCH] 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