From 6167c3b526f762e691f8c459170148796017161c Mon Sep 17 00:00:00 2001 From: KennyTV Date: Mon, 8 Jun 2020 23:01:55 +0200 Subject: [PATCH] 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()); } }