Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 08:30:09 +01:00
Use proper FU classes, shade dumbed down version
Dieser Commit ist enthalten in:
Ursprung
39cb8fd554
Commit
8188ae09f5
@ -20,12 +20,12 @@
|
||||
<scope>compile</scope> <!-- Velocity doesn't have snakeyaml -->
|
||||
</dependency>
|
||||
|
||||
<!-- FastUtil for optional performance increases -->
|
||||
<!-- FastUtil for performance increases -->
|
||||
<dependency>
|
||||
<groupId>it.unimi.dsi</groupId>
|
||||
<artifactId>fastutil</artifactId>
|
||||
<version>8.3.1</version>
|
||||
<scope>provided</scope>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -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<IntObjectMap<Protocol>> registryMap = CollectionUtil.createIntObjectMap(32);
|
||||
private static final Int2ObjectMap<Int2ObjectMap<Protocol>> registryMap = new Int2ObjectOpenHashMap<>(32);
|
||||
private static final Map<Class<? extends Protocol>, Protocol> protocols = new HashMap<>();
|
||||
private static final Map<Pair<Integer, Integer>, List<Pair<Integer, Protocol>>> pathCache = new ConcurrentHashMap<>();
|
||||
private static final Set<Integer> 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<Integer> supported, Integer output) {
|
||||
public static void registerProtocol(Protocol protocol, List<Integer> 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<Protocol> protocolMap = registryMap.get(version);
|
||||
Int2ObjectMap<Protocol> 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<Protocol> maps : registryMap.getMap().values()) {
|
||||
if (maps.containsKey(SERVER_PROTOCOL)) return true;
|
||||
for (Int2ObjectMap<Protocol> 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<Protocol> inputMap = registryMap.get(clientVersion);
|
||||
Int2ObjectMap<Protocol> 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<Pair<Integer, Protocol>> shortest = null;
|
||||
|
||||
for (Map.Entry<Integer, Protocol> entry : inputMap.getMap().entrySet()) {
|
||||
for (Int2ObjectMap.Entry<Protocol> entry : inputMap.int2ObjectEntrySet()) {
|
||||
// Ensure it wasn't caught by the other loop
|
||||
if (!entry.getKey().equals(serverVersion)) {
|
||||
Pair<Integer, Protocol> pair = new Pair<>(entry.getKey(), entry.getValue());
|
||||
// Ensure no recursion
|
||||
if (!current.contains(pair)) {
|
||||
// Create a copy
|
||||
List<Pair<Integer, Protocol>> 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<Integer, Protocol> pair = new Pair<>(entry.getIntKey(), entry.getValue());
|
||||
// Ensure no recursion
|
||||
if (current.contains(pair)) continue;
|
||||
|
||||
// Create a copy
|
||||
List<Pair<Integer, Protocol>> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<? extends EntityTracker> entityTrackerClass;
|
||||
private final Protocol protocol;
|
||||
private IntMap typeMapping;
|
||||
private Int2IntMap typeMapping;
|
||||
|
||||
protected MetadataRewriter(Protocol protocol, Class<? extends EntityTracker> entityTrackerClass) {
|
||||
this.protocol = protocol;
|
||||
@ -184,7 +184,7 @@ public abstract class MetadataRewriter {
|
||||
}
|
||||
|
||||
public <T extends Enum<T> & EntityType> void mapTypes(EntityType[] oldTypes, Class<T> 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());
|
||||
}
|
||||
|
||||
|
@ -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<String> idToKey = CollectionUtil.createIntObjectMap(8582);
|
||||
static Int2ObjectMap<String> idToKey = new Int2ObjectOpenHashMap<>(8582);
|
||||
static Map<String, Integer> keyToId = new HashMap<>(8582);
|
||||
static IntObjectMap<ConnectionHandler> connectionHandlerMap = CollectionUtil.createIntObjectMap(1);
|
||||
static IntObjectMap<BlockData> blockConnectionData = CollectionUtil.createIntObjectMap(1);
|
||||
static IntSet occludingStates = CollectionUtil.createIntSet(377);
|
||||
static Int2ObjectMap<ConnectionHandler> connectionHandlerMap = new Int2ObjectOpenHashMap<>(1);
|
||||
static Int2ObjectMap<BlockData> 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<String, JsonElement> entry : mappingBlockConnections.entrySet()) {
|
||||
int id = keyToId.get(entry.getKey());
|
||||
|
@ -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<String> baseFlower = new HashSet<>();
|
||||
|
@ -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<Integer> 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();
|
||||
|
@ -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<String, String[]> blockIdMapping;
|
||||
public static Map<String, String[]> fallbackReverseMapping;
|
||||
public static IntObjectMap<String> numberIdToString;
|
||||
public static Int2ObjectMap<String> 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<Map<Integer, String>>() {
|
||||
}.getType()
|
||||
)));
|
||||
));
|
||||
} finally {
|
||||
try {
|
||||
blockR.close();
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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<Position, ReplacementData> blocks = new ConcurrentHashMap<>();
|
||||
|
||||
static {
|
||||
|
@ -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<String, JsonElement> blockstates : mapping1_13_2.getAsJsonObject("blockstates").entrySet()) {
|
||||
final String state = blockstates.getValue().getAsString();
|
||||
if (state.contains("_slab") || state.contains("_stairs") || state.contains("_wall["))
|
||||
|
@ -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<String, Integer> POTION_NAME_TO_ID = new HashMap<>();
|
||||
private static final Map<Integer, String> 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);
|
||||
|
@ -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
|
||||
|
@ -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<Integer, Integer> 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 <V> IntObjectMap<V> createIntObjectMap(Map<Integer, V> 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 <V> IntObjectMap<V> 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<Integer> 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;
|
||||
}
|
||||
}
|
@ -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<Integer, Integer> getMap();
|
||||
}
|
@ -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 <V> Object value type
|
||||
*/
|
||||
public interface IntObjectMap<V> {
|
||||
|
||||
/**
|
||||
* @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<Integer, V> getMap();
|
||||
}
|
@ -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);
|
||||
}
|
@ -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<Integer, Integer> 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<Integer, Integer> getMap() {
|
||||
return map;
|
||||
}
|
||||
}
|
@ -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<V> implements IntObjectMap<V> {
|
||||
private final Int2ObjectMap<V> map;
|
||||
|
||||
WrappedFUIntObjectMap(Map<Integer, V> 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<Integer, V> getMap() {
|
||||
return map;
|
||||
}
|
||||
}
|
@ -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<Integer> 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);
|
||||
}
|
||||
}
|
@ -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<Integer, Integer> map;
|
||||
|
||||
WrappedIntMap(Map<Integer, Integer> 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<Integer, Integer> getMap() {
|
||||
return map;
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package us.myles.ViaVersion.util.fastutil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
final class WrappedIntObjectMap<V> implements IntObjectMap<V> {
|
||||
private final Map<Integer, V> map;
|
||||
|
||||
WrappedIntObjectMap(Map<Integer, V> 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<Integer, V> getMap() {
|
||||
return map;
|
||||
}
|
||||
}
|
@ -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<Integer> set;
|
||||
|
||||
WrappedIntSet(Set<Integer> 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);
|
||||
}
|
||||
}
|
37
jar/pom.xml
37
jar/pom.xml
@ -73,7 +73,44 @@
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<minimizeJar>false</minimizeJar>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>it.unimi.dsi:fastutil</artifact>
|
||||
<includes>
|
||||
<!-- We only want int and Object maps -->
|
||||
<include>it/unimi/dsi/fastutil/ints/*</include>
|
||||
<include>it/unimi/dsi/fastutil/objects/*</include>
|
||||
<include>it/unimi/dsi/fastutil/*.class</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<!-- Object types -->
|
||||
<exclude>it/unimi/dsi/fastutil/*/*Reference*</exclude>
|
||||
<exclude>it/unimi/dsi/fastutil/*/*Boolean*</exclude>
|
||||
<exclude>it/unimi/dsi/fastutil/*/*Byte*</exclude>
|
||||
<exclude>it/unimi/dsi/fastutil/*/*Short*</exclude>
|
||||
<exclude>it/unimi/dsi/fastutil/*/*Float*</exclude>
|
||||
<exclude>it/unimi/dsi/fastutil/*/*Double*</exclude>
|
||||
<exclude>it/unimi/dsi/fastutil/*/*Long*</exclude>
|
||||
<exclude>it/unimi/dsi/fastutil/*/*Char*</exclude>
|
||||
<!-- Map types -->
|
||||
<exclude>it/unimi/dsi/fastutil/*/*Custom*</exclude>
|
||||
<exclude>it/unimi/dsi/fastutil/*/*Linked*</exclude>
|
||||
<exclude>it/unimi/dsi/fastutil/*/*Sorted*</exclude>
|
||||
<exclude>it/unimi/dsi/fastutil/*/*Tree*</exclude>
|
||||
<exclude>it/unimi/dsi/fastutil/*/*Heap*</exclude>
|
||||
<exclude>it/unimi/dsi/fastutil/*/*Queue*</exclude>
|
||||
<!-- Crossing fingers -->
|
||||
<exclude>it/unimi/dsi/fastutil/*/*Big*</exclude>
|
||||
<exclude>it/unimi/dsi/fastutil/*/*Synchronized*</exclude>
|
||||
<exclude>it/unimi/dsi/fastutil/*/*Unmodifiable*</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>it.unimi.dsi.fastutil</pattern>
|
||||
<shadedPattern>us.myles.viaversion.libs.fastutil</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.github.steveice10.opennbt</pattern>
|
||||
<shadedPattern>us.myles.viaversion.libs.opennbt</shadedPattern>
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren