Convert item and block maps in Toolbox to TIntObjectMaps

This commit is contained in:
RednedEpic 2019-10-11 18:38:34 -05:00 committed by RednedEpic
parent 7a6c2b5914
commit 8c541304a6
3 changed files with 9 additions and 11 deletions

View file

@ -30,10 +30,6 @@ import org.geysermc.api.logger.Logger;
import org.geysermc.api.plugin.PluginManager;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.ScheduledExecutorService;
public class Geyser {

View file

@ -85,7 +85,7 @@ public class ItemTranslator {
}
public ItemEntry getItem(ItemData data) {
for (ItemEntry itemEntry : Toolbox.ITEM_ENTRIES.values()) {
for (ItemEntry itemEntry : Toolbox.ITEM_ENTRIES.valueCollection()) {
if (itemEntry.getBedrockId() == data.getId() && itemEntry.getBedrockData() == data.getDamage()) {
return itemEntry;
}

View file

@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.nukkitx.network.VarInts;
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
import com.nukkitx.protocol.bedrock.v361.BedrockUtils;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.geysermc.connector.console.GeyserLogger;
@ -19,8 +21,8 @@ public class Toolbox {
public static final Collection<StartGamePacket.ItemEntry> ITEMS;
public static final ByteBuf CACHED_PALLETE;
public static final Map<Integer, ItemEntry> ITEM_ENTRIES;
public static final Map<Integer, BlockEntry> BLOCK_ENTRIES;
public static final TIntObjectMap<ItemEntry> ITEM_ENTRIES;
public static final TIntObjectMap<BlockEntry> BLOCK_ENTRIES;
static {
InputStream stream = Toolbox.class.getClassLoader().getResourceAsStream("bedrock/cached_palette.json");
@ -79,7 +81,7 @@ public class Toolbox {
ex.printStackTrace();
}
Map<Integer, ItemEntry> itemEntries = new HashMap<>();
TIntObjectMap<ItemEntry> itemEntries = new TIntObjectHashMap<>();
int itemIndex = 0;
for (Map.Entry<String, Map<String, Object>> itemEntry : items.entrySet()) {
@ -87,7 +89,7 @@ public class Toolbox {
itemIndex++;
}
ITEM_ENTRIES = Collections.unmodifiableMap(itemEntries);
ITEM_ENTRIES = itemEntries;
InputStream blockStream = Toolbox.class.getClassLoader().getResourceAsStream("blocks.json");
ObjectMapper blockMapper = new ObjectMapper();
@ -99,7 +101,7 @@ public class Toolbox {
ex.printStackTrace();
}
Map<Integer, BlockEntry> blockEntries = new HashMap<>();
TIntObjectMap<BlockEntry> blockEntries = new TIntObjectHashMap<>();
int blockIndex = 0;
for (Map.Entry<String, Map<String, Object>> itemEntry : blocks.entrySet()) {
@ -113,6 +115,6 @@ public class Toolbox {
blockIndex++;
}
BLOCK_ENTRIES = Collections.unmodifiableMap(blockEntries);
BLOCK_ENTRIES = blockEntries;
}
}