mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-12-29 15:49:09 +01:00
Convert item and block maps in Toolbox to TIntObjectMaps
This commit is contained in:
parent
7a6c2b5914
commit
8c541304a6
3 changed files with 9 additions and 11 deletions
|
@ -30,10 +30,6 @@ import org.geysermc.api.logger.Logger;
|
||||||
import org.geysermc.api.plugin.PluginManager;
|
import org.geysermc.api.plugin.PluginManager;
|
||||||
|
|
||||||
import java.util.Collection;
|
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;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
|
||||||
public class Geyser {
|
public class Geyser {
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class ItemTranslator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemEntry getItem(ItemData data) {
|
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()) {
|
if (itemEntry.getBedrockId() == data.getId() && itemEntry.getBedrockData() == data.getDamage()) {
|
||||||
return itemEntry;
|
return itemEntry;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.nukkitx.network.VarInts;
|
import com.nukkitx.network.VarInts;
|
||||||
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
|
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
|
||||||
import com.nukkitx.protocol.bedrock.v361.BedrockUtils;
|
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.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import org.geysermc.connector.console.GeyserLogger;
|
import org.geysermc.connector.console.GeyserLogger;
|
||||||
|
@ -19,8 +21,8 @@ public class Toolbox {
|
||||||
public static final Collection<StartGamePacket.ItemEntry> ITEMS;
|
public static final Collection<StartGamePacket.ItemEntry> ITEMS;
|
||||||
public static final ByteBuf CACHED_PALLETE;
|
public static final ByteBuf CACHED_PALLETE;
|
||||||
|
|
||||||
public static final Map<Integer, ItemEntry> ITEM_ENTRIES;
|
public static final TIntObjectMap<ItemEntry> ITEM_ENTRIES;
|
||||||
public static final Map<Integer, BlockEntry> BLOCK_ENTRIES;
|
public static final TIntObjectMap<BlockEntry> BLOCK_ENTRIES;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
InputStream stream = Toolbox.class.getClassLoader().getResourceAsStream("bedrock/cached_palette.json");
|
InputStream stream = Toolbox.class.getClassLoader().getResourceAsStream("bedrock/cached_palette.json");
|
||||||
|
@ -79,7 +81,7 @@ public class Toolbox {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Integer, ItemEntry> itemEntries = new HashMap<>();
|
TIntObjectMap<ItemEntry> itemEntries = new TIntObjectHashMap<>();
|
||||||
int itemIndex = 0;
|
int itemIndex = 0;
|
||||||
|
|
||||||
for (Map.Entry<String, Map<String, Object>> itemEntry : items.entrySet()) {
|
for (Map.Entry<String, Map<String, Object>> itemEntry : items.entrySet()) {
|
||||||
|
@ -87,7 +89,7 @@ public class Toolbox {
|
||||||
itemIndex++;
|
itemIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ITEM_ENTRIES = Collections.unmodifiableMap(itemEntries);
|
ITEM_ENTRIES = itemEntries;
|
||||||
|
|
||||||
InputStream blockStream = Toolbox.class.getClassLoader().getResourceAsStream("blocks.json");
|
InputStream blockStream = Toolbox.class.getClassLoader().getResourceAsStream("blocks.json");
|
||||||
ObjectMapper blockMapper = new ObjectMapper();
|
ObjectMapper blockMapper = new ObjectMapper();
|
||||||
|
@ -99,7 +101,7 @@ public class Toolbox {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Integer, BlockEntry> blockEntries = new HashMap<>();
|
TIntObjectMap<BlockEntry> blockEntries = new TIntObjectHashMap<>();
|
||||||
int blockIndex = 0;
|
int blockIndex = 0;
|
||||||
|
|
||||||
for (Map.Entry<String, Map<String, Object>> itemEntry : blocks.entrySet()) {
|
for (Map.Entry<String, Map<String, Object>> itemEntry : blocks.entrySet()) {
|
||||||
|
@ -113,6 +115,6 @@ public class Toolbox {
|
||||||
blockIndex++;
|
blockIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
BLOCK_ENTRIES = Collections.unmodifiableMap(blockEntries);
|
BLOCK_ENTRIES = blockEntries;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue