diff --git a/README.md b/README.md
index 11d7e835d..9da7caf5d 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@ The ultimate goal of this project is to allow Minecraft: Bedrock Edition users t
Special thanks to the DragonProxy project for being a trailblazer in protocol translation and for all the team members who have joined us here!
-### Currently supporting Minecraft Bedrock 1.17 - 1.17.2 and Minecraft Java 1.17.1.
+### Currently supporting Minecraft Bedrock 1.17.0 - 1.17.10 and Minecraft Java 1.17.1.
## Setting Up
Take a look [here](https://github.com/GeyserMC/Geyser/wiki/Setup) for how to set up Geyser.
diff --git a/bootstrap/bungeecord/pom.xml b/bootstrap/bungeecord/pom.xml
index 710c8176e..0f13390d5 100644
--- a/bootstrap/bungeecord/pom.xml
+++ b/bootstrap/bungeecord/pom.xml
@@ -6,7 +6,7 @@
org.geysermc
bootstrap-parent
- 1.4.0-SNAPSHOT
+ 1.4.1-SNAPSHOT
bootstrap-bungeecord
@@ -14,7 +14,7 @@
org.geysermc
connector
- 1.4.0-SNAPSHOT
+ 1.4.1-SNAPSHOT
compile
diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml
index bf31f3fea..98a08ee31 100644
--- a/bootstrap/pom.xml
+++ b/bootstrap/pom.xml
@@ -6,7 +6,7 @@
org.geysermc
geyser-parent
- 1.4.0-SNAPSHOT
+ 1.4.1-SNAPSHOT
bootstrap-parent
pom
diff --git a/bootstrap/spigot/pom.xml b/bootstrap/spigot/pom.xml
index 4d295b66d..133ea7779 100644
--- a/bootstrap/spigot/pom.xml
+++ b/bootstrap/spigot/pom.xml
@@ -6,7 +6,7 @@
org.geysermc
bootstrap-parent
- 1.4.0-SNAPSHOT
+ 1.4.1-SNAPSHOT
bootstrap-spigot
@@ -21,7 +21,7 @@
org.geysermc
connector
- 1.4.0-SNAPSHOT
+ 1.4.1-SNAPSHOT
compile
diff --git a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/GeyserSpigot1_11CraftingListener.java b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/GeyserSpigot1_11CraftingListener.java
index eff79c7cc..4f24af19c 100644
--- a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/GeyserSpigot1_11CraftingListener.java
+++ b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/GeyserSpigot1_11CraftingListener.java
@@ -50,7 +50,7 @@ import org.bukkit.inventory.ShapelessRecipe;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.item.ItemTranslator;
-import org.geysermc.connector.network.translators.item.RecipeRegistry;
+import org.geysermc.connector.utils.InventoryUtils;
import java.util.*;
@@ -94,7 +94,7 @@ public class GeyserSpigot1_11CraftingListener implements Listener {
}
public void sendServerRecipes(GeyserSession session) {
- int netId = RecipeRegistry.LAST_RECIPE_NET_ID;
+ int netId = InventoryUtils.LAST_RECIPE_NET_ID;
CraftingDataPacket craftingDataPacket = new CraftingDataPacket();
craftingDataPacket.setCleanRecipes(true);
@@ -106,7 +106,7 @@ public class GeyserSpigot1_11CraftingListener implements Listener {
Pair outputs = translateToBedrock(session, recipe.getResult());
ItemStack javaOutput = outputs.getKey();
ItemData output = outputs.getValue();
- if (output.getId() == 0) continue; // If items make air we don't want that
+ if (output == null || output.getId() == 0) continue; // If items make air we don't want that
boolean isNotAllAir = false; // Check for all-air recipes
if (recipe instanceof ShapedRecipe) {
diff --git a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/GeyserSpigotBlockPlaceListener.java b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/GeyserSpigotBlockPlaceListener.java
index 51e68a263..8111c7e56 100644
--- a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/GeyserSpigotBlockPlaceListener.java
+++ b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/GeyserSpigotBlockPlaceListener.java
@@ -35,7 +35,8 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator;
+import org.geysermc.connector.network.translators.world.block.BlockStateValues;
+import org.geysermc.connector.registry.BlockRegistries;
import org.geysermc.platform.spigot.world.manager.GeyserSpigotWorldManager;
@AllArgsConstructor
@@ -53,11 +54,11 @@ public class GeyserSpigotBlockPlaceListener implements Listener {
placeBlockSoundPacket.setPosition(Vector3f.from(event.getBlockPlaced().getX(), event.getBlockPlaced().getY(), event.getBlockPlaced().getZ()));
placeBlockSoundPacket.setBabySound(false);
if (worldManager.isLegacy()) {
- placeBlockSoundPacket.setExtraData(session.getBlockTranslator().getBedrockBlockId(worldManager.getBlockAt(session,
+ placeBlockSoundPacket.setExtraData(session.getBlockMappings().getBedrockBlockId(worldManager.getBlockAt(session,
event.getBlockPlaced().getX(), event.getBlockPlaced().getY(), event.getBlockPlaced().getZ())));
} else {
String javaBlockId = event.getBlockPlaced().getBlockData().getAsString();
- placeBlockSoundPacket.setExtraData(session.getBlockTranslator().getBedrockBlockId(BlockTranslator.getJavaIdBlockMap().getOrDefault(javaBlockId, BlockTranslator.JAVA_AIR_ID)));
+ placeBlockSoundPacket.setExtraData(session.getBlockMappings().getBedrockBlockId(BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(javaBlockId, BlockStateValues.JAVA_AIR_ID)));
}
placeBlockSoundPacket.setIdentifier(":");
session.sendUpstreamPacket(placeBlockSoundPacket);
diff --git a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigot1_12NativeWorldManager.java b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigot1_12NativeWorldManager.java
index c59cb0d77..1875d3451 100644
--- a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigot1_12NativeWorldManager.java
+++ b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigot1_12NativeWorldManager.java
@@ -31,7 +31,7 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator;
+import org.geysermc.connector.network.translators.world.block.BlockStateValues;
import org.geysermc.geyser.adapters.spigot.SpigotAdapters;
import org.geysermc.geyser.adapters.spigot.SpigotWorldAdapter;
@@ -51,7 +51,7 @@ public class GeyserSpigot1_12NativeWorldManager extends GeyserSpigot1_12WorldMan
public int getBlockAt(GeyserSession session, int x, int y, int z) {
Player player = Bukkit.getPlayer(session.getPlayerEntity().getUsername());
if (player == null) {
- return BlockTranslator.JAVA_AIR_ID;
+ return BlockStateValues.JAVA_AIR_ID;
}
// Get block entity storage
BlockStorage storage = Via.getManager().getConnectionManager().getConnectedClient(player.getUniqueId()).get(BlockStorage.class);
diff --git a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigot1_12WorldManager.java b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigot1_12WorldManager.java
index b50aefee7..e32b52f24 100644
--- a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigot1_12WorldManager.java
+++ b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigot1_12WorldManager.java
@@ -37,7 +37,7 @@ import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator;
+import org.geysermc.connector.network.translators.world.block.BlockStateValues;
import java.util.List;
@@ -70,11 +70,11 @@ public class GeyserSpigot1_12WorldManager extends GeyserSpigotWorldManager {
public int getBlockAt(GeyserSession session, int x, int y, int z) {
Player player = Bukkit.getPlayer(session.getPlayerEntity().getUsername());
if (player == null) {
- return BlockTranslator.JAVA_AIR_ID;
+ return BlockStateValues.JAVA_AIR_ID;
}
if (!player.getWorld().isChunkLoaded(x >> 4, z >> 4)) {
// Prevent nasty async errors if a player is loading in
- return BlockTranslator.JAVA_AIR_ID;
+ return BlockStateValues.JAVA_AIR_ID;
}
// Get block entity storage
BlockStorage storage = Via.getManager().getConnectionManager().getConnectedClient(player.getUniqueId()).get(BlockStorage.class);
diff --git a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotFallbackWorldManager.java b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotFallbackWorldManager.java
index 8bd2c6628..88721b8b1 100644
--- a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotFallbackWorldManager.java
+++ b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotFallbackWorldManager.java
@@ -27,7 +27,7 @@ package org.geysermc.platform.spigot.world.manager;
import org.bukkit.plugin.Plugin;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator;
+import org.geysermc.connector.network.translators.world.block.BlockStateValues;
/**
* Should only be used when we know {@link GeyserSpigotWorldManager#getBlockAt(GeyserSession, int, int, int)}
@@ -41,7 +41,7 @@ public class GeyserSpigotFallbackWorldManager extends GeyserSpigotWorldManager {
@Override
public int getBlockAt(GeyserSession session, int x, int y, int z) {
- return BlockTranslator.JAVA_AIR_ID;
+ return BlockStateValues.JAVA_AIR_ID;
}
@Override
diff --git a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotNativeWorldManager.java b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotNativeWorldManager.java
index 7e0b9267b..91a589da1 100644
--- a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotNativeWorldManager.java
+++ b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotNativeWorldManager.java
@@ -29,7 +29,7 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator;
+import org.geysermc.connector.network.translators.world.block.BlockStateValues;
import org.geysermc.geyser.adapters.spigot.SpigotAdapters;
import org.geysermc.geyser.adapters.spigot.SpigotWorldAdapter;
@@ -45,7 +45,7 @@ public class GeyserSpigotNativeWorldManager extends GeyserSpigotWorldManager {
public int getBlockAt(GeyserSession session, int x, int y, int z) {
Player player = Bukkit.getPlayer(session.getPlayerEntity().getUsername());
if (player == null) {
- return BlockTranslator.JAVA_AIR_ID;
+ return BlockStateValues.JAVA_AIR_ID;
}
return adapter.getBlockAt(player.getWorld(), x, y, z);
}
diff --git a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotWorldManager.java b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotWorldManager.java
index 6746a8d1a..be6342172 100644
--- a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotWorldManager.java
+++ b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotWorldManager.java
@@ -42,7 +42,8 @@ import org.bukkit.plugin.Plugin;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.inventory.translators.LecternInventoryTranslator;
import org.geysermc.connector.network.translators.world.GeyserWorldManager;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator;
+import org.geysermc.connector.network.translators.world.block.BlockStateValues;
+import org.geysermc.connector.registry.BlockRegistries;
import org.geysermc.connector.utils.BlockEntityUtils;
import org.geysermc.connector.utils.GameRule;
@@ -68,15 +69,15 @@ public class GeyserSpigotWorldManager extends GeyserWorldManager {
public int getBlockAt(GeyserSession session, int x, int y, int z) {
Player bukkitPlayer;
if ((bukkitPlayer = Bukkit.getPlayer(session.getPlayerEntity().getUsername())) == null) {
- return BlockTranslator.JAVA_AIR_ID;
+ return BlockStateValues.JAVA_AIR_ID;
}
World world = bukkitPlayer.getWorld();
if (!world.isChunkLoaded(x >> 4, z >> 4)) {
// If the chunk isn't loaded, how could we even be here?
- return BlockTranslator.JAVA_AIR_ID;
+ return BlockStateValues.JAVA_AIR_ID;
}
- return BlockTranslator.getJavaIdBlockMap().getOrDefault(world.getBlockAt(x, y, z).getBlockData().getAsString(), BlockTranslator.JAVA_AIR_ID);
+ return BlockRegistries.JAVA_IDENTIFIERS.getOrDefault(world.getBlockAt(x, y, z).getBlockData().getAsString(), BlockStateValues.JAVA_AIR_ID);
}
@Override
diff --git a/bootstrap/sponge/pom.xml b/bootstrap/sponge/pom.xml
index 72733a311..e0f019152 100644
--- a/bootstrap/sponge/pom.xml
+++ b/bootstrap/sponge/pom.xml
@@ -6,7 +6,7 @@
org.geysermc
bootstrap-parent
- 1.4.0-SNAPSHOT
+ 1.4.1-SNAPSHOT
bootstrap-sponge
@@ -14,7 +14,7 @@
org.geysermc
connector
- 1.4.0-SNAPSHOT
+ 1.4.1-SNAPSHOT
compile
diff --git a/bootstrap/standalone/pom.xml b/bootstrap/standalone/pom.xml
index 2d28a7535..64aa54745 100644
--- a/bootstrap/standalone/pom.xml
+++ b/bootstrap/standalone/pom.xml
@@ -6,7 +6,7 @@
org.geysermc
bootstrap-parent
- 1.4.0-SNAPSHOT
+ 1.4.1-SNAPSHOT
bootstrap-standalone
@@ -14,7 +14,7 @@
org.geysermc
connector
- 1.4.0-SNAPSHOT
+ 1.4.1-SNAPSHOT
compile
diff --git a/bootstrap/velocity/pom.xml b/bootstrap/velocity/pom.xml
index e44d7b48f..c67f5a628 100644
--- a/bootstrap/velocity/pom.xml
+++ b/bootstrap/velocity/pom.xml
@@ -6,7 +6,7 @@
org.geysermc
bootstrap-parent
- 1.4.0-SNAPSHOT
+ 1.4.1-SNAPSHOT
bootstrap-velocity
@@ -14,7 +14,7 @@
org.geysermc
connector
- 1.4.0-SNAPSHOT
+ 1.4.1-SNAPSHOT
compile
diff --git a/common/pom.xml b/common/pom.xml
index 8ddcfd981..2dfa63a42 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -6,7 +6,7 @@
org.geysermc
geyser-parent
- 1.4.0-SNAPSHOT
+ 1.4.1-SNAPSHOT
common
diff --git a/connector/pom.xml b/connector/pom.xml
index b05a969b9..4c8391766 100644
--- a/connector/pom.xml
+++ b/connector/pom.xml
@@ -6,7 +6,7 @@
org.geysermc
geyser-parent
- 1.4.0-SNAPSHOT
+ 1.4.1-SNAPSHOT
connector
@@ -21,7 +21,7 @@
org.geysermc
common
- 1.4.0-SNAPSHOT
+ 1.4.1-SNAPSHOT
compile
@@ -57,8 +57,8 @@
com.github.CloudburstMC.Protocol
- bedrock-v440
- 1656151
+ bedrock-v448
+ ddfa38b
compile
diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java
index 9c3386e38..291f2d7e5 100644
--- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java
+++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java
@@ -44,20 +44,11 @@ import org.geysermc.connector.configuration.GeyserConfiguration;
import org.geysermc.connector.metrics.Metrics;
import org.geysermc.connector.network.ConnectorServerEventHandler;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.BiomeTranslator;
-import org.geysermc.connector.network.translators.EntityIdentifierRegistry;
+import org.geysermc.connector.registry.BlockRegistries;
+import org.geysermc.connector.registry.Registries;
import org.geysermc.connector.network.translators.PacketTranslatorRegistry;
-import org.geysermc.connector.network.translators.collision.CollisionTranslator;
-import org.geysermc.connector.network.translators.effect.EffectRegistry;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.network.translators.item.ItemTranslator;
-import org.geysermc.connector.network.translators.item.PotionMixRegistry;
-import org.geysermc.connector.network.translators.item.RecipeRegistry;
-import org.geysermc.connector.network.translators.sound.SoundHandlerRegistry;
-import org.geysermc.connector.network.translators.sound.SoundRegistry;
import org.geysermc.connector.network.translators.world.WorldManager;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator;
-import org.geysermc.connector.network.translators.world.block.entity.BlockEntityTranslator;
import org.geysermc.connector.network.translators.world.block.entity.SkullBlockEntityTranslator;
import org.geysermc.connector.skin.FloodgateSkinUploader;
import org.geysermc.connector.utils.*;
@@ -158,19 +149,11 @@ public class GeyserConnector {
PacketTranslatorRegistry.init();
/* Initialize translators and registries */
- BiomeTranslator.init();
- BlockTranslator.init();
- BlockEntityTranslator.init();
- EffectRegistry.init();
- EntityIdentifierRegistry.init();
- ItemRegistry.init();
+ BlockRegistries.init();
+ Registries.init();
+
ItemTranslator.init();
- CollisionTranslator.init();
LocaleUtils.init();
- PotionMixRegistry.init();
- RecipeRegistry.init();
- SoundRegistry.init();
- SoundHandlerRegistry.init();
ResourcePack.loadPacks();
diff --git a/connector/src/main/java/org/geysermc/connector/entity/AreaEffectCloudEntity.java b/connector/src/main/java/org/geysermc/connector/entity/AreaEffectCloudEntity.java
index 5a33bc98c..218275ae8 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/AreaEffectCloudEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/AreaEffectCloudEntity.java
@@ -32,7 +32,7 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.effect.EffectRegistry;
+import org.geysermc.connector.utils.EffectUtils;
public class AreaEffectCloudEntity extends Entity {
@@ -59,7 +59,7 @@ public class AreaEffectCloudEntity extends Entity {
metadata.put(EntityData.EFFECT_COLOR, entityMetadata.getValue());
} else if (entityMetadata.getId() == 11) {
Particle particle = (Particle) entityMetadata.getValue();
- int particleId = EffectRegistry.getParticleId(session, particle.getType());
+ int particleId = EffectUtils.getParticleId(session, particle.getType());
if (particleId != -1) {
metadata.put(EntityData.AREA_EFFECT_CLOUD_PARTICLE_ID, particleId);
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/CommandBlockMinecartEntity.java b/connector/src/main/java/org/geysermc/connector/entity/CommandBlockMinecartEntity.java
index bda4e7972..c04e9f0b7 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/CommandBlockMinecartEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/CommandBlockMinecartEntity.java
@@ -60,7 +60,7 @@ public class CommandBlockMinecartEntity extends DefaultBlockMinecartEntity {
*/
@Override
public void updateDefaultBlockMetadata(GeyserSession session) {
- metadata.put(EntityData.DISPLAY_ITEM, session.getBlockTranslator().getBedrockRuntimeCommandBlockId());
+ metadata.put(EntityData.DISPLAY_ITEM, session.getBlockMappings().getCommandBlockRuntimeId());
metadata.put(EntityData.DISPLAY_OFFSET, 6);
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/DefaultBlockMinecartEntity.java b/connector/src/main/java/org/geysermc/connector/entity/DefaultBlockMinecartEntity.java
index 24e5bb259..5df7ae440 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/DefaultBlockMinecartEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/DefaultBlockMinecartEntity.java
@@ -60,7 +60,7 @@ public class DefaultBlockMinecartEntity extends MinecartEntity {
customBlock = (int) entityMetadata.getValue();
if (showCustomBlock) {
- metadata.put(EntityData.DISPLAY_ITEM, session.getBlockTranslator().getBedrockBlockId(customBlock));
+ metadata.put(EntityData.DISPLAY_ITEM, session.getBlockMappings().getBedrockBlockId(customBlock));
}
}
@@ -77,7 +77,7 @@ public class DefaultBlockMinecartEntity extends MinecartEntity {
if (entityMetadata.getId() == 13) {
if ((boolean) entityMetadata.getValue()) {
showCustomBlock = true;
- metadata.put(EntityData.DISPLAY_ITEM, session.getBlockTranslator().getBedrockBlockId(customBlock));
+ metadata.put(EntityData.DISPLAY_ITEM, session.getBlockMappings().getBedrockBlockId(customBlock));
metadata.put(EntityData.DISPLAY_OFFSET, customBlockOffset);
} else {
showCustomBlock = false;
diff --git a/connector/src/main/java/org/geysermc/connector/entity/FallingBlockEntity.java b/connector/src/main/java/org/geysermc/connector/entity/FallingBlockEntity.java
index bd0fe9b80..a82118c21 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/FallingBlockEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/FallingBlockEntity.java
@@ -42,7 +42,7 @@ public class FallingBlockEntity extends Entity {
@Override
public void spawnEntity(GeyserSession session) {
- this.metadata.put(EntityData.VARIANT, session.getBlockTranslator().getBedrockBlockId(javaId));
+ this.metadata.put(EntityData.VARIANT, session.getBlockMappings().getBedrockBlockId(javaId));
super.spawnEntity(session);
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/FishingHookEntity.java b/connector/src/main/java/org/geysermc/connector/entity/FishingHookEntity.java
index db44a0767..66cfe386d 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/FishingHookEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/FishingHookEntity.java
@@ -36,10 +36,10 @@ import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.collision.BoundingBox;
import org.geysermc.connector.network.translators.collision.CollisionManager;
-import org.geysermc.connector.network.translators.collision.CollisionTranslator;
import org.geysermc.connector.network.translators.collision.translators.BlockCollision;
import org.geysermc.connector.network.translators.world.block.BlockStateValues;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator;
+import org.geysermc.connector.registry.BlockRegistries;
+import org.geysermc.connector.utils.BlockUtils;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
@@ -97,14 +97,14 @@ public class FishingHookEntity extends ThrowableEntity {
boolean collided = false;
for (Vector3i blockPos : collidableBlocks) {
int blockID = session.getConnector().getWorldManager().getBlockAt(session, blockPos);
- BlockCollision blockCollision = CollisionTranslator.getCollision(blockID, blockPos.getX(), blockPos.getY(), blockPos.getZ());
+ BlockCollision blockCollision = BlockUtils.getCollision(blockID, blockPos.getX(), blockPos.getY(), blockPos.getZ());
if (blockCollision != null && blockCollision.checkIntersection(boundingBox)) {
// TODO Push bounding box out of collision to improve movement
collided = true;
}
int waterLevel = BlockStateValues.getWaterLevel(blockID);
- if (BlockTranslator.isWaterlogged(blockID)) {
+ if (BlockRegistries.WATERLOGGED.get().contains(blockID)) {
waterLevel = 0;
}
if (waterLevel >= 0) {
@@ -175,7 +175,7 @@ public class FishingHookEntity extends ThrowableEntity {
*/
protected boolean isInAir(GeyserSession session) {
int block = session.getConnector().getWorldManager().getBlockAt(session, position.toInt());
- return block == BlockTranslator.JAVA_AIR_ID;
+ return block == BlockStateValues.JAVA_AIR_ID;
}
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/entity/FurnaceMinecartEntity.java b/connector/src/main/java/org/geysermc/connector/entity/FurnaceMinecartEntity.java
index 2eb083883..fea1e62bd 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/FurnaceMinecartEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/FurnaceMinecartEntity.java
@@ -30,7 +30,7 @@ import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator;
+import org.geysermc.connector.network.translators.world.block.BlockStateValues;
public class FurnaceMinecartEntity extends DefaultBlockMinecartEntity {
@@ -52,7 +52,7 @@ public class FurnaceMinecartEntity extends DefaultBlockMinecartEntity {
@Override
public void updateDefaultBlockMetadata(GeyserSession session) {
- metadata.put(EntityData.DISPLAY_ITEM, session.getBlockTranslator().getBedrockBlockId(hasFuel ? BlockTranslator.JAVA_RUNTIME_FURNACE_LIT_ID : BlockTranslator.JAVA_RUNTIME_FURNACE_ID));
+ metadata.put(EntityData.DISPLAY_ITEM, session.getBlockMappings().getBedrockBlockId(hasFuel ? BlockStateValues.JAVA_FURNACE_LIT_ID : BlockStateValues.JAVA_FURNACE_ID));
metadata.put(EntityData.DISPLAY_OFFSET, 6);
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/ItemFrameEntity.java b/connector/src/main/java/org/geysermc/connector/entity/ItemFrameEntity.java
index f2f36e606..dfa989c1d 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/ItemFrameEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/ItemFrameEntity.java
@@ -38,9 +38,8 @@ import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import lombok.Getter;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.network.translators.item.ItemTranslator;
+import org.geysermc.connector.registry.type.ItemMapping;
import java.util.concurrent.TimeUnit;
@@ -85,12 +84,12 @@ public class ItemFrameEntity extends Entity {
public void spawnEntity(GeyserSession session) {
NbtMapBuilder blockBuilder = NbtMap.builder()
.putString("name", this.entityType == EntityType.GLOW_ITEM_FRAME ? "minecraft:glow_frame" : "minecraft:frame")
- .putInt("version", session.getBlockTranslator().getBlockStateVersion());
+ .putInt("version", session.getBlockMappings().getBlockStateVersion());
blockBuilder.put("states", NbtMap.builder()
.putInt("facing_direction", direction.ordinal())
.putByte("item_frame_map_bit", (byte) 0)
.build());
- bedrockRuntimeId = session.getBlockTranslator().getItemFrame(blockBuilder.build());
+ bedrockRuntimeId = session.getBlockMappings().getItemFrame(blockBuilder.build());
bedrockPosition = Vector3i.from(position.getFloorX(), position.getFloorY(), position.getFloorZ());
session.getItemFrameCache().put(bedrockPosition, this);
@@ -108,7 +107,7 @@ public class ItemFrameEntity extends Entity {
if (entityMetadata.getId() == 8 && entityMetadata.getValue() != null) {
this.heldItem = (ItemStack) entityMetadata.getValue();
ItemData itemData = ItemTranslator.translateToBedrock(session, heldItem);
- ItemEntry itemEntry = ItemRegistry.getItem((ItemStack) entityMetadata.getValue());
+ ItemMapping mapping = session.getItemMappings().getMapping((ItemStack) entityMetadata.getValue());
NbtMapBuilder builder = NbtMap.builder();
builder.putByte("Count", (byte) itemData.getCount());
@@ -116,7 +115,7 @@ public class ItemFrameEntity extends Entity {
builder.put("tag", itemData.getTag());
}
builder.putShort("Damage", (short) itemData.getDamage());
- builder.putString("Name", itemEntry.getBedrockIdentifier());
+ builder.putString("Name", mapping.getBedrockIdentifier());
NbtMapBuilder tag = getDefaultTag().toBuilder();
tag.put("Item", builder.build());
tag.putFloat("ItemDropChance", 1.0f);
@@ -149,7 +148,7 @@ public class ItemFrameEntity extends Entity {
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
updateBlockPacket.setDataLayer(0);
updateBlockPacket.setBlockPosition(bedrockPosition);
- updateBlockPacket.setRuntimeId(session.getBlockTranslator().getBedrockAirId());
+ updateBlockPacket.setRuntimeId(session.getBlockMappings().getBedrockAirId());
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.PRIORITY);
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NETWORK);
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
diff --git a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java
index e1c85fc08..5ba66f71a 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java
@@ -45,7 +45,7 @@ import lombok.Setter;
import org.geysermc.connector.entity.attribute.GeyserAttributeType;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
+import org.geysermc.connector.registry.type.ItemMapping;
import org.geysermc.connector.utils.AttributeUtils;
import org.geysermc.connector.utils.ChunkUtils;
@@ -89,8 +89,9 @@ public class LivingEntity extends Entity {
//blocking gets triggered when using a bow, but if we set USING_ITEM for all items, it may look like
//you're "mining" with ex. a shield.
- boolean isUsingShield = (getHand().getId() == ItemRegistry.SHIELD.getBedrockId() ||
- getHand().equals(ItemData.AIR) && getOffHand().getId() == ItemRegistry.SHIELD.getBedrockId());
+ ItemMapping shield = session.getItemMappings().getStoredItems().shield();
+ boolean isUsingShield = (getHand().getId() == shield.getBedrockId() ||
+ getHand().equals(ItemData.AIR) && getOffHand().getId() == shield.getBedrockId());
metadata.getFlags().setFlag(EntityFlag.USING_ITEM, (xd & 0x01) == 0x01 && !isUsingShield);
metadata.getFlags().setFlag(EntityFlag.BLOCKING, (xd & 0x01) == 0x01);
@@ -171,10 +172,11 @@ public class LivingEntity extends Entity {
ItemData chestplate = this.chestplate;
// If an entity has a banner on them, it will be in the helmet slot in Java but the chestplate spot in Bedrock
// But don't overwrite the chestplate if it isn't empty
- if (chestplate.getId() == ItemData.AIR.getId() && helmet.getId() == ItemRegistry.BANNER.getBedrockId()) {
+ ItemMapping banner = session.getItemMappings().getStoredItems().banner();
+ if (chestplate.getId() == ItemData.AIR.getId() && helmet.getId() == banner.getBedrockId()) {
chestplate = this.helmet;
helmet = ItemData.AIR;
- } else if (chestplate.getId() == ItemRegistry.BANNER.getBedrockId()) {
+ } else if (chestplate.getId() == banner.getBedrockId()) {
// Prevent chestplate banners from showing erroneously
chestplate = ItemData.AIR;
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/MinecartEntity.java b/connector/src/main/java/org/geysermc/connector/entity/MinecartEntity.java
index 18d1d92a1..6ab9a1b22 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/MinecartEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/MinecartEntity.java
@@ -57,7 +57,7 @@ public class MinecartEntity extends Entity {
if (!(this instanceof DefaultBlockMinecartEntity)) { // Handled in the DefaultBlockMinecartEntity class
// Custom block
if (entityMetadata.getId() == 11) {
- metadata.put(EntityData.DISPLAY_ITEM, session.getBlockTranslator().getBedrockBlockId((int) entityMetadata.getValue()));
+ metadata.put(EntityData.DISPLAY_ITEM, session.getBlockMappings().getBedrockBlockId((int) entityMetadata.getValue()));
}
// Custom block offset
diff --git a/connector/src/main/java/org/geysermc/connector/entity/SpawnerMinecartEntity.java b/connector/src/main/java/org/geysermc/connector/entity/SpawnerMinecartEntity.java
index 2f7af73eb..c6d4c3aa5 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/SpawnerMinecartEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/SpawnerMinecartEntity.java
@@ -29,7 +29,7 @@ import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator;
+import org.geysermc.connector.network.translators.world.block.BlockStateValues;
public class SpawnerMinecartEntity extends DefaultBlockMinecartEntity {
@@ -39,7 +39,7 @@ public class SpawnerMinecartEntity extends DefaultBlockMinecartEntity {
@Override
public void updateDefaultBlockMetadata(GeyserSession session) {
- metadata.put(EntityData.DISPLAY_ITEM, session.getBlockTranslator().getBedrockBlockId(BlockTranslator.JAVA_RUNTIME_SPAWNER_ID));
+ metadata.put(EntityData.DISPLAY_ITEM, session.getBlockMappings().getBedrockBlockId(BlockStateValues.JAVA_SPAWNER_ID));
metadata.put(EntityData.DISPLAY_OFFSET, 6);
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/ThrownPotionEntity.java b/connector/src/main/java/org/geysermc/connector/entity/ThrownPotionEntity.java
index 9ce218a81..735bf274c 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/ThrownPotionEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/ThrownPotionEntity.java
@@ -36,9 +36,8 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.network.translators.item.Potion;
+import org.geysermc.connector.registry.type.ItemMapping;
import java.util.EnumSet;
@@ -53,8 +52,8 @@ public class ThrownPotionEntity extends ThrowableEntity {
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
if (entityMetadata.getId() == 8 && entityMetadata.getType() == MetadataType.ITEM) {
ItemStack itemStack = (ItemStack) entityMetadata.getValue();
- ItemEntry itemEntry = ItemRegistry.getItem(itemStack);
- if (itemEntry.getJavaIdentifier().endsWith("potion") && itemStack.getNbt() != null) {
+ ItemMapping mapping = session.getItemMappings().getMapping(itemStack);
+ if (mapping.getJavaIdentifier().endsWith("potion") && itemStack.getNbt() != null) {
Tag potionTag = itemStack.getNbt().get("Potion");
if (potionTag instanceof StringTag) {
Potion potion = Potion.getByJavaIdentifier(((StringTag) potionTag).getValue());
@@ -67,7 +66,7 @@ public class ThrownPotionEntity extends ThrowableEntity {
}
}
- boolean isLingering = itemEntry.getJavaIdentifier().equals("minecraft:lingering_potion");
+ boolean isLingering = mapping.getJavaIdentifier().equals("minecraft:lingering_potion");
metadata.getFlags().setFlag(EntityFlag.LINGERING, isLingering);
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/AnimalEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/AnimalEntity.java
index efded1f6f..2495eab0a 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/AnimalEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/AnimalEntity.java
@@ -29,7 +29,7 @@ import com.nukkitx.math.vector.Vector3f;
import org.geysermc.connector.entity.living.AgeableEntity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
public class AnimalEntity extends AgeableEntity {
@@ -42,7 +42,7 @@ public class AnimalEntity extends AgeableEntity {
* wheat
.
* @return true if this is a valid item to breed with for this animal.
*/
- public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
+ public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemMapping mapping) {
// This is what it defaults to. OK.
return javaIdentifierStripped.equals("wheat");
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/AxolotlEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/AxolotlEntity.java
index 7c6c81ba2..f3d634140 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/AxolotlEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/AxolotlEntity.java
@@ -31,7 +31,7 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
public class AxolotlEntity extends AnimalEntity {
public AxolotlEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
@@ -59,7 +59,7 @@ public class AxolotlEntity extends AnimalEntity {
}
@Override
- public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
+ public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemMapping mapping) {
return javaIdentifierStripped.equals("tropical_fish_bucket");
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/BeeEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/BeeEntity.java
index 59035bb85..07136252a 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/BeeEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/BeeEntity.java
@@ -33,7 +33,7 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
public class BeeEntity extends AnimalEntity {
@@ -66,7 +66,7 @@ public class BeeEntity extends AnimalEntity {
}
@Override
- public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
- return session.getTagCache().isFlower(itemEntry);
+ public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemMapping mapping) {
+ return session.getTagCache().isFlower(mapping);
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/ChickenEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/ChickenEntity.java
index b5f0395d4..c7eb62c6e 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/ChickenEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/ChickenEntity.java
@@ -28,7 +28,7 @@ package org.geysermc.connector.entity.living.animal;
import com.nukkitx.math.vector.Vector3f;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
public class ChickenEntity extends AnimalEntity {
@@ -37,7 +37,7 @@ public class ChickenEntity extends AnimalEntity {
}
@Override
- public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
+ public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemMapping mapping) {
return javaIdentifierStripped.contains("seeds");
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/FoxEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/FoxEntity.java
index 2c1934139..26da89612 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/FoxEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/FoxEntity.java
@@ -31,7 +31,7 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
public class FoxEntity extends AnimalEntity {
@@ -55,7 +55,7 @@ public class FoxEntity extends AnimalEntity {
}
@Override
- public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
- return session.getTagCache().isFoxFood(itemEntry);
+ public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemMapping mapping) {
+ return session.getTagCache().isFoxFood(mapping);
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/HoglinEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/HoglinEntity.java
index 492ff68a8..d782dc53e 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/HoglinEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/HoglinEntity.java
@@ -30,7 +30,7 @@ import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
import org.geysermc.connector.utils.DimensionUtils;
public class HoglinEntity extends AnimalEntity {
@@ -57,7 +57,7 @@ public class HoglinEntity extends AnimalEntity {
}
@Override
- public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
+ public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemMapping mapping) {
return javaIdentifierStripped.equals("crimson_fungus");
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/OcelotEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/OcelotEntity.java
index 48a5e08bf..98e7140cd 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/OcelotEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/OcelotEntity.java
@@ -30,7 +30,7 @@ import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
public class OcelotEntity extends AnimalEntity {
@@ -47,7 +47,7 @@ public class OcelotEntity extends AnimalEntity {
}
@Override
- public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
+ public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemMapping mapping) {
return javaIdentifierStripped.equals("cod") || javaIdentifierStripped.equals("salmon");
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/PandaEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/PandaEntity.java
index 83f0ed8d9..39049d91a 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/PandaEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/PandaEntity.java
@@ -33,8 +33,7 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
+import org.geysermc.connector.registry.type.ItemMapping;
public class PandaEntity extends AnimalEntity {
@@ -55,7 +54,7 @@ public class PandaEntity extends AnimalEntity {
EntityEventPacket packet = new EntityEventPacket();
packet.setRuntimeEntityId(geyserId);
packet.setType(EntityEventType.EATING_ITEM);
- packet.setData(ItemRegistry.BAMBOO.getBedrockId() << 16);
+ packet.setData(session.getItemMappings().getStoredItems().bamboo().getBedrockId() << 16);
session.sendUpstreamPacket(packet);
}
}
@@ -81,7 +80,7 @@ public class PandaEntity extends AnimalEntity {
}
@Override
- public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
+ public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemMapping mapping) {
return javaIdentifierStripped.equals("bamboo");
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/PigEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/PigEntity.java
index bc07472ea..ba6bfd553 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/PigEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/PigEntity.java
@@ -30,7 +30,7 @@ import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
public class PigEntity extends AnimalEntity {
@@ -47,7 +47,7 @@ public class PigEntity extends AnimalEntity {
}
@Override
- public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
+ public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemMapping mapping) {
return javaIdentifierStripped.equals("carrot") || javaIdentifierStripped.equals("potato") || javaIdentifierStripped.equals("beetroot");
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/PolarBearEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/PolarBearEntity.java
index 8f292411d..893def315 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/PolarBearEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/PolarBearEntity.java
@@ -30,7 +30,7 @@ import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
public class PolarBearEntity extends AnimalEntity {
@@ -47,7 +47,7 @@ public class PolarBearEntity extends AnimalEntity {
}
@Override
- public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
+ public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemMapping mapping) {
return false;
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/RabbitEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/RabbitEntity.java
index 41579d6a6..0f0e1fb3e 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/RabbitEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/RabbitEntity.java
@@ -31,7 +31,7 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
public class RabbitEntity extends AnimalEntity {
@@ -65,7 +65,7 @@ public class RabbitEntity extends AnimalEntity {
}
@Override
- public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
+ public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemMapping mapping) {
return javaIdentifierStripped.equals("dandelion") || javaIdentifierStripped.equals("carrot") || javaIdentifierStripped.equals("golden_carrot");
}
}
\ No newline at end of file
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/StriderEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/StriderEntity.java
index 437f60cb4..83c1e3674 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/StriderEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/StriderEntity.java
@@ -31,7 +31,7 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
public class StriderEntity extends AnimalEntity {
@@ -93,7 +93,7 @@ public class StriderEntity extends AnimalEntity {
}
@Override
- public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
+ public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemMapping mapping) {
return javaIdentifierStripped.equals("warped_fungus");
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/TurtleEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/TurtleEntity.java
index 7e9e3260d..b26b21ee2 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/TurtleEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/TurtleEntity.java
@@ -30,7 +30,7 @@ import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
public class TurtleEntity extends AnimalEntity {
@@ -49,7 +49,7 @@ public class TurtleEntity extends AnimalEntity {
}
@Override
- public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
+ public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemMapping mapping) {
return javaIdentifierStripped.equals("seagrass");
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/AbstractHorseEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/AbstractHorseEntity.java
index d4aed4196..e255d2856 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/AbstractHorseEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/AbstractHorseEntity.java
@@ -38,8 +38,7 @@ import org.geysermc.connector.entity.attribute.GeyserAttributeType;
import org.geysermc.connector.entity.living.animal.AnimalEntity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
+import org.geysermc.connector.registry.type.ItemMapping;
import java.util.Set;
@@ -105,7 +104,7 @@ public class AbstractHorseEntity extends AnimalEntity {
EntityEventPacket entityEventPacket = new EntityEventPacket();
entityEventPacket.setRuntimeEntityId(geyserId);
entityEventPacket.setType(EntityEventType.EATING_ITEM);
- entityEventPacket.setData(ItemRegistry.WHEAT.getBedrockId() << 16);
+ entityEventPacket.setData(session.getItemMappings().getStoredItems().wheat().getBedrockId() << 16);
session.sendUpstreamPacket(entityEventPacket);
}
@@ -120,7 +119,7 @@ public class AbstractHorseEntity extends AnimalEntity {
}
@Override
- public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
+ public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemMapping mapping) {
return DONKEY_AND_HORSE_FOODS.contains(javaIdentifierStripped);
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java
index 67e3304d3..14e625c81 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java
@@ -32,8 +32,7 @@ import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import com.nukkitx.protocol.bedrock.packet.MobArmorEquipmentPacket;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
+import org.geysermc.connector.registry.type.ItemMapping;
public class LlamaEntity extends ChestedHorseEntity {
@@ -59,7 +58,7 @@ public class LlamaEntity extends ChestedHorseEntity {
if (carpetIndex > -1 && carpetIndex <= 15) {
// The damage value is the dye color that Java sends us, for pre-1.16.220
// The item is always going to be a carpet
- equipmentPacket.setChestplate(ItemRegistry.CARPETS.get(carpetIndex));
+ equipmentPacket.setChestplate(session.getItemMappings().getCarpets().get(carpetIndex));
} else {
equipmentPacket.setChestplate(ItemData.AIR);
}
@@ -78,7 +77,7 @@ public class LlamaEntity extends ChestedHorseEntity {
}
@Override
- public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
+ public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemMapping mapping) {
return javaIdentifierStripped.equals("wheat") || javaIdentifierStripped.equals("hay_block");
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java
index ac4142988..904f563f9 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java
@@ -31,7 +31,7 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
public class CatEntity extends TameableEntity {
@@ -91,7 +91,7 @@ public class CatEntity extends TameableEntity {
}
@Override
- public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
+ public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemMapping mapping) {
return javaIdentifierStripped.equals("cod") || javaIdentifierStripped.equals("salmon");
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java
index dcc9d6f78..1bb75931e 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java
@@ -30,7 +30,7 @@ import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
public class ParrotEntity extends TameableEntity {
@@ -48,7 +48,7 @@ public class ParrotEntity extends TameableEntity {
}
@Override
- public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
+ public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemMapping mapping) {
return javaIdentifierStripped.contains("seeds") || javaIdentifierStripped.equals("cookie");
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java
index 0a5d2a58c..183719dbb 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java
@@ -32,7 +32,7 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
import java.util.Set;
@@ -88,7 +88,7 @@ public class WolfEntity extends TameableEntity {
}
@Override
- public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
+ public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemMapping mapping) {
// Cannot be a baby to eat these foods
return WOLF_FOODS.contains(javaIdentifierStripped) && !metadata.getFlags().getFlag(EntityFlag.BABY);
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java
index 1ba8b595b..3c94f9de2 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java
@@ -36,7 +36,7 @@ import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator;
+import org.geysermc.connector.registry.BlockRegistries;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -114,7 +114,7 @@ public class VillagerEntity extends AbstractMerchantEntity {
if (bedPosition != null) {
bedId = session.getConnector().getWorldManager().getBlockAt(session, bedPosition);
}
- String bedRotationZ = BlockTranslator.getJavaIdBlockMap().inverse().get(bedId);
+ String bedRotationZ = BlockRegistries.JAVA_IDENTIFIERS.get().inverse().get(bedId);
setRotation(rotation);
setOnGround(isOnGround);
this.position = Vector3f.from(position.getX() + relX, position.getY() + relY, position.getZ() + relZ);
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/EnderDragonEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/EnderDragonEntity.java
index 8e9dca997..d3d6e30d5 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/EnderDragonEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/EnderDragonEntity.java
@@ -27,7 +27,6 @@ package org.geysermc.connector.entity.living.monster;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.nukkitx.math.vector.Vector3f;
-import com.nukkitx.protocol.bedrock.data.AttributeData;
import com.nukkitx.protocol.bedrock.data.LevelEventType;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityEventType;
@@ -35,7 +34,6 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import com.nukkitx.protocol.bedrock.packet.*;
import lombok.Data;
import org.geysermc.connector.entity.Tickable;
-import org.geysermc.connector.entity.attribute.GeyserAttributeType;
import org.geysermc.connector.entity.living.InsentientEntity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/EndermanEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/EndermanEntity.java
index f11e57a8f..e187d7f0b 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/EndermanEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/EndermanEntity.java
@@ -44,7 +44,7 @@ public class EndermanEntity extends MonsterEntity {
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
// Held block
if (entityMetadata.getId() == 16) {
- metadata.put(EntityData.CARRIED_BLOCK, session.getBlockTranslator().getBedrockBlockId((int) entityMetadata.getValue()));
+ metadata.put(EntityData.CARRIED_BLOCK, session.getBlockMappings().getBedrockBlockId((int) entityMetadata.getValue()));
}
// "Is screaming" - controls sound
if (entityMetadata.getId() == 17) {
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/PiglinEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/PiglinEntity.java
index 5b1ccd342..860f6dfd3 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/PiglinEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/PiglinEntity.java
@@ -31,7 +31,6 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
public class PiglinEntity extends BasePiglinEntity {
@@ -61,7 +60,7 @@ public class PiglinEntity extends BasePiglinEntity {
@Override
public void updateOffHand(GeyserSession session) {
// Check if the Piglin is holding Gold and set the ADMIRING flag accordingly so its pose updates
- boolean changed = metadata.getFlags().setFlag(EntityFlag.ADMIRING, session.getTagCache().shouldPiglinAdmire(ItemRegistry.getItem(this.offHand)));
+ boolean changed = metadata.getFlags().setFlag(EntityFlag.ADMIRING, session.getTagCache().shouldPiglinAdmire(session.getItemMappings().getMapping(this.offHand)));
if (changed) {
super.updateBedrockMetadata(session);
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/raid/PillagerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/raid/PillagerEntity.java
index 73794586f..325cac7ab 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/raid/PillagerEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/raid/PillagerEntity.java
@@ -29,7 +29,7 @@ import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
+import org.geysermc.connector.registry.type.ItemMapping;
public class PillagerEntity extends AbstractIllagerEntity {
@@ -55,8 +55,9 @@ public class PillagerEntity extends AbstractIllagerEntity {
* Check for a crossbow in either the mainhand or offhand. If one exists, indicate that the pillager should be posing
*/
protected void checkForCrossbow(GeyserSession session) {
- boolean hasCrossbow = this.hand.getId() == ItemRegistry.CROSSBOW.getBedrockId()
- || this.offHand.getId() == ItemRegistry.CROSSBOW.getBedrockId();
+ ItemMapping crossbow = session.getItemMappings().getStoredItems().crossbow();
+ boolean hasCrossbow = this.hand.getId() == crossbow.getBedrockId()
+ || this.offHand.getId() == crossbow.getBedrockId();
boolean usingItemChanged = metadata.getFlags().setFlag(EntityFlag.USING_ITEM, hasCrossbow);
boolean chargedChanged = metadata.getFlags().setFlag(EntityFlag.CHARGED, hasCrossbow);
diff --git a/connector/src/main/java/org/geysermc/connector/inventory/GeyserItemStack.java b/connector/src/main/java/org/geysermc/connector/inventory/GeyserItemStack.java
index 1cfd425d9..b80757fbd 100644
--- a/connector/src/main/java/org/geysermc/connector/inventory/GeyserItemStack.java
+++ b/connector/src/main/java/org/geysermc/connector/inventory/GeyserItemStack.java
@@ -30,9 +30,8 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import lombok.Data;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemEntry;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.network.translators.item.ItemTranslator;
+import org.geysermc.connector.registry.type.ItemMapping;
@Data
public class GeyserItemStack {
@@ -105,8 +104,8 @@ public class GeyserItemStack {
return itemData;
}
- public ItemEntry getItemEntry() {
- return ItemRegistry.ITEM_ENTRIES.get(getJavaId());
+ public ItemMapping getMapping(GeyserSession session) {
+ return session.getItemMappings().getMapping(this.javaId);
}
public boolean isEmpty() {
diff --git a/connector/src/main/java/org/geysermc/connector/network/BedrockProtocol.java b/connector/src/main/java/org/geysermc/connector/network/BedrockProtocol.java
index 84fc449e9..0be6eefae 100644
--- a/connector/src/main/java/org/geysermc/connector/network/BedrockProtocol.java
+++ b/connector/src/main/java/org/geysermc/connector/network/BedrockProtocol.java
@@ -27,6 +27,7 @@ package org.geysermc.connector.network;
import com.nukkitx.protocol.bedrock.BedrockPacketCodec;
import com.nukkitx.protocol.bedrock.v440.Bedrock_v440;
+import com.nukkitx.protocol.bedrock.v448.Bedrock_v448;
import java.util.ArrayList;
import java.util.List;
@@ -47,6 +48,7 @@ public class BedrockProtocol {
static {
SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC);
+ SUPPORTED_BEDROCK_CODECS.add(Bedrock_v448.V448_CODEC);
}
/**
diff --git a/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java b/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java
index be34ca81b..159924541 100644
--- a/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java
+++ b/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java
@@ -35,8 +35,8 @@ import org.geysermc.connector.common.AuthType;
import org.geysermc.connector.configuration.GeyserConfiguration;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslatorRegistry;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator1_17_0;
+import org.geysermc.connector.registry.BlockRegistries;
+import org.geysermc.connector.registry.Registries;
import org.geysermc.connector.utils.*;
import java.io.FileInputStream;
@@ -71,7 +71,8 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
session.getUpstream().getSession().setPacketCodec(packetCodec);
// Set the block translation based off of version
- session.setBlockTranslator(BlockTranslator1_17_0.INSTANCE);
+ session.setBlockMappings(BlockRegistries.BLOCKS.forVersion(loginPacket.getProtocolVersion()));
+ session.setItemMappings(Registries.ITEMS.forVersion(loginPacket.getProtocolVersion()));
LoginEncryptionUtils.encryptPlayerConnection(connector, session, loginPacket);
@@ -131,7 +132,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
stackPacket.getResourcePacks().add(new ResourcePackStackPacket.Entry(header.getUuid().toString(), header.getVersionString(), ""));
}
- if (ItemRegistry.FURNACE_MINECART_DATA != null) {
+ if (session.getItemMappings().getFurnaceMinecartData() != null) {
// Allow custom items to work
stackPacket.getExperiments().add(new ExperimentData("data_driven_items", true));
}
@@ -194,6 +195,8 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
titlePacket.setFadeInTime(0);
titlePacket.setFadeOutTime(1);
titlePacket.setStayTime(2);
+ titlePacket.setXuid("");
+ titlePacket.setPlatformOnlineId("");
session.sendUpstreamPacket(titlePacket);
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java
index 8c5455d1e..512f248ac 100644
--- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java
+++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java
@@ -86,14 +86,13 @@ import org.geysermc.connector.inventory.PlayerInventory;
import org.geysermc.connector.network.session.auth.AuthData;
import org.geysermc.connector.network.session.auth.BedrockClientData;
import org.geysermc.connector.network.session.cache.*;
-import org.geysermc.connector.network.translators.BiomeTranslator;
-import org.geysermc.connector.network.translators.EntityIdentifierRegistry;
import org.geysermc.connector.network.translators.PacketTranslatorRegistry;
import org.geysermc.connector.network.translators.chat.MessageTranslator;
import org.geysermc.connector.network.translators.collision.CollisionManager;
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator;
+import org.geysermc.connector.registry.Registries;
+import org.geysermc.connector.registry.type.BlockMappings;
+import org.geysermc.connector.registry.type.ItemMappings;
import org.geysermc.connector.skin.FloodgateSkinUploader;
import org.geysermc.connector.skin.SkinManager;
import org.geysermc.connector.utils.*;
@@ -175,10 +174,16 @@ public class GeyserSession implements CommandSender {
private final CollisionManager collisionManager;
/**
- * Stores the block translations for this specific version.
+ * Stores the block mappings for this specific version.
*/
@Setter
- private BlockTranslator blockTranslator;
+ private BlockMappings blockMappings;
+
+ /**
+ * Stores the item translations for this specific version.
+ */
+ @Setter
+ private ItemMappings itemMappings;
private final Map skullCache = new ConcurrentHashMap<>();
private final Long2ObjectMap storedMaps = Long2ObjectMaps.synchronize(new Long2ObjectOpenHashMap<>());
@@ -487,26 +492,26 @@ public class GeyserSession implements CommandSender {
this.remoteAuthType = connector.getDefaultAuthType();
// Set the hardcoded shield ID to the ID we just defined in StartGamePacket
- upstream.getSession().getHardcodedBlockingId().set(ItemRegistry.SHIELD.getBedrockId());
+ upstream.getSession().getHardcodedBlockingId().set(this.itemMappings.getStoredItems().shield().getBedrockId());
- if (ItemRegistry.FURNACE_MINECART_DATA != null) {
+ if (this.itemMappings.getFurnaceMinecartData() != null) {
ItemComponentPacket componentPacket = new ItemComponentPacket();
- componentPacket.getItems().add(ItemRegistry.FURNACE_MINECART_DATA);
+ componentPacket.getItems().add(this.itemMappings.getFurnaceMinecartData());
upstream.sendPacket(componentPacket);
}
ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false);
BiomeDefinitionListPacket biomeDefinitionListPacket = new BiomeDefinitionListPacket();
- biomeDefinitionListPacket.setDefinitions(BiomeTranslator.BIOMES);
+ biomeDefinitionListPacket.setDefinitions(Registries.BIOMES.get());
upstream.sendPacket(biomeDefinitionListPacket);
AvailableEntityIdentifiersPacket entityPacket = new AvailableEntityIdentifiersPacket();
- entityPacket.setIdentifiers(EntityIdentifierRegistry.ENTITY_IDENTIFIERS);
+ entityPacket.setIdentifiers(Registries.ENTITY_IDENTIFIERS.get());
upstream.sendPacket(entityPacket);
CreativeContentPacket creativePacket = new CreativeContentPacket();
- creativePacket.setContents(ItemRegistry.CREATIVE_ITEMS);
+ creativePacket.setContents(this.itemMappings.getCreativeItems());
upstream.sendPacket(creativePacket);
PlayStatusPacket playStatusPacket = new PlayStatusPacket();
@@ -1054,7 +1059,7 @@ public class GeyserSession implements CommandSender {
// startGamePacket.setCurrentTick(0);
startGamePacket.setEnchantmentSeed(0);
startGamePacket.setMultiplayerCorrelationId("");
- startGamePacket.setItemEntries(ItemRegistry.ITEMS);
+ startGamePacket.setItemEntries(this.itemMappings.getItemEntries());
startGamePacket.setVanillaVersion("*");
startGamePacket.setInventoriesServerAuthoritative(true);
startGamePacket.setServerEngine(""); // Do we want to fill this in?
diff --git a/connector/src/main/java/org/geysermc/connector/network/session/UpstreamSession.java b/connector/src/main/java/org/geysermc/connector/network/session/UpstreamSession.java
index f973574b0..11df3139c 100644
--- a/connector/src/main/java/org/geysermc/connector/network/session/UpstreamSession.java
+++ b/connector/src/main/java/org/geysermc/connector/network/session/UpstreamSession.java
@@ -63,4 +63,13 @@ public class UpstreamSession {
public InetSocketAddress getAddress() {
return session.getRealAddress();
}
+
+ /**
+ * Gets the session's protocol version.
+ *
+ * @return the session's protocol version.
+ */
+ public int getProtocolVersion() {
+ return this.session.getPacketCodec().getProtocolVersion();
+ }
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/BookEditCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/BookEditCache.java
index cb3737895..d2ee8f552 100644
--- a/connector/src/main/java/org/geysermc/connector/network/session/cache/BookEditCache.java
+++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/BookEditCache.java
@@ -29,7 +29,6 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientEditB
import lombok.Setter;
import org.geysermc.connector.inventory.GeyserItemStack;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
/**
* Manages updating the current writable book.
@@ -64,7 +63,7 @@ public class BookEditCache {
}
// Don't send the update if the player isn't not holding a book, shouldn't happen if we catch all interactions
GeyserItemStack itemStack = session.getPlayerInventory().getItemInHand();
- if (itemStack == null || itemStack.getJavaId() != ItemRegistry.WRITABLE_BOOK.getJavaId()) {
+ if (itemStack == null || itemStack.getJavaId() != this.session.getItemMappings().getStoredItems().writableBook().getJavaId()) {
packet = null;
return;
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java
index 4f93b0f53..72d271a79 100644
--- a/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java
+++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java
@@ -31,7 +31,7 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import lombok.Setter;
import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator;
+import org.geysermc.connector.network.translators.world.block.BlockStateValues;
import org.geysermc.connector.network.translators.world.chunk.GeyserColumn;
import org.geysermc.connector.utils.MathUtils;
@@ -81,11 +81,11 @@ public class ChunkCache {
Chunk chunk = column.getChunks()[(y >> 4) - getChunkMinY()];
if (chunk == null) {
- if (block != BlockTranslator.JAVA_AIR_ID) {
+ if (block != BlockStateValues.JAVA_AIR_ID) {
// A previously empty chunk, which is no longer empty as a block has been added to it
chunk = new Chunk();
// Fixes the chunk assuming that all blocks is the `block` variable we are updating. /shrug
- chunk.getPalette().stateToId(BlockTranslator.JAVA_AIR_ID);
+ chunk.getPalette().stateToId(BlockStateValues.JAVA_AIR_ID);
column.getChunks()[(y >> 4) - getChunkMinY()] = chunk;
} else {
// Nothing to update
@@ -98,17 +98,17 @@ public class ChunkCache {
public int getBlockAt(int x, int y, int z) {
if (!cache) {
- return BlockTranslator.JAVA_AIR_ID;
+ return BlockStateValues.JAVA_AIR_ID;
}
GeyserColumn column = this.getChunk(x >> 4, z >> 4);
if (column == null) {
- return BlockTranslator.JAVA_AIR_ID;
+ return BlockStateValues.JAVA_AIR_ID;
}
if (y < minY || (y >> 4) > column.getChunks().length - 1) {
// Y likely goes above or below the height limit of this world
- return BlockTranslator.JAVA_AIR_ID;
+ return BlockStateValues.JAVA_AIR_ID;
}
Chunk chunk = column.getChunks()[(y >> 4) - getChunkMinY()];
@@ -116,7 +116,7 @@ public class ChunkCache {
return chunk.get(x & 0xF, y & 0xF, z & 0xF);
}
- return BlockTranslator.JAVA_AIR_ID;
+ return BlockStateValues.JAVA_AIR_ID;
}
public void removeChunk(int chunkX, int chunkZ) {
diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/TagCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/TagCache.java
index b1427a864..e10e4dad5 100644
--- a/connector/src/main/java/org/geysermc/connector/network/session/cache/TagCache.java
+++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/TagCache.java
@@ -28,8 +28,8 @@ package org.geysermc.connector.network.session.cache;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerDeclareTagsPacket;
import it.unimi.dsi.fastutil.ints.IntList;
import it.unimi.dsi.fastutil.ints.IntLists;
-import org.geysermc.connector.network.translators.item.ItemEntry;
import org.geysermc.connector.registry.type.BlockMapping;
+import org.geysermc.connector.registry.type.ItemMapping;
import java.util.Map;
@@ -99,16 +99,16 @@ public class TagCache {
this.piglinLoved = IntLists.emptyList();
}
- public boolean isFlower(ItemEntry itemEntry) {
- return flowers.contains(itemEntry.getJavaId());
+ public boolean isFlower(ItemMapping mapping) {
+ return flowers.contains(mapping.getJavaId());
}
- public boolean isFoxFood(ItemEntry itemEntry) {
- return foxFood.contains(itemEntry.getJavaId());
+ public boolean isFoxFood(ItemMapping mapping) {
+ return foxFood.contains(mapping.getJavaId());
}
- public boolean shouldPiglinAdmire(ItemEntry itemEntry) {
- return piglinLoved.contains(itemEntry.getJavaId());
+ public boolean shouldPiglinAdmire(ItemMapping mapping) {
+ return piglinLoved.contains(mapping.getJavaId());
}
public boolean isAxeEffective(BlockMapping blockMapping) {
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockBlockPickRequestTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockBlockPickRequestTranslator.java
index 493789bbb..3a3a4bbed 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockBlockPickRequestTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockBlockPickRequestTranslator.java
@@ -32,7 +32,8 @@ import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator;
+import org.geysermc.connector.network.translators.world.block.BlockStateValues;
+import org.geysermc.connector.registry.BlockRegistries;
import org.geysermc.connector.utils.InventoryUtils;
@Translator(packet = BlockPickRequestPacket.class)
@@ -44,7 +45,7 @@ public class BedrockBlockPickRequestTranslator extends PacketTranslator= 2 && session.getGameMode() == GameMode.CREATIVE) {
// Otherwise insufficient permissions
- int blockState = session.getBlockTranslator().getJavaBlockState(packet.getBlockRuntimeId());
- String blockName = BlockTranslator.getJavaIdBlockMap().inverse().getOrDefault(blockState, "");
+ int blockState = session.getBlockMappings().getJavaBlockState(packet.getBlockRuntimeId());
+ String blockName = BlockRegistries.JAVA_IDENTIFIERS.get().inverse().getOrDefault(blockState, "");
// In the future this can be used for structure blocks too, however not all elements
// are available in each GUI
if (blockName.contains("jigsaw")) {
@@ -243,7 +246,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator
switch (packet.getAction()) {
case INTERACT:
- if (session.getPlayerInventory().getItemInHand().getJavaId() == ItemRegistry.SHIELD.getJavaId()) {
+ if (session.getPlayerInventory().getItemInHand().getJavaId() == session.getItemMappings().getStoredItems().shield().getJavaId()) {
break;
}
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/collision/CollisionManager.java b/connector/src/main/java/org/geysermc/connector/network/translators/collision/CollisionManager.java
index b6d0ae176..ceb528650 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/collision/CollisionManager.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/collision/CollisionManager.java
@@ -39,7 +39,8 @@ import org.geysermc.connector.entity.player.PlayerEntity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.collision.translators.BlockCollision;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator;
+import org.geysermc.connector.network.translators.world.block.BlockStateValues;
+import org.geysermc.connector.utils.BlockUtils;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
@@ -228,7 +229,7 @@ public class CollisionManager {
// Used when correction code needs to be run before the main correction
for (Vector3i blockPos : collidableBlocks) {
- BlockCollision blockCollision = CollisionTranslator.getCollisionAt(
+ BlockCollision blockCollision = BlockUtils.getCollisionAt(
session, blockPos.getX(), blockPos.getY(), blockPos.getZ()
);
if (blockCollision != null) {
@@ -238,7 +239,7 @@ public class CollisionManager {
// Main correction code
for (Vector3i blockPos : collidableBlocks) {
- BlockCollision blockCollision = CollisionTranslator.getCollisionAt(
+ BlockCollision blockCollision = BlockUtils.getCollisionAt(
session, blockPos.getX(), blockPos.getY(), blockPos.getZ()
);
if (blockCollision != null) {
@@ -259,7 +260,7 @@ public class CollisionManager {
*/
public boolean isUnderSlab() {
Vector3i position = session.getPlayerEntity().getPosition().toInt();
- BlockCollision collision = CollisionTranslator.getCollisionAt(session, position.getX(), position.getY(), position.getZ());
+ BlockCollision collision = BlockUtils.getCollisionAt(session, position.getX(), position.getY(), position.getZ());
if (collision != null) {
// Determine, if the player's bounding box *were* at full height, if it would intersect with the block
// at the current location.
@@ -275,7 +276,7 @@ public class CollisionManager {
* @return if the player is currently in a water block
*/
public boolean isPlayerInWater() {
- return session.getConnector().getWorldManager().getBlockAt(session, session.getPlayerEntity().getPosition().toInt()) == BlockTranslator.JAVA_WATER_ID;
+ return session.getConnector().getWorldManager().getBlockAt(session, session.getPlayerEntity().getPosition().toInt()) == BlockStateValues.JAVA_WATER_ID;
}
/**
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/effect/EffectRegistry.java b/connector/src/main/java/org/geysermc/connector/network/translators/effect/EffectRegistry.java
deleted file mode 100644
index 91b21fb2a..000000000
--- a/connector/src/main/java/org/geysermc/connector/network/translators/effect/EffectRegistry.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * @author GeyserMC
- * @link https://github.com/GeyserMC/Geyser
- */
-
-package org.geysermc.connector.network.translators.effect;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.github.steveice10.mc.protocol.data.game.world.effect.SoundEffect;
-import com.github.steveice10.mc.protocol.data.game.world.particle.ParticleType;
-import com.nukkitx.protocol.bedrock.data.LevelEventType;
-import com.nukkitx.protocol.bedrock.data.SoundEvent;
-import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
-import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
-import lombok.NonNull;
-import org.geysermc.connector.GeyserConnector;
-import org.geysermc.connector.network.session.GeyserSession;
-import org.geysermc.connector.utils.FileUtils;
-
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * Registry for particles and effects.
- */
-public class EffectRegistry {
-
- public static final Map SOUND_EFFECTS = new HashMap<>();
- public static final Int2ObjectMap RECORDS = new Int2ObjectOpenHashMap<>();
-
- /**
- * Java particle type to Bedrock level event
- */
- private static final Map PARTICLE_TO_LEVEL_EVENT = new HashMap<>();
- /**
- * Java particle type to Bedrock namespaced string ID
- */
- private static final Map PARTICLE_TO_STRING = new HashMap<>();
-
- public static void init() {
- // no-op
- }
-
- static {
- /* Load particles */
- InputStream particleStream = FileUtils.getResource("mappings/particles.json");
- JsonNode particleEntries;
- try {
- particleEntries = GeyserConnector.JSON_MAPPER.readTree(particleStream);
- } catch (Exception e) {
- throw new AssertionError("Unable to load particle map", e);
- }
-
- Iterator> particlesIterator = particleEntries.fields();
- try {
- while (particlesIterator.hasNext()) {
- Map.Entry entry = particlesIterator.next();
- JsonNode bedrockId = entry.getValue().get("bedrockId");
- JsonNode eventType = entry.getValue().get("eventType");
- if (bedrockId != null) {
- PARTICLE_TO_STRING.put(ParticleType.valueOf(entry.getKey().toUpperCase()), bedrockId.asText());
- }
- if (eventType != null) {
- PARTICLE_TO_LEVEL_EVENT.put(ParticleType.valueOf(entry.getKey().toUpperCase()), LevelEventType.valueOf(eventType.asText().toUpperCase()));
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- /* Load effects */
- InputStream effectsStream = FileUtils.getResource("mappings/effects.json");
- JsonNode effects;
- try {
- effects = GeyserConnector.JSON_MAPPER.readTree(effectsStream);
- } catch (Exception e) {
- throw new AssertionError("Unable to load effects mappings", e);
- }
-
- Iterator> effectsIterator = effects.fields();
- while (effectsIterator.hasNext()) {
- Map.Entry entry = effectsIterator.next();
- JsonNode node = entry.getValue();
- try {
- String type = node.get("type").asText();
- SoundEffect javaEffect = null;
- Effect effect = null;
- switch (type) {
- case "soundLevel": {
- javaEffect = SoundEffect.valueOf(entry.getKey());
- LevelEventType levelEventType = LevelEventType.valueOf(node.get("name").asText());
- int data = node.has("data") ? node.get("data").intValue() : 0;
- effect = new SoundLevelEffect(levelEventType, data);
- break;
- }
- case "soundEvent": {
- javaEffect = SoundEffect.valueOf(entry.getKey());
- SoundEvent soundEvent = SoundEvent.valueOf(node.get("name").asText());
- String identifier = node.has("identifier") ? node.get("identifier").asText() : "";
- int extraData = node.has("extraData") ? node.get("extraData").intValue() : -1;
- effect = new SoundEventEffect(soundEvent, identifier, extraData);
- break;
- }
- case "playSound": {
- javaEffect = SoundEffect.valueOf(entry.getKey());
- String name = node.get("name").asText();
- float volume = node.has("volume") ? node.get("volume").floatValue() : 1.0f;
- boolean pitchSub = node.has("pitch_sub") && node.get("pitch_sub").booleanValue();
- float pitchMul = node.has("pitch_mul") ? node.get("pitch_mul").floatValue() : 1.0f;
- float pitchAdd = node.has("pitch_add") ? node.get("pitch_add").floatValue() : 0.0f;
- boolean relative = node.has("relative") && node.get("relative").booleanValue();
- effect = new PlaySoundEffect(name, volume, pitchSub, pitchMul, pitchAdd, relative);
- break;
- }
- case "record": {
- // Special case handled in ItemRegistry
- break;
- }
- }
- if (javaEffect != null) {
- SOUND_EFFECTS.put(javaEffect, effect);
- }
- } catch (Exception e) {
- GeyserConnector.getInstance().getLogger().warning("Failed to map sound effect " + entry.getKey() + " : " + e.toString());
- }
- }
- }
-
- /**
- * Used for area effect clouds.
- *
- * @param type the Java particle to search for
- * @return the Bedrock integer ID of the particle, or -1 if it does not exist
- */
- public static int getParticleId(GeyserSession session, @NonNull ParticleType type) {
- LevelEventType levelEventType = getParticleLevelEventType(type);
- if (levelEventType == null) {
- return -1;
- }
-
- // Remove the legacy bit applied to particles for LevelEventType serialization
- return session.getUpstream().getSession().getPacketCodec().getHelper().getLevelEventId(levelEventType) & ~0x4000;
- }
-
- /**
- * @param type the Java particle to search for
- * @return the level event equivalent Bedrock particle
- */
- public static LevelEventType getParticleLevelEventType(@NonNull ParticleType type) {
- return PARTICLE_TO_LEVEL_EVENT.getOrDefault(type, null);
- }
-
- /**
- * @param type the Java particle to search for
- * @return the namespaced ID equivalent for Bedrock
- */
- public static String getParticleString(@NonNull ParticleType type) {
- return PARTICLE_TO_STRING.getOrDefault(type, null);
- }
-}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java
index c8af7f38f..2ca80041b 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java
@@ -843,7 +843,7 @@ public abstract class InventoryTranslator {
for (int slot : affectedSlots) {
BedrockContainerSlot bedrockSlot = javaSlotToBedrockContainer(slot);
List list = containerMap.computeIfAbsent(bedrockSlot.getContainer(), k -> new ArrayList<>());
- list.add(makeItemEntry(bedrockSlot.getSlot(), inventory.getItem(slot)));
+ list.add(makeItemEntry(session, bedrockSlot.getSlot(), inventory.getItem(slot)));
}
List containerEntries = new ArrayList<>();
@@ -851,13 +851,13 @@ public abstract class InventoryTranslator {
containerEntries.add(new ItemStackResponsePacket.ContainerEntry(entry.getKey(), entry.getValue()));
}
- ItemStackResponsePacket.ItemEntry cursorEntry = makeItemEntry(0, session.getPlayerInventory().getCursor());
+ ItemStackResponsePacket.ItemEntry cursorEntry = makeItemEntry(session, 0, session.getPlayerInventory().getCursor());
containerEntries.add(new ItemStackResponsePacket.ContainerEntry(ContainerSlotType.CURSOR, Collections.singletonList(cursorEntry)));
return containerEntries;
}
- public static ItemStackResponsePacket.ItemEntry makeItemEntry(int bedrockSlot, GeyserItemStack itemStack) {
+ public static ItemStackResponsePacket.ItemEntry makeItemEntry(GeyserSession session, int bedrockSlot, GeyserItemStack itemStack) {
ItemStackResponsePacket.ItemEntry itemEntry;
if (!itemStack.isEmpty()) {
// As of 1.16.210: Bedrock needs confirmation on what the current item durability is.
@@ -866,7 +866,7 @@ public abstract class InventoryTranslator {
if (itemStack.getNbt() != null) {
Tag damage = itemStack.getNbt().get("Damage");
if (damage instanceof IntTag) {
- durability = ItemUtils.getCorrectBedrockDurability(itemStack.getJavaId(), ((IntTag) damage).getValue());
+ durability = ItemUtils.getCorrectBedrockDurability(session, itemStack.getJavaId(), ((IntTag) damage).getValue());
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/holder/BlockInventoryHolder.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/holder/BlockInventoryHolder.java
index b7f67879b..bb633780a 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/holder/BlockInventoryHolder.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/holder/BlockInventoryHolder.java
@@ -38,7 +38,7 @@ import org.geysermc.connector.inventory.Container;
import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator;
+import org.geysermc.connector.registry.BlockRegistries;
import java.util.Collections;
import java.util.HashSet;
@@ -57,7 +57,7 @@ public class BlockInventoryHolder extends InventoryHolder {
private final Set validBlocks;
public BlockInventoryHolder(String javaBlockIdentifier, ContainerType containerType, String... validBlocks) {
- this.defaultJavaBlockState = BlockTranslator.getJavaBlockState(javaBlockIdentifier);
+ this.defaultJavaBlockState = BlockRegistries.JAVA_IDENTIFIERS.get(javaBlockIdentifier);
this.containerType = containerType;
if (validBlocks != null) {
Set validBlocksTemp = new HashSet<>(validBlocks.length + 1);
@@ -77,7 +77,7 @@ public class BlockInventoryHolder extends InventoryHolder {
if (checkInteractionPosition(session)) {
// Then, check to see if the interacted block is valid for this inventory by ensuring the block state identifier is valid
int javaBlockId = session.getConnector().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition());
- String[] javaBlockString = BlockTranslator.getJavaIdBlockMap().inverse().getOrDefault(javaBlockId, "minecraft:air").split("\\[");
+ String[] javaBlockString = BlockRegistries.JAVA_IDENTIFIERS.get().inverse().getOrDefault(javaBlockId, "minecraft:air").split("\\[");
if (isValidBlock(javaBlockString)) {
// We can safely use this block
inventory.setHolderPosition(session.getLastInteractionBlockPosition());
@@ -93,7 +93,7 @@ public class BlockInventoryHolder extends InventoryHolder {
UpdateBlockPacket blockPacket = new UpdateBlockPacket();
blockPacket.setDataLayer(0);
blockPacket.setBlockPosition(position);
- blockPacket.setRuntimeId(session.getBlockTranslator().getBedrockBlockId(defaultJavaBlockState));
+ blockPacket.setRuntimeId(session.getBlockMappings().getBedrockBlockId(defaultJavaBlockState));
blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
session.sendUpstreamPacket(blockPacket);
inventory.setHolderPosition(position);
@@ -158,7 +158,7 @@ public class BlockInventoryHolder extends InventoryHolder {
UpdateBlockPacket blockPacket = new UpdateBlockPacket();
blockPacket.setDataLayer(0);
blockPacket.setBlockPosition(holderPos);
- blockPacket.setRuntimeId(session.getBlockTranslator().getBedrockBlockId(realBlock));
+ blockPacket.setRuntimeId(session.getBlockMappings().getBedrockBlockId(realBlock));
blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
session.sendUpstreamPacket(blockPacket);
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/CartographyInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/CartographyInventoryTranslator.java
index a3b50dace..76bf21bd3 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/CartographyInventoryTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/CartographyInventoryTranslator.java
@@ -48,11 +48,11 @@ public class CartographyInventoryTranslator extends AbstractBlockInventoryTransl
if (javaDestinationSlot == 0) {
// Bedrock Edition can use paper or an empty map in slot 0
GeyserItemStack itemStack = javaSourceSlot == -1 ? session.getPlayerInventory().getCursor() : inventory.getItem(javaSourceSlot);
- return itemStack.getItemEntry().getJavaIdentifier().equals("minecraft:paper") || itemStack.getItemEntry().getJavaIdentifier().equals("minecraft:map");
+ return itemStack.getMapping(session).getJavaIdentifier().equals("minecraft:paper") || itemStack.getMapping(session).getJavaIdentifier().equals("minecraft:map");
} else if (javaDestinationSlot == 1) {
// Bedrock Edition can use a compass to create locator maps, or use a filled map, in the ADDITIONAL slot
GeyserItemStack itemStack = javaSourceSlot == -1 ? session.getPlayerInventory().getCursor() : inventory.getItem(javaSourceSlot);
- return itemStack.getItemEntry().getJavaIdentifier().equals("minecraft:compass") || itemStack.getItemEntry().getJavaIdentifier().equals("minecraft:filled_map");
+ return itemStack.getMapping(session).getJavaIdentifier().equals("minecraft:compass") || itemStack.getMapping(session).getJavaIdentifier().equals("minecraft:filled_map");
}
return false;
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LoomInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LoomInventoryTranslator.java
index 17c93c15b..ec8f33f2e 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LoomInventoryTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LoomInventoryTranslator.java
@@ -112,7 +112,7 @@ public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator {
}
// Reject the item if Bedrock is attempting to put in a dye that is not a dye in Java Edition
- return !itemStack.getItemEntry().getJavaIdentifier().endsWith("_dye");
+ return !itemStack.getMapping(session).getJavaIdentifier().endsWith("_dye");
}
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/PlayerInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/PlayerInventoryTranslator.java
index e3dbec507..adde2b26f 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/PlayerInventoryTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/PlayerInventoryTranslator.java
@@ -43,16 +43,16 @@ import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.inventory.BedrockContainerSlot;
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
import org.geysermc.connector.network.translators.inventory.SlotType;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.network.translators.item.ItemTranslator;
import org.geysermc.connector.utils.InventoryUtils;
import org.geysermc.connector.utils.LanguageUtils;
import java.util.Arrays;
import java.util.Collections;
+import java.util.function.IntFunction;
public class PlayerInventoryTranslator extends InventoryTranslator {
- private static final ItemData UNUSUABLE_CRAFTING_SPACE_BLOCK = InventoryUtils.createUnusableSpaceBlock(LanguageUtils.getLocaleStringLog("geyser.inventory.unusable_item.creative"));
+ private static final IntFunction UNUSUABLE_CRAFTING_SPACE_BLOCK = InventoryUtils.createUnusableSpaceBlock(LanguageUtils.getLocaleStringLog("geyser.inventory.unusable_item.creative"));
public PlayerInventoryTranslator() {
super(46);
@@ -106,7 +106,7 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
slotPacket.setSlot(i + 27);
if (session.getGameMode() == GameMode.CREATIVE) {
- slotPacket.setItem(UNUSUABLE_CRAFTING_SPACE_BLOCK);
+ slotPacket.setItem(UNUSUABLE_CRAFTING_SPACE_BLOCK.apply(session.getUpstream().getProtocolVersion()));
} else {
slotPacket.setItem(ItemTranslator.translateToBedrock(session, inventory.getItem(i).getItemStack()));
}
@@ -384,12 +384,13 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
craftState = CraftState.RECIPE_ID;
int creativeId = creativeAction.getCreativeItemNetworkId() - 1;
- if (creativeId < 0 || creativeId >= ItemRegistry.CREATIVE_ITEMS.length) {
+ ItemData[] creativeItems = session.getItemMappings().getCreativeItems();
+ if (creativeId < 0 || creativeId >= creativeItems.length) {
return rejectRequest(request);
}
// Reference the creative items list we send to the client to know what it's asking of us
- ItemData creativeItem = ItemRegistry.CREATIVE_ITEMS[creativeId];
- javaCreativeItem = ItemTranslator.translateToJava(creativeItem);
+ ItemData creativeItem = creativeItems[creativeId];
+ javaCreativeItem = ItemTranslator.translateToJava(creativeItem, session.getItemMappings());
break;
}
case CRAFT_RESULTS_DEPRECATED: {
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/ShulkerInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/ShulkerInventoryTranslator.java
index 76d1cb1cf..4f28d0e4e 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/ShulkerInventoryTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/ShulkerInventoryTranslator.java
@@ -37,11 +37,12 @@ import org.geysermc.connector.network.translators.inventory.BedrockContainerSlot
import org.geysermc.connector.network.translators.inventory.holder.BlockInventoryHolder;
import org.geysermc.connector.network.translators.inventory.updater.ContainerInventoryUpdater;
import org.geysermc.connector.network.translators.world.block.entity.BlockEntityTranslator;
+import org.geysermc.connector.registry.Registries;
public class ShulkerInventoryTranslator extends AbstractBlockInventoryTranslator {
public ShulkerInventoryTranslator() {
super(27, new BlockInventoryHolder("minecraft:shulker_box[facing=north]", ContainerType.CONTAINER) {
- private final BlockEntityTranslator shulkerBoxTranslator = BlockEntityTranslator.BLOCK_ENTITY_TRANSLATORS.get("ShulkerBox");
+ private final BlockEntityTranslator shulkerBoxTranslator = Registries.BLOCK_ENTITIES.get("ShulkerBox");
@Override
protected boolean isValidBlock(String[] javaBlockString) {
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/StonecutterInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/StonecutterInventoryTranslator.java
index 2acce3a9b..e4dea7265 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/StonecutterInventoryTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/StonecutterInventoryTranslator.java
@@ -75,7 +75,7 @@ public class StonecutterInventoryTranslator extends AbstractBlockInventoryTransl
return rejectRequest(request);
}
- ItemStack javaOutput = ItemTranslator.translateToJava(craftData.getResultItems()[0]);
+ ItemStack javaOutput = ItemTranslator.translateToJava(craftData.getResultItems()[0], session.getItemMappings());
int button = results.indexOf(javaOutput.getId());
// If we've already pressed the button with this item, no need to press it again!
if (container.getStonecutterButton() != button) {
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/chest/DoubleChestInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/chest/DoubleChestInventoryTranslator.java
index 78ac0b609..a20cca12e 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/chest/DoubleChestInventoryTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/chest/DoubleChestInventoryTranslator.java
@@ -37,16 +37,16 @@ import org.geysermc.connector.inventory.Container;
import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.world.block.BlockStateValues;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator;
import org.geysermc.connector.network.translators.world.block.DoubleChestValue;
import org.geysermc.connector.network.translators.world.block.entity.DoubleChestBlockEntityTranslator;
+import org.geysermc.connector.registry.BlockRegistries;
public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
private final int defaultJavaBlockState;
public DoubleChestInventoryTranslator(int size) {
super(size, 54);
- this.defaultJavaBlockState = BlockTranslator.getJavaBlockState("minecraft:chest[facing=north,type=single,waterlogged=false]");
+ this.defaultJavaBlockState = BlockRegistries.JAVA_IDENTIFIERS.get("minecraft:chest[facing=north,type=single,waterlogged=false]");
}
@Override
@@ -54,7 +54,7 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
// See BlockInventoryHolder - same concept there except we're also dealing with a specific block state
if (session.getLastInteractionPlayerPosition().equals(session.getPlayerEntity().getPosition())) {
int javaBlockId = session.getConnector().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition());
- String[] javaBlockString = BlockTranslator.getJavaIdBlockMap().inverse().getOrDefault(javaBlockId, "minecraft:air").split("\\[");
+ String[] javaBlockString = BlockRegistries.JAVA_IDENTIFIERS.get().inverse().getOrDefault(javaBlockId, "minecraft:air").split("\\[");
if (javaBlockString.length > 1 && (javaBlockString[0].equals("minecraft:chest") || javaBlockString[0].equals("minecraft:trapped_chest"))
&& !javaBlockString[1].contains("type=single")) {
inventory.setHolderPosition(session.getLastInteractionBlockPosition());
@@ -82,7 +82,7 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
Vector3i position = session.getPlayerEntity().getPosition().toInt().add(Vector3i.UP);
Vector3i pairPosition = position.add(Vector3i.UNIT_X);
- int bedrockBlockId = session.getBlockTranslator().getBedrockBlockId(defaultJavaBlockState);
+ int bedrockBlockId = session.getBlockMappings().getBedrockBlockId(defaultJavaBlockState);
UpdateBlockPacket blockPacket = new UpdateBlockPacket();
blockPacket.setDataLayer(0);
@@ -154,7 +154,7 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
UpdateBlockPacket blockPacket = new UpdateBlockPacket();
blockPacket.setDataLayer(0);
blockPacket.setBlockPosition(holderPos);
- blockPacket.setRuntimeId(session.getBlockTranslator().getBedrockBlockId(realBlock));
+ blockPacket.setRuntimeId(session.getBlockMappings().getBedrockBlockId(realBlock));
session.sendUpstreamPacket(blockPacket);
holderPos = holderPos.add(Vector3i.UNIT_X);
@@ -162,7 +162,7 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
blockPacket = new UpdateBlockPacket();
blockPacket.setDataLayer(0);
blockPacket.setBlockPosition(holderPos);
- blockPacket.setRuntimeId(session.getBlockTranslator().getBedrockBlockId(realBlock));
+ blockPacket.setRuntimeId(session.getBlockMappings().getBedrockBlockId(realBlock));
session.sendUpstreamPacket(blockPacket);
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/updater/ChestInventoryUpdater.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/updater/ChestInventoryUpdater.java
index f5029f749..b421044bf 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/updater/ChestInventoryUpdater.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/updater/ChestInventoryUpdater.java
@@ -37,10 +37,11 @@ import org.geysermc.connector.utils.LanguageUtils;
import java.util.ArrayList;
import java.util.List;
+import java.util.function.IntFunction;
@AllArgsConstructor
public class ChestInventoryUpdater extends InventoryUpdater {
- private static final ItemData UNUSUABLE_SPACE_BLOCK = InventoryUtils.createUnusableSpaceBlock(LanguageUtils.getLocaleStringLog("geyser.inventory.unusable_item.slot"));
+ private static final IntFunction UNUSUABLE_SPACE_BLOCK = InventoryUtils.createUnusableSpaceBlock(LanguageUtils.getLocaleStringLog("geyser.inventory.unusable_item.slot"));
private final int paddedSize;
@@ -53,7 +54,7 @@ public class ChestInventoryUpdater extends InventoryUpdater {
if (i < translator.size) {
bedrockItems.add(inventory.getItem(i).getItemData(session));
} else {
- bedrockItems.add(UNUSUABLE_SPACE_BLOCK);
+ bedrockItems.add(UNUSUABLE_SPACE_BLOCK.apply(session.getUpstream().getProtocolVersion()));
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemRegistry.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemRegistry.java
deleted file mode 100644
index 4d8a50e85..000000000
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemRegistry.java
+++ /dev/null
@@ -1,628 +0,0 @@
-/*
- * Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * @author GeyserMC
- * @link https://github.com/GeyserMC/Geyser
- */
-
-package org.geysermc.connector.network.translators.item;
-
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
-import com.google.common.collect.ImmutableSet;
-import com.nukkitx.nbt.NbtMap;
-import com.nukkitx.nbt.NbtMapBuilder;
-import com.nukkitx.nbt.NbtType;
-import com.nukkitx.nbt.NbtUtils;
-import com.nukkitx.protocol.bedrock.data.SoundEvent;
-import com.nukkitx.protocol.bedrock.data.inventory.ComponentItemData;
-import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
-import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
-import it.unimi.dsi.fastutil.ints.*;
-import it.unimi.dsi.fastutil.objects.Object2IntMap;
-import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
-import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
-import org.geysermc.connector.GeyserConnector;
-import org.geysermc.connector.network.translators.effect.EffectRegistry;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator;
-import org.geysermc.connector.network.translators.world.block.BlockTranslator1_17_0;
-import org.geysermc.connector.utils.FileUtils;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.*;
-
-/**
- * Registry for anything item related.
- */
-public class ItemRegistry {
-
- private static final Map JAVA_IDENTIFIER_MAP = new HashMap<>();
-
- /**
- * A list of all identifiers that only exist on Java. Used to prevent creative items from becoming these unintentionally.
- */
- private static final Set JAVA_ONLY_ITEMS;
-
- public static final ItemData[] CREATIVE_ITEMS;
-
- public static final List ITEMS = new ArrayList<>();
- public static final Int2ObjectMap ITEM_ENTRIES = new Int2ObjectOpenHashMap<>();
-
- /**
- * A list of all Java item names.
- */
- public static final String[] ITEM_NAMES;
-
- /**
- * Bamboo item entry, used in PandaEntity.java
- */
- public static ItemEntry BAMBOO;
- /**
- * Banner item entry, used in LivingEntity.java
- */
- public static ItemEntry BANNER;
- /**
- * Boat item entries, used in BedrockInventoryTransactionTranslator.java
- */
- public static final IntSet BOATS = new IntArraySet();
- /**
- * Bucket item entries (excluding the milk bucket), used in BedrockInventoryTransactionTranslator.java
- */
- public static final IntSet BUCKETS = new IntArraySet();
- /**
- * Carpet item data, used in LlamaEntity.java
- */
- public static final List CARPETS = new ArrayList<>(16);
- /**
- * Crossbow item entry, used in PillagerEntity.java
- */
- public static ItemEntry CROSSBOW;
- /**
- * Fishing rod item entry, used in ItemUtils.java
- */
- public static ItemEntry FISHING_ROD;
- /**
- * Empty item bucket, used in BedrockInventoryTransactionTranslator.java
- */
- public static ItemEntry MILK_BUCKET;
- /**
- * Egg item entry, used in JavaEntityStatusTranslator.java
- */
- public static ItemEntry EGG;
- /**
- * Shield item entry, used in Entity.java and LivingEntity.java
- */
- public static ItemEntry SHIELD;
- /**
- * A list of all spawn eggs by their Bedrock IDs. Used in BedrockInventoryTransactionTranslator.java
- */
- public static final IntSet SPAWN_EGGS = new IntArraySet();
- /**
- * Wheat item entry, used in AbstractHorseEntity.java
- */
- public static ItemEntry WHEAT;
- /**
- * Writable book item entry, used in BedrockBookEditTranslator.java
- */
- public static ItemEntry WRITABLE_BOOK;
-
- public static int BARRIER_INDEX = 0;
-
- /**
- * Stores the properties and data of the "custom" furnace minecart item.
- */
- public static final ComponentItemData FURNACE_MINECART_DATA;
-
- public static void init() {
- // no-op
- }
-
- static {
- /* Load item palette */
- InputStream stream = FileUtils.getResource("bedrock/runtime_item_states.json");
-
- TypeReference> itemEntriesType = new TypeReference>() {
- };
-
- // Used to get the Bedrock namespaced ID (in instances where there are small differences)
- Int2ObjectMap bedrockIdToIdentifier = new Int2ObjectOpenHashMap<>();
-
- List itemNames = new ArrayList<>();
-
- List itemEntries;
- try {
- itemEntries = GeyserConnector.JSON_MAPPER.readValue(stream, itemEntriesType);
- } catch (Exception e) {
- throw new AssertionError("Unable to load Bedrock runtime item IDs", e);
- }
-
- int lodestoneCompassId = 0;
-
- for (JsonNode entry : itemEntries) {
- ITEMS.add(new StartGamePacket.ItemEntry(entry.get("name").textValue(), (short) entry.get("id").intValue()));
- bedrockIdToIdentifier.put(entry.get("id").intValue(), entry.get("name").textValue());
- if (entry.get("name").textValue().equals("minecraft:lodestone_compass")) {
- lodestoneCompassId = entry.get("id").intValue();
- }
- }
-
- Object2IntMap bedrockBlockIdOverrides = new Object2IntOpenHashMap<>();
- Object2IntMap blacklistedIdentifiers = new Object2IntOpenHashMap<>();
-
- // Load creative items
- // We load this before item mappings to get overridden block runtime ID mappings
- stream = FileUtils.getResource("bedrock/creative_items.json");
-
- JsonNode creativeItemEntries;
- try {
- creativeItemEntries = GeyserConnector.JSON_MAPPER.readTree(stream).get("items");
- } catch (Exception e) {
- throw new AssertionError("Unable to load creative items", e);
- }
-
- int netId = 1;
- List creativeItems = new ArrayList<>();
- for (JsonNode itemNode : creativeItemEntries) {
- int count = 1;
- int damage = 0;
- int blockRuntimeId = 0;
- NbtMap tag = null;
- JsonNode damageNode = itemNode.get("damage");
- if (damageNode != null) {
- damage = damageNode.asInt();
- }
- JsonNode countNode = itemNode.get("count");
- if (countNode != null) {
- count = countNode.asInt();
- }
- JsonNode blockRuntimeIdNode = itemNode.get("blockRuntimeId");
- if (blockRuntimeIdNode != null) {
- blockRuntimeId = blockRuntimeIdNode.asInt();
- }
- JsonNode nbtNode = itemNode.get("nbt_b64");
- if (nbtNode != null) {
- byte[] bytes = Base64.getDecoder().decode(nbtNode.asText());
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- try {
- tag = (NbtMap) NbtUtils.createReaderLE(bais).readTag();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- String identifier = itemNode.get("id").textValue();
- int id = -1;
- for (StartGamePacket.ItemEntry itemEntry : ITEMS) {
- if (itemEntry.getIdentifier().equals(identifier)) {
- id = itemEntry.getId();
- break;
- }
- }
- if (id == -1) {
- throw new RuntimeException("Unable to find matching Bedrock item for " + identifier);
- }
-
- creativeItems.add(ItemData.builder()
- .id(id)
- .damage(damage)
- .count(count)
- .blockRuntimeId(blockRuntimeId)
- .tag(tag)
- .netId(netId++).build());
-
- if (blockRuntimeId != 0) {
- // Add override for item mapping, unless it already exists... then we know multiple states can exist
- if (!blacklistedIdentifiers.containsKey(identifier)) {
- if (bedrockBlockIdOverrides.containsKey(identifier)) {
- bedrockBlockIdOverrides.remove(identifier);
- // Save this as a blacklist, but also as knowledge of what the block state name should be
- blacklistedIdentifiers.put(identifier, blockRuntimeId);
- } else {
- // Unless there's multiple possibilities for this one state, let this be
- bedrockBlockIdOverrides.put(identifier, blockRuntimeId);
- }
- }
- }
- }
-
- // Load item mappings from Java Edition to Bedrock Edition
- stream = FileUtils.getResource("mappings/items.json");
-
- JsonNode items;
- try {
- items = GeyserConnector.JSON_MAPPER.readTree(stream);
- } catch (Exception e) {
- throw new AssertionError("Unable to load Java runtime item IDs", e);
- }
-
- BlockTranslator blockTranslator = BlockTranslator1_17_0.INSTANCE;
-
- int itemIndex = 0;
- int javaFurnaceMinecartId = 0;
- boolean usingFurnaceMinecart = GeyserConnector.getInstance().getConfig().isAddNonBedrockItems();
- Iterator> iterator = items.fields();
- while (iterator.hasNext()) {
- Map.Entry entry = iterator.next();
- if (usingFurnaceMinecart && entry.getKey().equals("minecraft:furnace_minecart")) {
- javaFurnaceMinecartId = itemIndex;
- itemIndex++;
- continue;
- }
- int bedrockId = entry.getValue().get("bedrock_id").intValue();
- String bedrockIdentifier = bedrockIdToIdentifier.get(bedrockId);
- if (bedrockIdentifier == null) {
- throw new RuntimeException("Missing Bedrock ID in mappings!: " + bedrockId);
- }
- JsonNode stackSizeNode = entry.getValue().get("stack_size");
- int stackSize = stackSizeNode == null ? 64 : stackSizeNode.intValue();
-
- int bedrockBlockId = -1;
- JsonNode blockRuntimeIdNode = entry.getValue().get("blockRuntimeId");
- if (blockRuntimeIdNode != null) {
- int blockIdOverride = bedrockBlockIdOverrides.getOrDefault(bedrockIdentifier, -1);
- if (blockIdOverride != -1) {
- // Straight from BDS is our best chance of getting an item that doesn't run into issues
- bedrockBlockId = blockIdOverride;
- } else {
- // Try to get an example block runtime ID from the creative contents packet, for Bedrock identifier obtaining
- int aValidBedrockBlockId = blacklistedIdentifiers.getOrDefault(bedrockIdentifier, -1);
- if (aValidBedrockBlockId == -1) {
- // Fallback
- bedrockBlockId = blockTranslator.getBedrockBlockId(blockRuntimeIdNode.intValue());
- } else {
- // As of 1.16.220, every item requires a block runtime ID attached to it.
- // This is mostly for identifying different blocks with the same item ID - wool, slabs, some walls.
- // However, in order for some visuals and crafting to work, we need to send the first matching block state
- // as indexed by Bedrock's block palette
- // There are exceptions! But, ideally, the block ID override should take care of those.
- String javaBlockIdentifier = BlockTranslator.getBlockMapping(blockRuntimeIdNode.intValue()).getCleanJavaIdentifier();
- NbtMapBuilder requiredBlockStatesBuilder = NbtMap.builder();
- String correctBedrockIdentifier = blockTranslator.getAllBedrockBlockStates().get(aValidBedrockBlockId).getString("name");
- boolean firstPass = true;
- for (Map.Entry blockEntry : BlockTranslator.getJavaIdBlockMap().entrySet()) {
- if (blockEntry.getKey().split("\\[")[0].equals(javaBlockIdentifier)) {
- int bedrockBlockRuntimeId = blockTranslator.getBedrockBlockId(blockEntry.getValue());
- NbtMap blockTag = blockTranslator.getAllBedrockBlockStates().get(bedrockBlockRuntimeId);
- String bedrockName = blockTag.getString("name");
- if (!bedrockName.equals(correctBedrockIdentifier)) {
- continue;
- }
- NbtMap states = blockTag.getCompound("states");
-
- if (firstPass) {
- firstPass = false;
- if (states.size() == 0) {
- // No need to iterate and find all block states - this is the one, as there can't be any others
- bedrockBlockId = bedrockBlockRuntimeId;
- break;
- }
- requiredBlockStatesBuilder.putAll(states);
- continue;
- }
- for (Map.Entry nbtEntry : states.entrySet()) {
- Object value = requiredBlockStatesBuilder.get(nbtEntry.getKey());
- if (value != null && !nbtEntry.getValue().equals(value)) { // Null means this value has already been removed/deemed as unneeded
- // This state can change between different block states, and therefore is not required
- // to build a successful block state of this
- requiredBlockStatesBuilder.remove(nbtEntry.getKey());
- }
- }
- if (requiredBlockStatesBuilder.size() == 0) {
- // There are no required block states
- // E.G. there was only a direction property that is no longer in play
- // (States that are important include color for glass)
- break;
- }
- }
- }
-
- NbtMap requiredBlockStates = requiredBlockStatesBuilder.build();
- if (bedrockBlockId == -1) {
- int i = -1;
- // We need to loop around again (we can't cache the block tags above) because Bedrock can include states that we don't have a pairing for
- // in it's "preferred" block state - I.E. the first matching block state in the list
- for (NbtMap blockTag : blockTranslator.getAllBedrockBlockStates()) {
- i++;
- if (blockTag.getString("name").equals(correctBedrockIdentifier)) {
- NbtMap states = blockTag.getCompound("states");
- boolean valid = true;
- for (Map.Entry nbtEntry : requiredBlockStates.entrySet()) {
- if (!states.get(nbtEntry.getKey()).equals(nbtEntry.getValue())) {
- // A required block state doesn't match - this one is not valid
- valid = false;
- break;
- }
- }
- if (valid) {
- bedrockBlockId = i;
- break;
- }
- }
- }
- if (bedrockBlockId == -1) {
- throw new RuntimeException("Could not find a block match for " + entry.getKey());
- }
- }
-
- // Because we have replaced the Bedrock block ID, we also need to replace the creative contents block runtime ID
- // That way, creative items work correctly for these blocks
- for (int j = 0; j < creativeItems.size(); j++) {
- ItemData itemData = creativeItems.get(j);
- if (itemData.getId() == bedrockId) {
- if (itemData.getDamage() != 0) {
- break;
- }
- NbtMap states = blockTranslator.getAllBedrockBlockStates().get(itemData.getBlockRuntimeId()).getCompound("states");
- boolean valid = true;
- for (Map.Entry nbtEntry : requiredBlockStates.entrySet()) {
- if (!states.get(nbtEntry.getKey()).equals(nbtEntry.getValue())) {
- // A required block state doesn't match - this one is not valid
- valid = false;
- break;
- }
- }
- if (valid) {
- creativeItems.set(j, itemData.toBuilder().blockRuntimeId(bedrockBlockId).build());
- break;
- }
- }
- }
- }
- }
- }
-
- ItemEntry itemEntry;
- if (entry.getValue().has("tool_type")) {
- if (entry.getValue().has("tool_tier")) {
- itemEntry = new ToolItemEntry(
- entry.getKey(), bedrockIdentifier, itemIndex, bedrockId,
- entry.getValue().get("bedrock_data").intValue(),
- entry.getValue().get("tool_type").textValue(),
- entry.getValue().get("tool_tier").textValue(),
- bedrockBlockId,
- stackSize);
- } else {
- itemEntry = new ToolItemEntry(
- entry.getKey(), bedrockIdentifier, itemIndex, bedrockId,
- entry.getValue().get("bedrock_data").intValue(),
- entry.getValue().get("tool_type").textValue(),
- "", bedrockBlockId,
- stackSize);
- }
- } else if (entry.getKey().equals("minecraft:spectral_arrow") || entry.getKey().equals("minecraft:knowledge_book")
- // To remove later... hopefully
- || entry.getKey().contains("candle") || entry.getKey().equals("minecraft:bundle") || entry.getKey().equals("minecraft:sculk_sensor")) {
- // These items don't exist on Bedrock, so set up a container that indicates they should have custom names
- itemEntry = new TranslatableItemEntry(
- entry.getKey(), bedrockIdentifier, itemIndex, bedrockId,
- entry.getValue().get("bedrock_data").intValue(),
- bedrockBlockId,
- stackSize);
- GeyserConnector.getInstance().getLogger().debug("Adding " + entry.getKey() + " as an item that needs to be translated.");
- } else {
- itemEntry = new ItemEntry(
- entry.getKey(), bedrockIdentifier, itemIndex, bedrockId,
- entry.getValue().get("bedrock_data").intValue(),
- bedrockBlockId,
- stackSize);
- }
- ITEM_ENTRIES.put(itemIndex, itemEntry);
-
- switch (entry.getKey()) {
- case "minecraft:barrier":
- BARRIER_INDEX = itemIndex;
- break;
- case "minecraft:bamboo":
- BAMBOO = itemEntry;
- break;
- case "minecraft:crossbow":
- CROSSBOW = itemEntry;
- break;
- case "minecraft:egg":
- EGG = itemEntry;
- break;
- case "minecraft:fishing_rod":
- FISHING_ROD = itemEntry;
- break;
- case "minecraft:shield":
- SHIELD = itemEntry;
- break;
- case "minecraft:milk_bucket":
- MILK_BUCKET = itemEntry;
- break;
- case "minecraft:wheat":
- WHEAT = itemEntry;
- break;
- case "minecraft:white_banner": // As of 1.16.220, all banners share the same Bedrock ID and differ their colors through their damage value
- BANNER = itemEntry;
- break;
- case "minecraft:writable_book":
- WRITABLE_BOOK = itemEntry;
- break;
- default:
- break;
- }
-
- if (entry.getKey().contains("boat")) {
- BOATS.add(itemEntry.getBedrockId());
- } else if (entry.getKey().contains("bucket") && !entry.getKey().contains("milk")) {
- BUCKETS.add(itemEntry.getBedrockId());
- } else if (entry.getKey().contains("_carpet") && !entry.getKey().contains("moss")) {
- // This should be the numerical order Java sends as an integer value for llamas
- CARPETS.add(ItemData.builder()
- .id(itemEntry.getBedrockId())
- .damage(itemEntry.getBedrockData())
- .count(1)
- .blockRuntimeId(itemEntry.getBedrockBlockId()).build());
- } else if (entry.getKey().startsWith("minecraft:music_disc_")) {
- // The Java record level event uses the item ID as the "key" to play the record
- EffectRegistry.RECORDS.put(itemIndex, SoundEvent.valueOf("RECORD_" +
- entry.getKey().replace("minecraft:music_disc_", "").toUpperCase(Locale.ENGLISH)));
- } else if (entry.getKey().endsWith("_spawn_egg")) {
- SPAWN_EGGS.add(itemEntry.getBedrockId());
- }
-
- itemNames.add(entry.getKey());
-
- itemIndex++;
- }
-
- itemNames.add("minecraft:furnace_minecart");
-
- if (lodestoneCompassId == 0) {
- throw new RuntimeException("Lodestone compass not found in item palette!");
- }
-
- // Add the loadstone compass since it doesn't exist on java but we need it for item conversion
- ITEM_ENTRIES.put(itemIndex, new ItemEntry("minecraft:lodestone_compass", "minecraft:lodestone_compass", itemIndex,
- lodestoneCompassId, 0, -1, 1));
-
- if (usingFurnaceMinecart) {
- // Add the furnace minecart as a custom item
- int furnaceMinecartId = ITEMS.size() + 1;
-
- ITEMS.add(new StartGamePacket.ItemEntry("geysermc:furnace_minecart", (short) furnaceMinecartId, true));
- ITEM_ENTRIES.put(javaFurnaceMinecartId, new ItemEntry("minecraft:furnace_minecart", "geysermc:furnace_minecart", javaFurnaceMinecartId,
- furnaceMinecartId, 0, -1, 1));
- creativeItems.add(ItemData.builder()
- .netId(netId)
- .id(furnaceMinecartId)
- .count(1).build());
-
- NbtMapBuilder builder = NbtMap.builder();
- builder.putString("name", "geysermc:furnace_minecart")
- .putInt("id", furnaceMinecartId);
-
- NbtMapBuilder componentBuilder = NbtMap.builder();
- // Conveniently, as of 1.16.200, the furnace minecart has a texture AND translation string already.
- componentBuilder.putCompound("minecraft:icon", NbtMap.builder().putString("texture", "minecart_furnace").build());
- componentBuilder.putCompound("minecraft:display_name", NbtMap.builder().putString("value", "item.minecartFurnace.name").build());
-
- // Indicate that the arm animation should play on rails
- List useOnTag = Collections.singletonList(NbtMap.builder().putString("tags", "q.any_tag('rail')").build());
- componentBuilder.putCompound("minecraft:entity_placer", NbtMap.builder()
- .putList("dispense_on", NbtType.COMPOUND, useOnTag)
- .putString("entity", "minecraft:minecart")
- .putList("use_on", NbtType.COMPOUND, useOnTag)
- .build());
-
- NbtMapBuilder itemProperties = NbtMap.builder();
- // We always want to allow offhand usage when we can - matches Java Edition
- itemProperties.putBoolean("allow_off_hand", true);
- itemProperties.putBoolean("hand_equipped", false);
- itemProperties.putInt("max_stack_size", 1);
- itemProperties.putString("creative_group", "itemGroup.name.minecart");
- itemProperties.putInt("creative_category", 4); // 4 - "Items"
-
- componentBuilder.putCompound("item_properties", itemProperties.build());
- builder.putCompound("components", componentBuilder.build());
- FURNACE_MINECART_DATA = new ComponentItemData("geysermc:furnace_minecart", builder.build());
- } else {
- FURNACE_MINECART_DATA = null;
- }
-
- CREATIVE_ITEMS = creativeItems.toArray(new ItemData[0]);
-
- ITEM_NAMES = itemNames.toArray(new String[0]);
-
- Set javaOnlyItems = new ObjectOpenHashSet<>();
- Collections.addAll(javaOnlyItems, "minecraft:spectral_arrow", "minecraft:debug_stick",
- "minecraft:knowledge_book", "minecraft:tipped_arrow", "minecraft:trader_llama_spawn_egg",
- // To be removed in Bedrock 1.17.10... right??? RIGHT???
- "minecraft:candle", "minecraft:white_candle", "minecraft:orange_candle", "minecraft:magenta_candle",
- "minecraft:light_blue_candle", "minecraft:yellow_candle", "minecraft:lime_candle", "minecraft:pink_candle",
- "minecraft:gray_candle", "minecraft:light_gray_candle", "minecraft:cyan_candle", "minecraft:purple_candle",
- "minecraft:blue_candle", "minecraft:brown_candle", "minecraft:green_candle", "minecraft:red_candle", "minecraft:black_candle",
- "minecraft:bundle", "minecraft:sculk_sensor");
- if (!usingFurnaceMinecart) {
- javaOnlyItems.add("minecraft:furnace_minecart");
- }
- JAVA_ONLY_ITEMS = ImmutableSet.copyOf(javaOnlyItems);
- }
-
- /**
- * Gets an {@link ItemEntry} from the given {@link ItemStack}.
- *
- * @param stack the item stack
- * @return an item entry from the given item stack
- */
- public static ItemEntry getItem(ItemStack stack) {
- return ITEM_ENTRIES.get(stack.getId());
- }
-
- /**
- * Gets an {@link ItemEntry} from the given {@link ItemData}.
- *
- * @param data the item data
- * @return an item entry from the given item data
- */
- public static ItemEntry getItem(ItemData data) {
- boolean isBlock = data.getBlockRuntimeId() != 0;
- boolean hasDamage = data.getDamage() != 0;
-
- for (ItemEntry itemEntry : ITEM_ENTRIES.values()) {
- if (itemEntry.getBedrockId() == data.getId()) {
- if (isBlock && !hasDamage) { // Pre-1.16.220 will not use block runtime IDs at all, so we shouldn't check either
- if (data.getBlockRuntimeId() != itemEntry.getBedrockBlockId()) {
- continue;
- }
- } else {
- if (!(itemEntry.getBedrockData() == data.getDamage() ||
- // Make exceptions for potions and tipped arrows, whose damage values can vary
- (itemEntry.getJavaIdentifier().endsWith("potion") || itemEntry.getJavaIdentifier().equals("minecraft:arrow")))) {
- continue;
- }
- }
- if (!JAVA_ONLY_ITEMS.contains(itemEntry.getJavaIdentifier())) {
- // From a Bedrock item data, we aren't getting one of these items
- return itemEntry;
- }
- }
- }
-
- // This will hide the message when the player clicks with an empty hand
- if (data.getId() != 0 && data.getDamage() != 0) {
- GeyserConnector.getInstance().getLogger().debug("Missing mapping for bedrock item " + data.getId() + ":" + data.getDamage());
- }
- return ItemEntry.AIR;
- }
-
- /**
- * Gets an {@link ItemEntry} from the given Minecraft: Java Edition
- * block state identifier.
- *
- * @param javaIdentifier the block state identifier
- * @return an item entry from the given java edition identifier
- */
- public static ItemEntry getItemEntry(String javaIdentifier) {
- return JAVA_IDENTIFIER_MAP.computeIfAbsent(javaIdentifier, key -> {
- for (ItemEntry entry : ITEM_ENTRIES.values()) {
- if (entry.getJavaIdentifier().equals(key)) {
- return entry;
- }
- }
- return null;
- });
- }
-}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java
index c2bef9c6d..c4d098f79 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java
@@ -38,6 +38,9 @@ import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.ItemRemapper;
import org.geysermc.connector.network.translators.chat.MessageTranslator;
+import org.geysermc.connector.registry.BlockRegistries;
+import org.geysermc.connector.registry.type.ItemMapping;
+import org.geysermc.connector.registry.type.ItemMappings;
import org.geysermc.connector.utils.FileUtils;
import org.geysermc.connector.utils.LocaleUtils;
import org.reflections.Reflections;
@@ -73,8 +76,8 @@ public abstract class ItemTranslator {
continue;
}
ItemTranslator itemStackTranslator = (ItemTranslator) clazz.newInstance();
- List appliedItems = itemStackTranslator.getAppliedItems();
- for (ItemEntry item : appliedItems) {
+ List appliedItems = itemStackTranslator.getAppliedItems();
+ for (ItemMapping item : appliedItems) {
ItemTranslator registered = ITEM_STACK_TRANSLATORS.get(item.getJavaId());
if (registered != null) {
GeyserConnector.getInstance().getLogger().error("Could not instantiate annotated item translator " +
@@ -92,18 +95,23 @@ public abstract class ItemTranslator {
NBT_TRANSLATORS = loadedNbtItemTranslators.keySet().stream().sorted(Comparator.comparingInt(loadedNbtItemTranslators::get)).collect(Collectors.toList());
}
- public static ItemStack translateToJava(ItemData data) {
+ /**
+ * @param mappings item mappings to use while translating. This can't just be a Geyser session as this method is used
+ * when loading recipes.
+ */
+ public static ItemStack translateToJava(ItemData data, ItemMappings mappings) {
if (data == null) {
return new ItemStack(0);
}
- ItemEntry javaItem = ItemRegistry.getItem(data);
+
+ ItemMapping javaItem = mappings.getMapping(data);
ItemStack itemStack;
ItemTranslator itemStackTranslator = ITEM_STACK_TRANSLATORS.get(javaItem.getJavaId());
if (itemStackTranslator != null) {
- itemStack = itemStackTranslator.translateToJava(data, javaItem);
+ itemStack = itemStackTranslator.translateToJava(data, javaItem, mappings);
} else {
- itemStack = DEFAULT_TRANSLATOR.translateToJava(data, javaItem);
+ itemStack = DEFAULT_TRANSLATOR.translateToJava(data, javaItem, mappings);
}
if (itemStack != null && itemStack.getNbt() != null) {
@@ -125,9 +133,9 @@ public abstract class ItemTranslator {
return ItemData.AIR;
}
- ItemEntry bedrockItem = ItemRegistry.getItem(stack);
+ ItemMapping bedrockItem = session.getItemMappings().getMapping(stack);
if (bedrockItem == null) {
- session.getConnector().getLogger().debug("No matching ItemEntry for " + stack);
+ session.getConnector().getLogger().debug("No matching ItemMapping for " + stack);
return ItemData.AIR;
}
@@ -154,9 +162,9 @@ public abstract class ItemTranslator {
ItemData.Builder builder;
ItemTranslator itemStackTranslator = ITEM_STACK_TRANSLATORS.get(bedrockItem.getJavaId());
if (itemStackTranslator != null) {
- builder = itemStackTranslator.translateToBedrock(itemStack, bedrockItem);
+ builder = itemStackTranslator.translateToBedrock(itemStack, bedrockItem, session.getItemMappings());
} else {
- builder = DEFAULT_TRANSLATOR.translateToBedrock(itemStack, bedrockItem);
+ builder = DEFAULT_TRANSLATOR.translateToBedrock(itemStack, bedrockItem, session.getItemMappings());
}
if (bedrockItem.isBlock()) {
builder.blockRuntimeId(bedrockItem.getBedrockBlockId());
@@ -168,8 +176,8 @@ public abstract class ItemTranslator {
String[] canBreak = new String[0];
ListTag canPlaceOn = nbt.get("CanPlaceOn");
String[] canPlace = new String[0];
- canBreak = getCanModify(session, canDestroy, canBreak);
- canPlace = getCanModify(session, canPlaceOn, canPlace);
+ canBreak = getCanModify(canDestroy, canBreak);
+ canPlace = getCanModify(canPlaceOn, canPlace);
builder.canBreak(canBreak);
builder.canPlace(canPlace);
}
@@ -185,7 +193,7 @@ public abstract class ItemTranslator {
* @param canModifyBedrock the empty list of items in Bedrock
* @return the new list of items in Bedrock
*/
- private static String[] getCanModify(GeyserSession session, ListTag canModifyJava, String[] canModifyBedrock) {
+ private static String[] getCanModify(ListTag canModifyJava, String[] canModifyBedrock) {
if (canModifyJava != null && canModifyJava.size() > 0) {
canModifyBedrock = new String[canModifyJava.size()];
for (int i = 0; i < canModifyBedrock.length; i++) {
@@ -195,7 +203,7 @@ public abstract class ItemTranslator {
if (!block.startsWith("minecraft:")) block = "minecraft:" + block;
// Get the Bedrock identifier of the item and replace it.
// This will unfortunately be limited - for example, beds and banners will be translated weirdly
- canModifyBedrock[i] = session.getBlockTranslator().getBedrockBlockIdentifier(block).replace("minecraft:", "");
+ canModifyBedrock[i] = BlockRegistries.JAVA_TO_BEDROCK_IDENTIFIERS.get(block).replace("minecraft:", "");
}
}
return canModifyBedrock;
@@ -203,19 +211,19 @@ public abstract class ItemTranslator {
private static final ItemTranslator DEFAULT_TRANSLATOR = new ItemTranslator() {
@Override
- public List getAppliedItems() {
+ public List getAppliedItems() {
return null;
}
};
- public ItemData.Builder translateToBedrock(ItemStack itemStack, ItemEntry itemEntry) {
+ public ItemData.Builder translateToBedrock(ItemStack itemStack, ItemMapping mapping, ItemMappings mappings) {
if (itemStack == null) {
// Return, essentially, air
return ItemData.builder();
}
ItemData.Builder builder = ItemData.builder()
- .id(itemEntry.getBedrockId())
- .damage(itemEntry.getBedrockData())
+ .id(mapping.getBedrockId())
+ .damage(mapping.getBedrockData())
.count(itemStack.getAmount());
if (itemStack.getNbt() != null) {
builder.tag(this.translateNbtToBedrock(itemStack.getNbt()));
@@ -223,15 +231,15 @@ public abstract class ItemTranslator {
return builder;
}
- public ItemStack translateToJava(ItemData itemData, ItemEntry itemEntry) {
+ public ItemStack translateToJava(ItemData itemData, ItemMapping mapping, ItemMappings mappings) {
if (itemData == null) return null;
if (itemData.getTag() == null) {
- return new ItemStack(itemEntry.getJavaId(), itemData.getCount(), new CompoundTag(""));
+ return new ItemStack(mapping.getJavaId(), itemData.getCount(), new CompoundTag(""));
}
- return new ItemStack(itemEntry.getJavaId(), itemData.getCount(), this.translateToJavaNBT("", itemData.getTag()));
+ return new ItemStack(mapping.getJavaId(), itemData.getCount(), this.translateToJavaNBT("", itemData.getTag()));
}
- public abstract List getAppliedItems();
+ public abstract List getAppliedItems();
public NbtMap translateNbtToBedrock(CompoundTag tag) {
NbtMapBuilder builder = NbtMap.builder();
@@ -395,19 +403,19 @@ public abstract class ItemTranslator {
* Translates the display name of the item
* @param session the Bedrock client's session
* @param tag the tag to translate
- * @param itemEntry the item entry, in case it requires translation
+ * @param mapping the item entry, in case it requires translation
*
* @return the new tag to use, should the current one be null
*/
- public static CompoundTag translateDisplayProperties(GeyserSession session, CompoundTag tag, ItemEntry itemEntry) {
- return translateDisplayProperties(session, tag, itemEntry, 'f');
+ public static CompoundTag translateDisplayProperties(GeyserSession session, CompoundTag tag, ItemMapping mapping) {
+ return translateDisplayProperties(session, tag, mapping, 'f');
}
/**
* @param translationColor if this item is not available on Java, the color that the new name should be.
* Normally, this should just be white, but for shulker boxes this should be gray.
*/
- public static CompoundTag translateDisplayProperties(GeyserSession session, CompoundTag tag, ItemEntry itemEntry, char translationColor) {
+ public static CompoundTag translateDisplayProperties(GeyserSession session, CompoundTag tag, ItemMapping mapping, char translationColor) {
boolean hasCustomName = false;
if (tag != null) {
CompoundTag display = tag.get("display");
@@ -427,7 +435,7 @@ public abstract class ItemTranslator {
}
}
- if (!hasCustomName && itemEntry instanceof TranslatableItemEntry) {
+ if (!hasCustomName && mapping.hasTranslation()) {
// No custom name, but we need to localize the item's name
if (tag == null) {
tag = new CompoundTag("");
@@ -439,7 +447,7 @@ public abstract class ItemTranslator {
tag.put(display);
}
- String translationKey = ((TranslatableItemEntry) itemEntry).getTranslationString();
+ String translationKey = mapping.getTranslationString();
// Reset formatting since Bedrock defaults to italics
display.put(new StringTag("Name", "§r§" + translationColor + LocaleUtils.getLocaleString(translationKey, session.getLocale())));
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/NbtItemStackTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/NbtItemStackTranslator.java
index bfd1d777c..a7044c3b2 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/NbtItemStackTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/NbtItemStackTranslator.java
@@ -27,6 +27,7 @@ package org.geysermc.connector.network.translators.item;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import org.geysermc.connector.network.session.GeyserSession;
+import org.geysermc.connector.registry.type.ItemMapping;
public class NbtItemStackTranslator {
@@ -34,26 +35,28 @@ public class NbtItemStackTranslator {
* Translate the item NBT to Bedrock
* @param session the client's current session
* @param itemTag the item's CompoundTag
- * @param itemEntry Geyser's item entry
+ * @param mapping Geyser's item mapping
*/
- public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
}
/**
* Translate the item NBT to Java.
* @param itemTag the item's CompoundTag
- * @param itemEntry Geyser's item entry
+ * @param mapping Geyser's item mapping
*/
- public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToJava(CompoundTag itemTag, ItemMapping mapping) {
}
/**
- * @param itemEntry Geyser's item entry
+ * Gets whether this nbt translator takes in this item.
+ *
+ * @param mapping Geyser's item mapping
* @return if the item should be processed under this class
*/
- public boolean acceptItem(ItemEntry itemEntry) {
+ public boolean acceptItem(ItemMapping mapping) {
return true;
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/StoredItemMappings.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/StoredItemMappings.java
new file mode 100644
index 000000000..80a50f831
--- /dev/null
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/StoredItemMappings.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author GeyserMC
+ * @link https://github.com/GeyserMC/Geyser
+ */
+
+package org.geysermc.connector.network.translators.item;
+
+import lombok.Getter;
+import lombok.experimental.Accessors;
+import org.geysermc.connector.registry.type.ItemMapping;
+
+import javax.annotation.Nonnull;
+import java.util.Map;
+
+/**
+ * A class to have easy access to specific item mappings per-version.
+ */
+@Getter
+@Accessors(fluent = true)
+public class StoredItemMappings {
+ private final ItemMapping bamboo;
+ private final ItemMapping banner;
+ private final ItemMapping barrier;
+ private final ItemMapping compass;
+ private final ItemMapping crossbow;
+ private final ItemMapping fishingRod;
+ private final ItemMapping lodestoneCompass;
+ private final ItemMapping milkBucket;
+ private final ItemMapping egg;
+ private final ItemMapping shield;
+ private final ItemMapping wheat;
+ private final ItemMapping writableBook;
+
+ public StoredItemMappings(Map itemMappings) {
+ this.bamboo = load(itemMappings, "bamboo");
+ this.banner = load(itemMappings, "white_banner"); // As of 1.17.10, all banners have the same Bedrock ID
+ this.barrier = load(itemMappings, "barrier");
+ this.compass = load(itemMappings, "compass");
+ this.crossbow = load(itemMappings, "crossbow");
+ this.fishingRod = load(itemMappings, "fishing_rod");
+ this.lodestoneCompass = load(itemMappings, "lodestone_compass");
+ this.milkBucket = load(itemMappings, "milk_bucket");
+ this.egg = load(itemMappings, "egg");
+ this.shield = load(itemMappings, "shield");
+ this.wheat = load(itemMappings, "wheat");
+ this.writableBook = load(itemMappings, "writable_book");
+ }
+
+ @Nonnull
+ private ItemMapping load(Map itemMappings, String cleanIdentifier) {
+ ItemMapping mapping = itemMappings.get("minecraft:" + cleanIdentifier);
+ if (mapping == null) {
+ throw new RuntimeException("Could not find item " + cleanIdentifier);
+ }
+
+ return mapping;
+ }
+}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/BannerTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/BannerTranslator.java
index fb1256e40..116e703bc 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/BannerTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/BannerTranslator.java
@@ -32,10 +32,12 @@ import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtMapBuilder;
import com.nukkitx.nbt.NbtType;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
+import org.geysermc.connector.network.BedrockProtocol;
import org.geysermc.connector.network.translators.ItemRemapper;
-import org.geysermc.connector.network.translators.item.ItemEntry;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.network.translators.item.ItemTranslator;
+import org.geysermc.connector.registry.Registries;
+import org.geysermc.connector.registry.type.ItemMapping;
+import org.geysermc.connector.registry.type.ItemMappings;
import java.util.ArrayList;
import java.util.HashMap;
@@ -54,7 +56,7 @@ public class BannerTranslator extends ItemTranslator {
*/
public static final ListTag OMINOUS_BANNER_PATTERN;
- private final List appliedItems;
+ private final List appliedItems;
static {
OMINOUS_BANNER_PATTERN = new ListTag("Patterns");
@@ -79,7 +81,9 @@ public class BannerTranslator extends ItemTranslator {
}
public BannerTranslator() {
- appliedItems = ItemRegistry.ITEM_ENTRIES.values()
+ appliedItems = Registries.ITEMS.forVersion(BedrockProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion())
+ .getItems()
+ .values()
.stream()
.filter(entry -> entry.getJavaIdentifier().endsWith("banner"))
.collect(Collectors.toList());
@@ -153,12 +157,12 @@ public class BannerTranslator extends ItemTranslator {
}
@Override
- public ItemData.Builder translateToBedrock(ItemStack itemStack, ItemEntry itemEntry) {
+ public ItemData.Builder translateToBedrock(ItemStack itemStack, ItemMapping mapping, ItemMappings mappings) {
if (itemStack.getNbt() == null) {
- return super.translateToBedrock(itemStack, itemEntry);
+ return super.translateToBedrock(itemStack, mapping, mappings);
}
- ItemData.Builder builder = super.translateToBedrock(itemStack, itemEntry);
+ ItemData.Builder builder = super.translateToBedrock(itemStack, mapping, mappings);
CompoundTag blockEntityTag = itemStack.getNbt().get("BlockEntityTag");
if (blockEntityTag != null && blockEntityTag.contains("Patterns")) {
@@ -180,12 +184,12 @@ public class BannerTranslator extends ItemTranslator {
}
@Override
- public ItemStack translateToJava(ItemData itemData, ItemEntry itemEntry) {
+ public ItemStack translateToJava(ItemData itemData, ItemMapping mapping, ItemMappings mappings) {
if (itemData.getTag() == null) {
- return super.translateToJava(itemData, itemEntry);
+ return super.translateToJava(itemData, mapping, mappings);
}
- ItemStack itemStack = super.translateToJava(itemData, itemEntry);
+ ItemStack itemStack = super.translateToJava(itemData, mapping, mappings);
NbtMap nbtTag = itemData.getTag();
if (nbtTag.containsKey("Type", NbtType.INT) && nbtTag.getInt("Type") == 1) {
@@ -209,7 +213,7 @@ public class BannerTranslator extends ItemTranslator {
}
@Override
- public List getAppliedItems() {
+ public List getAppliedItems() {
return appliedItems;
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/CompassTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/CompassTranslator.java
index 08c7426fe..e35e5c252 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/CompassTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/CompassTranslator.java
@@ -28,10 +28,12 @@ package org.geysermc.connector.network.translators.item.translators;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.opennbt.tag.builtin.*;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
+import org.geysermc.connector.network.BedrockProtocol;
import org.geysermc.connector.network.translators.ItemRemapper;
-import org.geysermc.connector.network.translators.item.ItemEntry;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.network.translators.item.ItemTranslator;
+import org.geysermc.connector.registry.Registries;
+import org.geysermc.connector.registry.type.ItemMapping;
+import org.geysermc.connector.registry.type.ItemMappings;
import org.geysermc.connector.utils.LoadstoneTracker;
import java.util.List;
@@ -40,20 +42,25 @@ import java.util.stream.Collectors;
@ItemRemapper
public class CompassTranslator extends ItemTranslator {
- private final List appliedItems;
+ private final List appliedItems;
public CompassTranslator() {
- appliedItems = ItemRegistry.ITEM_ENTRIES.values().stream().filter(entry -> entry.getJavaIdentifier().endsWith("compass")).collect(Collectors.toList());
+ appliedItems = Registries.ITEMS.forVersion(BedrockProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion())
+ .getItems()
+ .values()
+ .stream()
+ .filter(entry -> entry.getJavaIdentifier().endsWith("compass"))
+ .collect(Collectors.toList());
}
@Override
- public ItemData.Builder translateToBedrock(ItemStack itemStack, ItemEntry itemEntry) {
- if (itemStack.getNbt() == null) return super.translateToBedrock(itemStack, itemEntry);
+ public ItemData.Builder translateToBedrock(ItemStack itemStack, ItemMapping mapping, ItemMappings mappings) {
+ if (itemStack.getNbt() == null) return super.translateToBedrock(itemStack, mapping, mappings);
Tag lodestoneTag = itemStack.getNbt().get("LodestoneTracked");
if (lodestoneTag instanceof ByteTag) {
// Get the fake lodestonecompass entry
- itemEntry = ItemRegistry.getItemEntry("minecraft:lodestone_compass");
+ mapping = mappings.getStoredItems().lodestoneCompass();
// Get the loadstone pos
CompoundTag loadstonePos = itemStack.getNbt().get("LodestonePos");
@@ -75,20 +82,20 @@ public class CompassTranslator extends ItemTranslator {
}
}
- return super.translateToBedrock(itemStack, itemEntry);
+ return super.translateToBedrock(itemStack, mapping, mappings);
}
@Override
- public ItemStack translateToJava(ItemData itemData, ItemEntry itemEntry) {
+ public ItemStack translateToJava(ItemData itemData, ItemMapping mapping, ItemMappings mappings) {
boolean isLoadstone = false;
- if (itemEntry.getBedrockIdentifier().equals("minecraft:lodestone_compass")) {
+ if (mapping.getBedrockIdentifier().equals("minecraft:lodestone_compass")) {
// Revert the entry back to the compass
- itemEntry = ItemRegistry.getItemEntry("minecraft:compass");
+ mapping = mappings.getStoredItems().compass();
isLoadstone = true;
}
- ItemStack itemStack = super.translateToJava(itemData, itemEntry);
+ ItemStack itemStack = super.translateToJava(itemData, mapping, mappings);
if (isLoadstone) {
// Get the tracking id
@@ -113,7 +120,7 @@ public class CompassTranslator extends ItemTranslator {
}
@Override
- public List getAppliedItems() {
+ public List getAppliedItems() {
return appliedItems;
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/PotionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/PotionTranslator.java
index 9f41472fe..2908754aa 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/PotionTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/PotionTranslator.java
@@ -30,11 +30,13 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import org.geysermc.connector.GeyserConnector;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
+import org.geysermc.connector.network.BedrockProtocol;
import org.geysermc.connector.network.translators.item.ItemTranslator;
import org.geysermc.connector.network.translators.ItemRemapper;
-import org.geysermc.connector.network.translators.item.ItemEntry;
import org.geysermc.connector.network.translators.item.Potion;
+import org.geysermc.connector.registry.Registries;
+import org.geysermc.connector.registry.type.ItemMapping;
+import org.geysermc.connector.registry.type.ItemMappings;
import java.util.List;
import java.util.stream.Collectors;
@@ -42,34 +44,39 @@ import java.util.stream.Collectors;
@ItemRemapper
public class PotionTranslator extends ItemTranslator {
- private final List appliedItems;
+ private final List appliedItems;
public PotionTranslator() {
- appliedItems = ItemRegistry.ITEM_ENTRIES.values().stream().filter(entry -> entry.getJavaIdentifier().endsWith("potion")).collect(Collectors.toList());
+ appliedItems = Registries.ITEMS.forVersion(BedrockProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion())
+ .getItems()
+ .values()
+ .stream()
+ .filter(entry -> entry.getJavaIdentifier().endsWith("potion"))
+ .collect(Collectors.toList());
}
@Override
- public ItemData.Builder translateToBedrock(ItemStack itemStack, ItemEntry itemEntry) {
- if (itemStack.getNbt() == null) return super.translateToBedrock(itemStack, itemEntry);
+ public ItemData.Builder translateToBedrock(ItemStack itemStack, ItemMapping mapping, ItemMappings mappings) {
+ if (itemStack.getNbt() == null) return super.translateToBedrock(itemStack, mapping, mappings);
Tag potionTag = itemStack.getNbt().get("Potion");
if (potionTag instanceof StringTag) {
Potion potion = Potion.getByJavaIdentifier(((StringTag) potionTag).getValue());
if (potion != null) {
return ItemData.builder()
- .id(itemEntry.getBedrockId())
+ .id(mapping.getBedrockId())
.damage(potion.getBedrockId())
.count(itemStack.getAmount())
.tag(translateNbtToBedrock(itemStack.getNbt()));
}
GeyserConnector.getInstance().getLogger().debug("Unknown Java potion: " + potionTag.getValue());
}
- return super.translateToBedrock(itemStack, itemEntry);
+ return super.translateToBedrock(itemStack, mapping, mappings);
}
@Override
- public ItemStack translateToJava(ItemData itemData, ItemEntry itemEntry) {
+ public ItemStack translateToJava(ItemData itemData, ItemMapping mapping, ItemMappings mappings) {
Potion potion = Potion.getByBedrockId(itemData.getDamage());
- ItemStack itemStack = super.translateToJava(itemData, itemEntry);
+ ItemStack itemStack = super.translateToJava(itemData, mapping, mappings);
if (potion != null) {
StringTag potionTag = new StringTag("Potion", potion.getJavaIdentifier());
itemStack.getNbt().put(potionTag);
@@ -78,7 +85,7 @@ public class PotionTranslator extends ItemTranslator {
}
@Override
- public List getAppliedItems() {
+ public List getAppliedItems() {
return appliedItems;
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/TippedArrowTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/TippedArrowTranslator.java
index 8b64732c4..ebc3936de 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/TippedArrowTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/TippedArrowTranslator.java
@@ -30,11 +30,13 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import org.geysermc.connector.GeyserConnector;
+import org.geysermc.connector.network.BedrockProtocol;
import org.geysermc.connector.network.translators.ItemRemapper;
-import org.geysermc.connector.network.translators.item.ItemEntry;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.network.translators.item.ItemTranslator;
import org.geysermc.connector.network.translators.item.TippedArrowPotion;
+import org.geysermc.connector.registry.Registries;
+import org.geysermc.connector.registry.type.ItemMapping;
+import org.geysermc.connector.registry.type.ItemMappings;
import java.util.List;
import java.util.stream.Collectors;
@@ -42,40 +44,47 @@ import java.util.stream.Collectors;
@ItemRemapper
public class TippedArrowTranslator extends ItemTranslator {
- private final List appliedItems;
+ private final List appliedItems;
- private static final int TIPPED_ARROW_JAVA_ID = ItemRegistry.getItemEntry("minecraft:tipped_arrow").getJavaId();
+ private static final int TIPPED_ARROW_JAVA_ID = Registries.ITEMS.forVersion(BedrockProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion())
+ .getMapping("minecraft:tipped_arrow")
+ .getJavaId();
public TippedArrowTranslator() {
- appliedItems = ItemRegistry.ITEM_ENTRIES.values().stream().filter(entry ->
- entry.getJavaIdentifier().contains("arrow") && !entry.getJavaIdentifier().contains("spectral")).collect(Collectors.toList());
+ appliedItems = Registries.ITEMS.forVersion(BedrockProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion())
+ .getItems()
+ .values()
+ .stream()
+ .filter(entry -> entry.getJavaIdentifier().contains("arrow")
+ && !entry.getJavaIdentifier().contains("spectral"))
+ .collect(Collectors.toList());
}
@Override
- public ItemData.Builder translateToBedrock(ItemStack itemStack, ItemEntry itemEntry) {
- if (!itemEntry.getJavaIdentifier().equals("minecraft:tipped_arrow") || itemStack.getNbt() == null) {
+ public ItemData.Builder translateToBedrock(ItemStack itemStack, ItemMapping mapping, ItemMappings mappings) {
+ if (!mapping.getJavaIdentifier().equals("minecraft:tipped_arrow") || itemStack.getNbt() == null) {
// We're only concerned about minecraft:arrow when translating Bedrock -> Java
- return super.translateToBedrock(itemStack, itemEntry);
+ return super.translateToBedrock(itemStack, mapping, mappings);
}
Tag potionTag = itemStack.getNbt().get("Potion");
if (potionTag instanceof StringTag) {
TippedArrowPotion tippedArrowPotion = TippedArrowPotion.getByJavaIdentifier(((StringTag) potionTag).getValue());
if (tippedArrowPotion != null) {
return ItemData.builder()
- .id(itemEntry.getBedrockId())
+ .id(mapping.getBedrockId())
.damage(tippedArrowPotion.getBedrockId())
.count(itemStack.getAmount())
.tag(translateNbtToBedrock(itemStack.getNbt()));
}
GeyserConnector.getInstance().getLogger().debug("Unknown Java potion (tipped arrow): " + potionTag.getValue());
}
- return super.translateToBedrock(itemStack, itemEntry);
+ return super.translateToBedrock(itemStack, mapping, mappings);
}
@Override
- public ItemStack translateToJava(ItemData itemData, ItemEntry itemEntry) {
+ public ItemStack translateToJava(ItemData itemData, ItemMapping mapping, ItemMappings mappings) {
TippedArrowPotion tippedArrowPotion = TippedArrowPotion.getByBedrockId(itemData.getDamage());
- ItemStack itemStack = super.translateToJava(itemData, itemEntry);
+ ItemStack itemStack = super.translateToJava(itemData, mapping, mappings);
if (tippedArrowPotion != null) {
itemStack = new ItemStack(TIPPED_ARROW_JAVA_ID, itemStack.getAmount(), itemStack.getNbt());
StringTag potionTag = new StringTag("Potion", tippedArrowPotion.getJavaIdentifier());
@@ -85,7 +94,7 @@ public class TippedArrowTranslator extends ItemTranslator {
}
@Override
- public List getAppliedItems() {
+ public List getAppliedItems() {
return appliedItems;
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/AxolotlBucketTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/AxolotlBucketTranslator.java
index a0fe4910b..f62ac05ae 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/AxolotlBucketTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/AxolotlBucketTranslator.java
@@ -30,15 +30,15 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.ItemRemapper;
-import org.geysermc.connector.network.translators.item.ItemEntry;
import org.geysermc.connector.network.translators.item.NbtItemStackTranslator;
+import org.geysermc.connector.registry.type.ItemMapping;
import org.geysermc.connector.utils.LocaleUtils;
@ItemRemapper
public class AxolotlBucketTranslator extends NbtItemStackTranslator {
@Override
- public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
// Bedrock Edition displays the properties of the axolotl. Java does not.
// To work around this, set the custom name to the Axolotl translation and it's displayed correctly
itemTag.put(new ByteTag("AppendCustomName", (byte) 1));
@@ -49,7 +49,7 @@ public class AxolotlBucketTranslator extends NbtItemStackTranslator {
}
@Override
- public boolean acceptItem(ItemEntry itemEntry) {
- return itemEntry.getJavaIdentifier().equals("minecraft:axolotl_bucket");
+ public boolean acceptItem(ItemMapping mapping) {
+ return mapping.getJavaIdentifier().equals("minecraft:axolotl_bucket");
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BasicItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BasicItemTranslator.java
index c097dd544..58d72de0e 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BasicItemTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BasicItemTranslator.java
@@ -29,8 +29,8 @@ import com.github.steveice10.opennbt.tag.builtin.*;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.ItemRemapper;
import org.geysermc.connector.network.translators.chat.MessageTranslator;
-import org.geysermc.connector.network.translators.item.ItemEntry;
import org.geysermc.connector.network.translators.item.NbtItemStackTranslator;
+import org.geysermc.connector.registry.type.ItemMapping;
import org.geysermc.connector.utils.ItemUtils;
import java.util.ArrayList;
@@ -40,11 +40,11 @@ import java.util.List;
public class BasicItemTranslator extends NbtItemStackTranslator {
@Override
- public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
Tag damage = itemTag.get("Damage");
if (damage instanceof IntTag) {
int originalDurability = ((IntTag) damage).getValue();
- int durability = ItemUtils.getCorrectBedrockDurability(itemEntry.getJavaId(), originalDurability);
+ int durability = ItemUtils.getCorrectBedrockDurability(session, mapping.getJavaId(), originalDurability);
if (durability != originalDurability) {
// Fix damage tag inconsistencies
itemTag.put(new IntTag("Damage", durability));
@@ -68,7 +68,7 @@ public class BasicItemTranslator extends NbtItemStackTranslator {
}
@Override
- public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToJava(CompoundTag itemTag, ItemMapping mapping) {
CompoundTag displayTag = itemTag.get("display");
if (displayTag == null) {
return;
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BookPagesTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BookPagesTranslator.java
index 90eef3bce..208db0987 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BookPagesTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BookPagesTranslator.java
@@ -32,8 +32,8 @@ import com.github.steveice10.opennbt.tag.builtin.Tag;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.ItemRemapper;
import org.geysermc.connector.network.translators.item.NbtItemStackTranslator;
-import org.geysermc.connector.network.translators.item.ItemEntry;
import org.geysermc.connector.network.translators.chat.MessageTranslator;
+import org.geysermc.connector.registry.type.ItemMapping;
import java.util.ArrayList;
import java.util.List;
@@ -42,7 +42,7 @@ import java.util.List;
public class BookPagesTranslator extends NbtItemStackTranslator {
@Override
- public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
if (!itemTag.contains("pages")) {
return;
}
@@ -65,7 +65,7 @@ public class BookPagesTranslator extends NbtItemStackTranslator {
}
@Override
- public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToJava(CompoundTag itemTag, ItemMapping mapping) {
if (!itemTag.contains("pages")) {
return;
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/CrossbowTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/CrossbowTranslator.java
index ae52e4221..b0e55737f 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/CrossbowTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/CrossbowTranslator.java
@@ -30,30 +30,29 @@ import com.github.steveice10.opennbt.tag.builtin.*;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.ItemRemapper;
-import org.geysermc.connector.network.translators.item.ItemEntry;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.network.translators.item.ItemTranslator;
import org.geysermc.connector.network.translators.item.NbtItemStackTranslator;
+import org.geysermc.connector.registry.type.ItemMapping;
@ItemRemapper
public class CrossbowTranslator extends NbtItemStackTranslator {
@Override
- public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
if (itemTag.get("ChargedProjectiles") != null) {
ListTag chargedProjectiles = itemTag.get("ChargedProjectiles");
if (!chargedProjectiles.getValue().isEmpty()) {
CompoundTag projectile = (CompoundTag) chargedProjectiles.getValue().get(0);
- ItemEntry projectileEntry = ItemRegistry.getItemEntry((String) projectile.get("id").getValue());
- if (projectileEntry == null) return;
+ ItemMapping projectileMapping = session.getItemMappings().getMapping((String) projectile.get("id").getValue());
+ if (projectileMapping == null) return;
CompoundTag tag = projectile.get("tag");
- ItemStack itemStack = new ItemStack(itemEntry.getJavaId(), (byte) projectile.get("Count").getValue(), tag);
+ ItemStack itemStack = new ItemStack(mapping.getJavaId(), (byte) projectile.get("Count").getValue(), tag);
ItemData itemData = ItemTranslator.translateToBedrock(session, itemStack);
CompoundTag newProjectile = new CompoundTag("chargedItem");
newProjectile.put(new ByteTag("Count", (byte) itemData.getCount()));
- newProjectile.put(new StringTag("Name", projectileEntry.getBedrockIdentifier()));
+ newProjectile.put(new StringTag("Name", projectileMapping.getBedrockIdentifier()));
newProjectile.put(new ShortTag("Damage", (short) itemData.getDamage()));
@@ -63,7 +62,7 @@ public class CrossbowTranslator extends NbtItemStackTranslator {
}
@Override
- public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToJava(CompoundTag itemTag, ItemMapping mapping) {
if (itemTag.get("chargedItem") != null) {
CompoundTag chargedItem = itemTag.get("chargedItem");
@@ -79,7 +78,7 @@ public class CrossbowTranslator extends NbtItemStackTranslator {
}
@Override
- public boolean acceptItem(ItemEntry itemEntry) {
- return "minecraft:crossbow".equals(itemEntry.getJavaIdentifier());
+ public boolean acceptItem(ItemMapping mapping) {
+ return "minecraft:crossbow".equals(mapping.getJavaIdentifier());
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/EnchantedBookTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/EnchantedBookTranslator.java
index cc01feb4f..0bca7a8ba 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/EnchantedBookTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/EnchantedBookTranslator.java
@@ -31,13 +31,13 @@ import com.github.steveice10.opennbt.tag.builtin.Tag;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.ItemRemapper;
import org.geysermc.connector.network.translators.item.NbtItemStackTranslator;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
@ItemRemapper(priority = 1)
public class EnchantedBookTranslator extends NbtItemStackTranslator {
@Override
- public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
if (!itemTag.contains("StoredEnchantments")) {
return;
}
@@ -50,7 +50,7 @@ public class EnchantedBookTranslator extends NbtItemStackTranslator {
}
@Override
- public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToJava(CompoundTag itemTag, ItemMapping mapping) {
if (!itemTag.contains("Enchantments")) {
return;
}
@@ -63,7 +63,7 @@ public class EnchantedBookTranslator extends NbtItemStackTranslator {
}
@Override
- public boolean acceptItem(ItemEntry itemEntry) {
- return "minecraft:enchanted_book".equals(itemEntry.getJavaIdentifier());
+ public boolean acceptItem(ItemMapping mapping) {
+ return "minecraft:enchanted_book".equals(mapping.getJavaIdentifier());
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/EnchantmentTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/EnchantmentTranslator.java
index 2e381d223..58caad3f1 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/EnchantmentTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/EnchantmentTranslator.java
@@ -31,7 +31,7 @@ import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.ItemRemapper;
import org.geysermc.connector.network.translators.item.NbtItemStackTranslator;
import org.geysermc.connector.network.translators.item.Enchantment;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
import java.util.ArrayList;
import java.util.List;
@@ -41,7 +41,7 @@ import java.util.Map;
public class EnchantmentTranslator extends NbtItemStackTranslator {
@Override
- public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
List newTags = new ArrayList<>();
if (itemTag.contains("Enchantments")) {
ListTag enchantmentTag = itemTag.get("Enchantments");
@@ -73,7 +73,7 @@ public class EnchantmentTranslator extends NbtItemStackTranslator {
}
@Override
- public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToJava(CompoundTag itemTag, ItemMapping mapping) {
if (!itemTag.contains("ench")) {
return;
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/FireworkRocketTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/FireworkRocketTranslator.java
index f294315c8..0d37f0477 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/FireworkRocketTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/FireworkRocketTranslator.java
@@ -31,14 +31,14 @@ import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.ItemRemapper;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
import org.geysermc.connector.utils.MathUtils;
@ItemRemapper
public class FireworkRocketTranslator extends FireworkBaseTranslator {
@Override
- public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
CompoundTag fireworks = itemTag.get("Fireworks");
if (fireworks == null) {
return;
@@ -62,7 +62,7 @@ public class FireworkRocketTranslator extends FireworkBaseTranslator {
}
@Override
- public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToJava(CompoundTag itemTag, ItemMapping mapping) {
CompoundTag fireworks = itemTag.get("Fireworks");
if (fireworks == null) {
return;
@@ -86,7 +86,7 @@ public class FireworkRocketTranslator extends FireworkBaseTranslator {
}
@Override
- public boolean acceptItem(ItemEntry itemEntry) {
- return "minecraft:firework_rocket".equals(itemEntry.getJavaIdentifier());
+ public boolean acceptItem(ItemMapping mapping) {
+ return "minecraft:firework_rocket".equals(mapping.getJavaIdentifier());
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/FireworkStarTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/FireworkStarTranslator.java
index 686887b45..38eca4856 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/FireworkStarTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/FireworkStarTranslator.java
@@ -31,13 +31,13 @@ import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.ItemRemapper;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
@ItemRemapper
public class FireworkStarTranslator extends FireworkBaseTranslator {
@Override
- public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
Tag explosion = itemTag.get("Explosion");
if (explosion instanceof CompoundTag) {
CompoundTag newExplosion = translateExplosionToBedrock((CompoundTag) explosion, "FireworksItem");
@@ -78,7 +78,7 @@ public class FireworkStarTranslator extends FireworkBaseTranslator {
}
@Override
- public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToJava(CompoundTag itemTag, ItemMapping mapping) {
Tag explosion = itemTag.get("FireworksItem");
if (explosion instanceof CompoundTag) {
CompoundTag newExplosion = translateExplosionToJava((CompoundTag) explosion, "Explosion");
@@ -90,7 +90,7 @@ public class FireworkStarTranslator extends FireworkBaseTranslator {
}
@Override
- public boolean acceptItem(ItemEntry itemEntry) {
- return "minecraft:firework_star".equals(itemEntry.getJavaIdentifier());
+ public boolean acceptItem(ItemMapping mapping) {
+ return "minecraft:firework_star".equals(mapping.getJavaIdentifier());
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/LeatherArmorTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/LeatherArmorTranslator.java
index c2305738d..0fd6f1e7b 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/LeatherArmorTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/LeatherArmorTranslator.java
@@ -30,16 +30,19 @@ import com.github.steveice10.opennbt.tag.builtin.IntTag;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.ItemRemapper;
import org.geysermc.connector.network.translators.item.NbtItemStackTranslator;
-import org.geysermc.connector.network.translators.item.ItemEntry;
+import org.geysermc.connector.registry.type.ItemMapping;
+
+import java.util.Arrays;
+import java.util.List;
@ItemRemapper
public class LeatherArmorTranslator extends NbtItemStackTranslator {
- private static final String[] ITEMS = new String[]{"minecraft:leather_helmet", "minecraft:leather_chestplate",
- "minecraft:leather_leggings", "minecraft:leather_boots", "minecraft:leather_horse_armor"};
+ private static final List ITEMS = Arrays.asList("minecraft:leather_helmet", "minecraft:leather_chestplate",
+ "minecraft:leather_leggings", "minecraft:leather_boots", "minecraft:leather_horse_armor");
@Override
- public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
CompoundTag displayTag = itemTag.get("display");
if (displayTag == null) {
return;
@@ -52,7 +55,7 @@ public class LeatherArmorTranslator extends NbtItemStackTranslator {
}
@Override
- public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToJava(CompoundTag itemTag, ItemMapping mapping) {
IntTag color = itemTag.get("customColor");
if (color == null) {
return;
@@ -66,10 +69,7 @@ public class LeatherArmorTranslator extends NbtItemStackTranslator {
}
@Override
- public boolean acceptItem(ItemEntry itemEntry) {
- for (String item : ITEMS) {
- if (itemEntry.getJavaIdentifier().equals(item)) return true;
- }
- return false;
+ public boolean acceptItem(ItemMapping mapping) {
+ return ITEMS.contains(mapping.getJavaIdentifier());
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/MapItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/MapItemTranslator.java
index 79db364b1..14342a8b3 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/MapItemTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/MapItemTranslator.java
@@ -28,14 +28,14 @@ package org.geysermc.connector.network.translators.item.translators.nbt;
import com.github.steveice10.opennbt.tag.builtin.*;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.ItemRemapper;
-import org.geysermc.connector.network.translators.item.ItemEntry;
import org.geysermc.connector.network.translators.item.NbtItemStackTranslator;
+import org.geysermc.connector.registry.type.ItemMapping;
@ItemRemapper
public class MapItemTranslator extends NbtItemStackTranslator {
@Override
- public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
// Can be either an IntTag or ShortTag
Tag mapId = itemTag.get("map");
if (mapId == null) return;
@@ -55,7 +55,7 @@ public class MapItemTranslator extends NbtItemStackTranslator {
}
@Override
- public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToJava(CompoundTag itemTag, ItemMapping mapping) {
IntTag tag = itemTag.get("map_name_index");
if (tag != null) {
itemTag.put(new IntTag("map", tag.getValue()));
@@ -65,7 +65,7 @@ public class MapItemTranslator extends NbtItemStackTranslator {
}
@Override
- public boolean acceptItem(ItemEntry itemEntry) {
- return itemEntry.getJavaIdentifier().equals("minecraft:filled_map");
+ public boolean acceptItem(ItemMapping mapping) {
+ return mapping.getJavaIdentifier().equals("minecraft:filled_map");
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/PlayerHeadTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/PlayerHeadTranslator.java
index 3824ff3c8..152c28daa 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/PlayerHeadTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/PlayerHeadTranslator.java
@@ -30,15 +30,15 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.ItemRemapper;
-import org.geysermc.connector.network.translators.item.ItemEntry;
import org.geysermc.connector.network.translators.item.NbtItemStackTranslator;
+import org.geysermc.connector.registry.type.ItemMapping;
import org.geysermc.connector.utils.LocaleUtils;
@ItemRemapper
public class PlayerHeadTranslator extends NbtItemStackTranslator {
@Override
- public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
if (!itemTag.contains("display") || !((CompoundTag) itemTag.get("display")).contains("Name")) {
if (itemTag.contains("SkullOwner")) {
StringTag name;
@@ -66,7 +66,7 @@ public class PlayerHeadTranslator extends NbtItemStackTranslator {
}
@Override
- public boolean acceptItem(ItemEntry itemEntry) {
- return itemEntry.getJavaIdentifier().equals("minecraft:player_head");
+ public boolean acceptItem(ItemMapping mapping) {
+ return mapping.getJavaIdentifier().equals("minecraft:player_head");
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/ShulkerBoxItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/ShulkerBoxItemTranslator.java
index 197e119fc..5f39d3a68 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/ShulkerBoxItemTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/ShulkerBoxItemTranslator.java
@@ -29,12 +29,13 @@ import com.github.steveice10.opennbt.tag.builtin.*;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.ItemRemapper;
import org.geysermc.connector.network.translators.item.*;
+import org.geysermc.connector.registry.type.ItemMapping;
@ItemRemapper
public class ShulkerBoxItemTranslator extends NbtItemStackTranslator {
@Override
- public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
if (!itemTag.contains("BlockEntityTag")) return; // Empty shulker box
CompoundTag blockEntityTag = itemTag.get("BlockEntityTag");
@@ -46,18 +47,18 @@ public class ShulkerBoxItemTranslator extends NbtItemStackTranslator {
boxItemTag.put(new ByteTag("Slot", ((ByteTag) itemData.get("Slot")).getValue()));
boxItemTag.put(new ByteTag("WasPickedUp", (byte) 0)); // ???
- ItemEntry boxItemEntry = ItemRegistry.getItemEntry(((StringTag) itemData.get("id")).getValue());
+ ItemMapping boxMapping = session.getItemMappings().getMapping(((StringTag) itemData.get("id")).getValue());
- boxItemTag.put(new StringTag("Name", boxItemEntry.getBedrockIdentifier()));
- boxItemTag.put(new ShortTag("Damage", (short) boxItemEntry.getBedrockData()));
+ boxItemTag.put(new StringTag("Name", boxMapping.getBedrockIdentifier()));
+ boxItemTag.put(new ShortTag("Damage", (short) boxMapping.getBedrockData()));
boxItemTag.put(new ByteTag("Count", ((ByteTag) itemData.get("Count")).getValue()));
// Only the display name is what we have interest in, so just translate that if relevant
CompoundTag displayTag = itemData.get("tag");
- if (displayTag == null && boxItemEntry instanceof TranslatableItemEntry) {
+ if (displayTag == null && boxMapping.hasTranslation()) {
displayTag = new CompoundTag("tag");
}
if (displayTag != null) {
- boxItemTag.put(ItemTranslator.translateDisplayProperties(session, displayTag, boxItemEntry, '7'));
+ boxItemTag.put(ItemTranslator.translateDisplayProperties(session, displayTag, boxMapping, '7'));
}
itemsList.add(boxItemTag);
@@ -69,14 +70,14 @@ public class ShulkerBoxItemTranslator extends NbtItemStackTranslator {
}
@Override
- public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
+ public void translateToJava(CompoundTag itemTag, ItemMapping mapping) {
if (itemTag.contains("Items")) { // Remove any extraneous Bedrock tag and don't touch the Java one
itemTag.remove("Items");
}
}
@Override
- public boolean acceptItem(ItemEntry itemEntry) {
- return itemEntry.getJavaIdentifier().contains("shulker_box");
+ public boolean acceptItem(ItemMapping mapping) {
+ return mapping.getJavaIdentifier().contains("shulker_box");
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaAdvancementsTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaAdvancementsTranslator.java
index 714578e9a..2e1057e0e 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaAdvancementsTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaAdvancementsTranslator.java
@@ -95,6 +95,8 @@ public class JavaAdvancementsTranslator extends PacketTranslator new HashSet<>()).add(node.getName().toLowerCase());
@@ -168,11 +167,12 @@ public class JavaDeclareCommandsTranslator extends PacketTranslator= 1) {
// Create the root param node and build all the children
ParamInfo rootParam = new ParamInfo(commandNode, null);
- rootParam.buildChildren(allNodes);
+ rootParam.buildChildren(session, allNodes);
List treeData = rootParam.getTree();
@@ -195,10 +195,11 @@ public class JavaDeclareCommandsTranslator extends PacketTranslator {
+ /**
+ * Required to use the specified cartography table recipes
+ */
+ private static final List CARTOGRAPHY_RECIPES = Arrays.asList(
+ CraftingData.fromMulti(UUID.fromString("8b36268c-1829-483c-a0f1-993b7156a8f2"), ++LAST_RECIPE_NET_ID), // Map extending
+ CraftingData.fromMulti(UUID.fromString("442d85ed-8272-4543-a6f1-418f90ded05d"), ++LAST_RECIPE_NET_ID), // Map cloning
+ CraftingData.fromMulti(UUID.fromString("98c84b38-1085-46bd-b1ce-dd38c159e6cc"), ++LAST_RECIPE_NET_ID), // Map upgrading
+ CraftingData.fromMulti(UUID.fromString("602234e4-cac1-4353-8bb7-b1ebff70024b"), ++LAST_RECIPE_NET_ID) // Map locking
+ );
@Override
public void translate(ServerDeclareRecipesPacket packet, GeyserSession session) {
+ Map> recipeTypes = Registries.CRAFTING_DATA.forVersion(session.getUpstream().getProtocolVersion());
// Get the last known network ID (first used for the pregenerated recipes) and increment from there.
- int netId = RecipeRegistry.LAST_RECIPE_NET_ID + 1;
- Int2ObjectMap recipeMap = new Int2ObjectOpenHashMap<>(RecipeRegistry.ALL_CRAFTING_RECIPES);
+ int netId = InventoryUtils.LAST_RECIPE_NET_ID + 1;
+
+ Int2ObjectMap recipeMap = new Int2ObjectOpenHashMap<>(Registries.RECIPES.forVersion(session.getUpstream().getProtocolVersion()));
Int2ObjectMap> unsortedStonecutterData = new Int2ObjectOpenHashMap<>();
CraftingDataPacket craftingDataPacket = new CraftingDataPacket();
craftingDataPacket.setCleanRecipes(true);
@@ -94,55 +111,6 @@ public class JavaDeclareRecipesTranslator extends PacketTranslator craftingData = recipeTypes.get(recipe.getType());
+ if (craftingData != null) {
+ craftingDataPacket.getCraftingData().addAll(craftingData);
+ }
+ break;
}
}
}
- // Add all cartography table recipe UUIDs, so we can use the cartography table
- craftingDataPacket.getCraftingData().addAll(RecipeRegistry.CARTOGRAPHY_RECIPE_DATA);
-
- craftingDataPacket.getPotionMixData().addAll(PotionMixRegistry.POTION_MIXES);
+ craftingDataPacket.getCraftingData().addAll(CARTOGRAPHY_RECIPES);
+ craftingDataPacket.getPotionMixData().addAll(Registries.POTION_MIXES.get());
Int2ObjectMap stonecutterRecipeMap = new Int2ObjectOpenHashMap<>();
for (Int2ObjectMap.Entry> data : unsortedStonecutterData.int2ObjectEntrySet()) {
// Sort the list by each output item's Java identifier - this is how it's sorted on Java, and therefore
// We can get the correct order for button pressing
data.getValue().sort(Comparator.comparing((stoneCuttingRecipeData ->
- ItemRegistry.getItem(stoneCuttingRecipeData.getResult()).getJavaIdentifier())));
+ session.getItemMappings().getItems().get(stoneCuttingRecipeData.getResult().getId()).getJavaIdentifier())));
// Now that it's sorted, let's translate these recipes
for (StoneCuttingRecipeData stoneCuttingData : data.getValue()) {
@@ -222,8 +196,8 @@ public class JavaDeclareRecipesTranslator extends PacketTranslator new IntOpenHashSet()).add(i);
}
int totalCombinations = 1;
- for (Set optionSet : squashedOptions.keySet()) {
+ for (Set optionSet : squashedOptions.keySet()) {
totalCombinations *= optionSet.size();
}
if (totalCombinations > 500) {
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java
index 162028ef8..af1cfc45b 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java
@@ -38,7 +38,6 @@ import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
@Translator(packet = ServerEntityStatusPacket.class)
public class JavaEntityStatusTranslator extends PacketTranslator {
@@ -98,7 +97,7 @@ public class JavaEntityStatusTranslator extends PacketTranslator {
@@ -77,7 +76,7 @@ public class JavaBlockValueTranslator extends PacketTranslator {
try {
+ if (session.isClosed()) {
+ return;
+ }
ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(session, column, yOffset);
ChunkSection[] sections = chunkData.getSections();
@@ -74,7 +77,7 @@ public class JavaChunkDataTranslator extends PacketTranslator {
@@ -44,7 +46,7 @@ public class JavaPlayBuiltinSoundTranslator extends PacketTranslator {
@@ -50,7 +51,7 @@ public class JavaPlaySoundTranslator extends PacketTranslator createParticle(GeyserSession session, Particle particle) {
switch (particle.getType()) {
case BLOCK: {
- int blockState = session.getBlockTranslator().getBedrockBlockId(((BlockParticleData) particle.getData()).getBlockState());
+ int blockState = session.getBlockMappings().getBedrockBlockId(((BlockParticleData) particle.getData()).getBlockState());
return (position) -> {
LevelEventPacket packet = new LevelEventPacket();
packet.setType(LevelEventType.PARTICLE_CRACK_BLOCK);
@@ -91,7 +91,7 @@ public class JavaSpawnParticleTranslator extends PacketTranslator {
LevelEventPacket packet = new LevelEventPacket();
// In fact, FallingDustParticle should have data like DustParticle,
@@ -130,7 +130,7 @@ public class JavaSpawnParticleTranslator extends PacketTranslator {
LevelEventPacket packet = new LevelEventPacket();
@@ -139,7 +139,7 @@ public class JavaSpawnParticleTranslator extends PacketTranslator {
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaStopSoundTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaStopSoundTranslator.java
index d7d0f0738..ebcf2234e 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaStopSoundTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaStopSoundTranslator.java
@@ -32,7 +32,8 @@ import com.nukkitx.protocol.bedrock.packet.StopSoundPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
-import org.geysermc.connector.network.translators.sound.SoundRegistry;
+import org.geysermc.connector.registry.Registries;
+import org.geysermc.connector.registry.type.SoundMapping;
@Translator(packet = ServerStopSoundPacket.class)
public class JavaStopSoundTranslator extends PacketTranslator {
@@ -57,7 +58,7 @@ public class JavaStopSoundTranslator extends PacketTranslator "
+ soundMapping + (soundMapping == null ? "[not found]" : "")
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaTradeListTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaTradeListTranslator.java
index c4dcf50c9..cce48f5cc 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaTradeListTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaTradeListTranslator.java
@@ -41,9 +41,8 @@ import org.geysermc.connector.inventory.MerchantContainer;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
-import org.geysermc.connector.network.translators.item.ItemEntry;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.network.translators.item.ItemTranslator;
+import org.geysermc.connector.registry.type.ItemMapping;
import java.util.ArrayList;
import java.util.List;
@@ -136,18 +135,18 @@ public class JavaTradeListTranslator extends PacketTranslator> interactionEntry : SoundHandlerRegistry.INTERACTION_HANDLERS.entrySet()) {
+ for (Map.Entry> interactionEntry : Registries.SOUND_HANDLERS.get().entrySet()) {
if (!(interactionEntry.getValue() instanceof BlockSoundInteractionHandler)) {
continue;
}
@@ -68,7 +69,7 @@ public interface BlockSoundInteractionHandler extends SoundInteractionHandler> interactionEntry : SoundHandlerRegistry.INTERACTION_HANDLERS.entrySet()) {
+ for (Map.Entry> interactionEntry : Registries.SOUND_HANDLERS.get().entrySet()) {
if (!(interactionEntry.getValue() instanceof EntitySoundInteractionHandler)) {
continue;
}
@@ -70,7 +71,7 @@ public interface EntitySoundInteractionHandler extends SoundInteractionHandler bedrockBlockStates;
-
- /**
- * Stores a list of differences in block identifiers.
- * Items will not be added to this list if the key and value is the same.
- */
- private static final Object2ObjectMap JAVA_TO_BEDROCK_IDENTIFIERS = new Object2ObjectOpenHashMap<>();
- private static final BiMap JAVA_ID_BLOCK_MAP = HashBiMap.create();
- private static final IntSet WATERLOGGED = new IntOpenHashSet();
- private final Object2IntMap itemFrames = new Object2IntOpenHashMap<>();
- private final Map flowerPotBlocks = new HashMap<>();
-
- private static final Int2ObjectMap JAVA_RUNTIME_ID_TO_BLOCK_MAPPING = new Int2ObjectOpenHashMap<>();
-
- /**
- * Java numeric ID to java unique identifier, used for block names in the statistics screen
- */
- public static final Int2ObjectMap JAVA_ID_TO_JAVA_IDENTIFIER_MAP = new Int2ObjectOpenHashMap<>();
-
- /**
- * Runtime command block ID, used for fixing command block minecart appearances
- */
- @Getter
- private final int bedrockRuntimeCommandBlockId;
-
- private final EmptyChunkProvider emptyChunkProvider;
-
- public static final int JAVA_COBWEB_BLOCK_ID;
- public static final int JAVA_BELL_BLOCK_ID;
-
- public static final int JAVA_RUNTIME_FURNACE_ID;
- public static final int JAVA_RUNTIME_FURNACE_LIT_ID;
-
- public static final int JAVA_RUNTIME_SPAWNER_ID;
-
- /**
- * Contains a map of Java blocks to their respective Bedrock block tag, if the Java identifier is different from Bedrock.
- * Required to fix villager trades with these blocks.
- */
- private final Map javaIdentifierToBedrockTag;
-
- /**
- * Stores the raw blocks JSON until it is no longer needed.
- */
- public static JsonNode BLOCKS_JSON;
-
- static {
- InputStream stream = FileUtils.getResource("mappings/blocks.json");
- try {
- BLOCKS_JSON = GeyserConnector.JSON_MAPPER.readTree(stream);
- } catch (Exception e) {
- throw new AssertionError("Unable to load Java block mappings", e);
- }
-
- int javaRuntimeId = -1;
- int bellBlockId = -1;
- int cobwebBlockId = -1;
- int furnaceRuntimeId = -1;
- int furnaceLitRuntimeId = -1;
- int spawnerRuntimeId = -1;
- int uniqueJavaId = -1;
- int waterRuntimeId = -1;
- Iterator> blocksIterator = BLOCKS_JSON.fields();
- while (blocksIterator.hasNext()) {
- javaRuntimeId++;
- Map.Entry entry = blocksIterator.next();
- String javaId = entry.getKey();
-
- BlockMapping.BlockMappingBuilder builder = BlockMapping.builder();
- // TODO fix this, (no block should have a null hardness)
- JsonNode hardnessNode = entry.getValue().get("block_hardness");
- if (hardnessNode != null) {
- builder.hardness(hardnessNode.doubleValue());
- }
-
- JsonNode canBreakWithHandNode = entry.getValue().get("can_break_with_hand");
- if (canBreakWithHandNode != null) {
- builder.canBreakWithHand(canBreakWithHandNode.booleanValue());
- } else {
- builder.canBreakWithHand(false);
- }
-
- JsonNode collisionIndexNode = entry.getValue().get("collision_index");
- if (hardnessNode != null) {
- builder.collisionIndex(collisionIndexNode.intValue());
- }
-
- JsonNode pickItemNode = entry.getValue().get("pick_item");
- if (pickItemNode != null) {
- builder.pickItem(pickItemNode.textValue());
- }
-
- boolean waterlogged = entry.getKey().contains("waterlogged=true")
- || javaId.contains("minecraft:bubble_column") || javaId.contains("minecraft:kelp") || javaId.contains("seagrass");
-
- if (waterlogged) {
- WATERLOGGED.add(javaRuntimeId);
- }
-
- JAVA_ID_BLOCK_MAP.put(javaId, javaRuntimeId);
-
- BlockStateValues.storeBlockStateValues(entry.getKey(), javaRuntimeId, entry.getValue());
-
- String cleanJavaIdentifier = entry.getKey().split("\\[")[0];
- String bedrockIdentifier = entry.getValue().get("bedrock_identifier").asText();
-
- if (!JAVA_ID_TO_JAVA_IDENTIFIER_MAP.containsValue(cleanJavaIdentifier)) {
- uniqueJavaId++;
- JAVA_ID_TO_JAVA_IDENTIFIER_MAP.put(uniqueJavaId, cleanJavaIdentifier);
- }
-
- // Keeping this here since this is currently unchanged between versions
- if (!cleanJavaIdentifier.equals(bedrockIdentifier)) {
- JAVA_TO_BEDROCK_IDENTIFIERS.put(cleanJavaIdentifier, bedrockIdentifier);
- }
-
- builder.javaBlockId(uniqueJavaId);
-
- builder.javaIdentifier(javaId);
-
- JAVA_RUNTIME_ID_TO_BLOCK_MAPPING.put(javaRuntimeId, builder.build());
-
- if (javaId.startsWith("minecraft:bell[")) {
- bellBlockId = uniqueJavaId;
-
- } else if (javaId.contains("cobweb")) {
- cobwebBlockId = uniqueJavaId;
-
- } else if (javaId.startsWith("minecraft:furnace[facing=north")) {
- if (javaId.contains("lit=true")) {
- furnaceLitRuntimeId = javaRuntimeId;
- } else {
- furnaceRuntimeId = javaRuntimeId;
- }
-
- } else if (javaId.startsWith("minecraft:spawner")) {
- spawnerRuntimeId = javaRuntimeId;
-
- } else if ("minecraft:water[level=0]".equals(javaId)) {
- waterRuntimeId = javaRuntimeId;
- }
- }
-
- if (bellBlockId == -1) {
- throw new AssertionError("Unable to find bell in palette");
- }
- JAVA_BELL_BLOCK_ID = bellBlockId;
-
- if (cobwebBlockId == -1) {
- throw new AssertionError("Unable to find cobwebs in palette");
- }
- JAVA_COBWEB_BLOCK_ID = cobwebBlockId;
-
- if (furnaceRuntimeId == -1) {
- throw new AssertionError("Unable to find furnace in palette");
- }
- JAVA_RUNTIME_FURNACE_ID = furnaceRuntimeId;
-
- if (furnaceLitRuntimeId == -1) {
- throw new AssertionError("Unable to find lit furnace in palette");
- }
- JAVA_RUNTIME_FURNACE_LIT_ID = furnaceLitRuntimeId;
-
- if (spawnerRuntimeId == -1) {
- throw new AssertionError("Unable to find spawner in palette");
- }
- JAVA_RUNTIME_SPAWNER_ID = spawnerRuntimeId;
-
- if (waterRuntimeId == -1) {
- throw new AssertionError("Unable to find Java water in palette");
- }
- JAVA_WATER_ID = waterRuntimeId;
-
- BlockMapping.AIR = JAVA_RUNTIME_ID_TO_BLOCK_MAPPING.get(JAVA_AIR_ID);
-
- BlockTranslator1_17_0.init();
- BLOCKS_JSON = null; // We no longer require this so let it garbage collect away
- }
-
- public BlockTranslator(String paletteFile) {
- /* Load block palette */
- InputStream stream = FileUtils.getResource(paletteFile);
-
- NbtList blocksTag;
- try (NBTInputStream nbtInputStream = new NBTInputStream(new DataInputStream(new GZIPInputStream(stream)))) {
- NbtMap blockPalette = (NbtMap) nbtInputStream.readTag();
- blocksTag = (NbtList) blockPalette.getList("blocks", NbtType.COMPOUND);
- this.bedrockBlockStates = blocksTag;
- } catch (Exception e) {
- throw new AssertionError("Unable to get blocks from runtime block states", e);
- }
-
- javaIdentifierToBedrockTag = new Object2ObjectOpenHashMap<>();
-
- // New since 1.16.100 - find the block runtime ID by the order given to us in the block palette,
- // as we no longer send a block palette
- Object2IntMap blockStateOrderedMap = new Object2IntOpenHashMap<>(blocksTag.size());
-
- for (int i = 0; i < blocksTag.size(); i++) {
- NbtMap tag = blocksTag.get(i);
- if (blockStateOrderedMap.containsKey(tag)) {
- throw new AssertionError("Duplicate block states in Bedrock palette: " + tag);
- }
- blockStateOrderedMap.put(tag, i);
- }
-
- int airRuntimeId = -1;
- int commandBlockRuntimeId = -1;
- int javaRuntimeId = -1;
- int waterRuntimeId = -1;
- Iterator> blocksIterator = BLOCKS_JSON.fields();
- while (blocksIterator.hasNext()) {
- javaRuntimeId++;
- Map.Entry entry = blocksIterator.next();
- String javaId = entry.getKey();
-
- NbtMap blockTag = buildBedrockState(entry.getValue());
- int bedrockRuntimeId = blockStateOrderedMap.getOrDefault(blockTag, -1);
- if (bedrockRuntimeId == -1) {
- throw new RuntimeException("Unable to find " + javaId + " Bedrock runtime ID! Built compound tag: \n" + blockTag);
- }
-
- switch (javaId) {
- case "minecraft:air":
- airRuntimeId = bedrockRuntimeId;
- break;
- case "minecraft:water[level=0]":
- waterRuntimeId = bedrockRuntimeId;
- break;
- case "minecraft:command_block[conditional=false,facing=north]":
- commandBlockRuntimeId = bedrockRuntimeId;
- break;
- }
-
- boolean waterlogged = entry.getKey().contains("waterlogged=true")
- || javaId.contains("minecraft:bubble_column") || javaId.contains("minecraft:kelp") || javaId.contains("seagrass");
-
- if (waterlogged) {
- bedrockToJavaBlockMap.putIfAbsent(bedrockRuntimeId | 1 << 31, javaRuntimeId);
- } else {
- bedrockToJavaBlockMap.putIfAbsent(bedrockRuntimeId, javaRuntimeId);
- }
-
- String cleanJavaIdentifier = entry.getKey().split("\\[")[0];
-
- // Get the tag needed for non-empty flower pots
- if (entry.getValue().get("pottable") != null) {
- flowerPotBlocks.put(cleanJavaIdentifier, blockTag);
- }
-
- if (!cleanJavaIdentifier.equals(entry.getValue().get("bedrock_identifier").asText())) {
- javaIdentifierToBedrockTag.put(cleanJavaIdentifier, blockTag);
- }
-
- javaToBedrockBlockMap.put(javaRuntimeId, bedrockRuntimeId);
- }
-
- if (commandBlockRuntimeId == -1) {
- throw new AssertionError("Unable to find command block in palette");
- }
- bedrockRuntimeCommandBlockId = commandBlockRuntimeId;
-
- if (waterRuntimeId == -1) {
- throw new AssertionError("Unable to find water in palette");
- }
- bedrockWaterId = waterRuntimeId;
-
- if (airRuntimeId == -1) {
- throw new AssertionError("Unable to find air in palette");
- }
- bedrockAirId = airRuntimeId;
-
- // Loop around again to find all item frame runtime IDs
- for (Object2IntMap.Entry entry : blockStateOrderedMap.object2IntEntrySet()) {
- String name = entry.getKey().getString("name");
- if (name.equals("minecraft:frame") || name.equals("minecraft:glow_frame")) {
- itemFrames.put(entry.getKey(), entry.getIntValue());
- }
- }
-
- this.emptyChunkProvider = new EmptyChunkProvider(bedrockAirId);
- }
-
- public static void init() {
- // no-op
- }
-
- private NbtMap buildBedrockState(JsonNode node) {
- NbtMapBuilder tagBuilder = NbtMap.builder();
- String bedrockIdentifier = node.get("bedrock_identifier").textValue();
- tagBuilder.putString("name", bedrockIdentifier)
- .putInt("version", getBlockStateVersion());
-
- NbtMapBuilder statesBuilder = NbtMap.builder();
-
- // check for states
- if (node.has("bedrock_states")) {
- Iterator> statesIterator = node.get("bedrock_states").fields();
-
- while (statesIterator.hasNext()) {
- Map.Entry stateEntry = statesIterator.next();
- JsonNode stateValue = stateEntry.getValue();
- switch (stateValue.getNodeType()) {
- case BOOLEAN:
- statesBuilder.putBoolean(stateEntry.getKey(), stateValue.booleanValue());
- continue;
- case STRING:
- statesBuilder.putString(stateEntry.getKey(), stateValue.textValue());
- continue;
- case NUMBER:
- statesBuilder.putInt(stateEntry.getKey(), stateValue.intValue());
- }
- }
- }
- tagBuilder.put("states", adjustBlockStateForVersion(bedrockIdentifier, statesBuilder).build());
- return tagBuilder.build();
- }
-
- /**
- * @return an adjusted state list, if necessary, that converts Geyser's new mapping to Bedrock's older version
- * of the mapping.
- */
- protected NbtMapBuilder adjustBlockStateForVersion(String bedrockIdentifier, NbtMapBuilder statesBuilder) {
- return statesBuilder;
- }
-
- public int getBedrockBlockId(int state) {
- return javaToBedrockBlockMap.get(state);
- }
-
- public int getJavaBlockState(int bedrockId) {
- return bedrockToJavaBlockMap.get(bedrockId);
- }
-
- /**
- * @param javaIdentifier the Java identifier of the block to search for
- * @return the Bedrock identifier if different, or else the Java identifier
- */
- public String getBedrockBlockIdentifier(String javaIdentifier) {
- return JAVA_TO_BEDROCK_IDENTIFIERS.getOrDefault(javaIdentifier, javaIdentifier);
- }
-
- public int getItemFrame(NbtMap tag) {
- return itemFrames.getOrDefault(tag, -1);
- }
-
- public boolean isItemFrame(int bedrockBlockRuntimeId) {
- return itemFrames.values().contains(bedrockBlockRuntimeId);
- }
-
- /**
- * Get the map of contained flower pot plants to Bedrock CompoundTag
- *
- * @return Map of flower pot blocks.
- */
- public Map getFlowerPotBlocks() {
- return flowerPotBlocks;
- }
-
- public int getBedrockAirId() {
- return bedrockAirId;
- }
-
- public int getBedrockWaterId() {
- return bedrockWaterId;
- }
-
- public NbtList getAllBedrockBlockStates() {
- return this.bedrockBlockStates;
- }
-
- /**
- * @return the "block state version" generated in the Bedrock block palette that completes an NBT indication of a
- * block state.
- */
- public abstract int getBlockStateVersion();
-
- public byte[] getEmptyChunkData() {
- return emptyChunkProvider.getEmptyLevelChunkData();
- }
-
- public ChunkSection getEmptyChunkSection() {
- return emptyChunkProvider.getEmptySection();
- }
-
- /**
- * @param javaId the Java string identifier to search for
- * @return the Java block state integer, or {@link #JAVA_AIR_ID} if there is no valid entry.
- */
- public static int getJavaBlockState(String javaId) {
- return JAVA_ID_BLOCK_MAP.getOrDefault(javaId, JAVA_AIR_ID);
- }
-
- public static boolean isWaterlogged(int state) {
- return WATERLOGGED.contains(state);
- }
-
- public static BiMap getJavaIdBlockMap() {
- return JAVA_ID_BLOCK_MAP;
- }
-
- /**
- * @param javaRuntimeId the Java runtime ID of the block to search for.
- * @return the corresponding block mapping for this runtime ID.
- */
- public static BlockMapping getBlockMapping(int javaRuntimeId) {
- return JAVA_RUNTIME_ID_TO_BLOCK_MAPPING.getOrDefault(javaRuntimeId, BlockMapping.AIR);
- }
-
- /**
- * @return a list of all Java block identifiers. For use with command suggestions.
- */
- public static String[] getAllBlockIdentifiers() {
- return JAVA_ID_TO_JAVA_IDENTIFIER_MAP.values().toArray(new String[0]);
- }
-
- /**
- * @param cleanJavaIdentifier the clean Java identifier of the block to look up
- *
- * @return the block tag of the block name mapped from Java to Bedrock.
- */
- public NbtMap getBedrockBlockNbt(String cleanJavaIdentifier) {
- return javaIdentifierToBedrockTag.get(cleanJavaIdentifier);
- }
-}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/BlockEntityTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/BlockEntityTranslator.java
index 983a3d06d..41843e96a 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/BlockEntityTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/BlockEntityTranslator.java
@@ -31,69 +31,15 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtMapBuilder;
-import it.unimi.dsi.fastutil.objects.ObjectArrayList;
-import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.utils.BlockEntityUtils;
-import org.geysermc.connector.utils.FileUtils;
-import org.reflections.Reflections;
-
-import java.util.HashMap;
-import java.util.Map;
/**
* The class that all block entities (on both Java and Bedrock) should translate with
*/
public abstract class BlockEntityTranslator {
- public static final Map BLOCK_ENTITY_TRANSLATORS = new HashMap<>();
- /**
- * A list of all block entities that only exist on Bedrock
- */
- public static final ObjectArrayList BEDROCK_ONLY_BLOCK_ENTITIES = new ObjectArrayList<>();
-
- /**
- * Contains a list of irregular block entity name translations that can't be fit into the regex
- */
- public static final Map BLOCK_ENTITY_TRANSLATIONS = new HashMap() {
- {
- // Bedrock/Java differences
- put("minecraft:enchanting_table", "EnchantTable");
- put("minecraft:jigsaw", "JigsawBlock");
- put("minecraft:piston_head", "PistonArm");
- put("minecraft:trapped_chest", "Chest");
- // There are some legacy IDs sent but as far as I can tell they are not needed for things to work properly
- }
- };
-
protected BlockEntityTranslator() {
}
- public static void init() {
- // no-op
- }
-
- static {
- Reflections ref = GeyserConnector.getInstance().useXmlReflections() ? FileUtils.getReflections("org.geysermc.connector.network.translators.world.block.entity") : new Reflections("org.geysermc.connector.network.translators.world.block.entity");
- for (Class> clazz : ref.getTypesAnnotatedWith(BlockEntity.class)) {
- GeyserConnector.getInstance().getLogger().debug("Found annotated block entity: " + clazz.getCanonicalName());
-
- try {
- BLOCK_ENTITY_TRANSLATORS.put(clazz.getAnnotation(BlockEntity.class).name(), (BlockEntityTranslator) clazz.newInstance());
- } catch (InstantiationException | IllegalAccessException e) {
- GeyserConnector.getInstance().getLogger().error("Could not instantiate annotated block entity" + clazz.getCanonicalName());
- }
- }
- for (Class> clazz : ref.getSubTypesOf(BedrockOnlyBlockEntity.class)) {
- GeyserConnector.getInstance().getLogger().debug("Found Bedrock-only block entity: " + clazz.getCanonicalName());
-
- try {
- BedrockOnlyBlockEntity bedrockOnlyBlockEntity = (BedrockOnlyBlockEntity) clazz.newInstance();
- BEDROCK_ONLY_BLOCK_ENTITIES.add(bedrockOnlyBlockEntity);
- } catch (InstantiationException | IllegalAccessException e) {
- GeyserConnector.getInstance().getLogger().error("Could not instantiate annotated block state " + clazz.getCanonicalName());
- }
- }
- }
-
public abstract void translateTag(NbtMapBuilder builder, CompoundTag tag, int blockState);
public NbtMap getBlockEntityTag(String id, CompoundTag tag, int blockState) {
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/CampfireBlockEntityTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/CampfireBlockEntityTranslator.java
index 40f305ad6..88bb14203 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/CampfireBlockEntityTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/CampfireBlockEntityTranslator.java
@@ -29,8 +29,9 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtMapBuilder;
-import org.geysermc.connector.network.translators.item.ItemEntry;
-import org.geysermc.connector.network.translators.item.ItemRegistry;
+import org.geysermc.connector.network.BedrockProtocol;
+import org.geysermc.connector.registry.Registries;
+import org.geysermc.connector.registry.type.ItemMapping;
@BlockEntity(name = "Campfire")
public class CampfireBlockEntityTranslator extends BlockEntityTranslator {
@@ -45,11 +46,12 @@ public class CampfireBlockEntityTranslator extends BlockEntityTranslator {
}
protected NbtMap getItem(CompoundTag tag) {
- ItemEntry entry = ItemRegistry.getItemEntry((String) tag.get("id").getValue());
+ // TODO: Version independent mappings
+ ItemMapping mapping = Registries.ITEMS.forVersion(BedrockProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion()).getMapping((String) tag.get("id").getValue());
NbtMapBuilder tagBuilder = NbtMap.builder()
- .putString("Name", entry.getBedrockIdentifier())
+ .putString("Name", mapping.getBedrockIdentifier())
.putByte("Count", (byte) tag.get("Count").getValue())
- .putShort("Damage", (short) entry.getBedrockData());
+ .putShort("Damage", (short) mapping.getBedrockData());
tagBuilder.put("tag", NbtMap.builder().build());
return tagBuilder.build();
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/FlowerPotBlockEntityTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/FlowerPotBlockEntityTranslator.java
index 1fa6cab02..833542543 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/FlowerPotBlockEntityTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/FlowerPotBlockEntityTranslator.java
@@ -61,7 +61,7 @@ public class FlowerPotBlockEntityTranslator implements BedrockOnlyBlockEntity {
if (name != null) {
// Get the Bedrock CompoundTag of the block.
// This is where we need to store the *Java* name because Bedrock has six minecraft:sapling blocks with different block states.
- NbtMap plant = session.getBlockTranslator().getFlowerPotBlocks().get(name);
+ NbtMap plant = session.getBlockMappings().getFlowerPotBlocks().get(name);
if (plant != null) {
tagBuilder.put("PlantBlock", plant.toBuilder().build());
}
@@ -80,7 +80,7 @@ public class FlowerPotBlockEntityTranslator implements BedrockOnlyBlockEntity {
BlockEntityUtils.updateBlockEntity(session, tag, position);
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
updateBlockPacket.setDataLayer(0);
- updateBlockPacket.setRuntimeId(session.getBlockTranslator().getBedrockBlockId(blockState));
+ updateBlockPacket.setRuntimeId(session.getBlockMappings().getBedrockBlockId(blockState));
updateBlockPacket.setBlockPosition(position);
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NETWORK);
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/SignBlockEntityTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/SignBlockEntityTranslator.java
index ad6c32d4f..0551386c5 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/SignBlockEntityTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/SignBlockEntityTranslator.java
@@ -34,69 +34,72 @@ import org.geysermc.connector.utils.SignUtils;
@BlockEntity(name = "Sign")
public class SignBlockEntityTranslator extends BlockEntityTranslator {
/**
- * Maps a color stored in a sign's Color tag to a Bedrock Edition formatting code.
- *
- * The color names correspond to dye names, because of this we can't use a more global method.
+ * Maps a color stored in a sign's Color tag to its ARGB value.
*
* @param javaColor The dye color stored in the sign's Color tag.
- * @return A Bedrock Edition formatting code for valid dye colors, otherwise an empty string.
+ * @return Java Edition's integer matching the color specified
*/
- private String getBedrockSignColor(String javaColor) {
- String base = "\u00a7";
+ private int getBedrockSignColor(String javaColor) {
+ //TODO create a DyeColor class and combine with FireworkColor???
+ int dyeColor;
switch (javaColor) {
case "white":
- base += 'f';
+ dyeColor = 16383998;
break;
case "orange":
- base += '6';
+ dyeColor = 16351261;
break;
case "magenta":
- case "purple":
- base += '5';
+ dyeColor = 13061821;
break;
case "light_blue":
- base += 'b';
+ dyeColor = 3847130;
break;
case "yellow":
- base += 'e';
+ dyeColor = 16701501;
break;
case "lime":
- base += 'a';
+ dyeColor = 8439583;
break;
case "pink":
- base += 'd';
+ dyeColor = 15961002;
break;
case "gray":
- base += '8';
+ dyeColor = 4673362;
break;
case "light_gray":
- base += '7';
+ dyeColor = 10329495;
break;
case "cyan":
- base += '3';
+ dyeColor = 1481884;
+ break;
+ case "purple":
+ dyeColor = 8991416;
break;
case "blue":
- base += '9';
+ dyeColor = 3949738;
break;
- case "brown": // Brown does not have a bedrock counterpart.
- case "red": // In Java Edition light red (&c) can only be applied using commands. Red dye gives &4.
- base += '4';
+ case "brown":
+ dyeColor = 8606770;
break;
case "green":
- base += '2';
+ dyeColor = 6192150;
+ break;
+ case "red":
+ dyeColor = 11546150;
break;
case "black":
- base += '0';
- break;
default:
- return "";
+ // The proper Java color is 1908001, but this does not render well with glow text.
+ dyeColor = 0;
+ break;
}
- return base;
+ // Add the transparency of the color, too.
+ return dyeColor | (255 << 24);
}
@Override
public void translateTag(NbtMapBuilder builder, CompoundTag tag, int blockState) {
- //TODO Bedrock 1.17.10 glow text
StringBuilder signText = new StringBuilder();
for (int i = 0; i < 4; i++) {
int currentLine = i + 1;
@@ -127,16 +130,21 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator {
}
}
- // Java Edition 1.14 added the ability to change the text color of the whole sign using dye
- Tag color = tag.get("Color");
- if (color != null) {
- signText.append(getBedrockSignColor(color.getValue().toString()));
- }
-
signText.append(finalSignLine);
signText.append("\n");
}
- builder.put("Text", signText.toString());
+ builder.putString("Text", signText.toString());
+
+ // Java Edition 1.14 added the ability to change the text color of the whole sign using dye
+ Tag color = tag.get("Color");
+ if (color != null) {
+ builder.putInt("SignTextColor", getBedrockSignColor(color.getValue().toString()));
+ }
+
+ // Glowing text
+ boolean isGlowing = getOrDefault(tag.getValue().get("GlowingText"), (byte) 0) != (byte) 0;
+ builder.putBoolean("IgnoreLighting", isGlowing);
+ builder.putBoolean("TextIgnoreLegacyBugResolved", isGlowing); // ??? required
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/registry/AbstractMappedRegistry.java b/connector/src/main/java/org/geysermc/connector/registry/AbstractMappedRegistry.java
new file mode 100644
index 000000000..034eef706
--- /dev/null
+++ b/connector/src/main/java/org/geysermc/connector/registry/AbstractMappedRegistry.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author GeyserMC
+ * @link https://github.com/GeyserMC/Geyser
+ */
+
+package org.geysermc.connector.registry;
+
+import org.geysermc.connector.registry.loader.RegistryLoader;
+
+import java.util.Map;
+
+public abstract class AbstractMappedRegistry> extends Registry {
+ protected AbstractMappedRegistry(I input, RegistryLoader registryLoader) {
+ super(input, registryLoader);
+ }
+
+ public V get(K key) {
+ return this.mappings.get(key);
+ }
+
+ public V getOrDefault(K key, V defaultValue) {
+ return this.mappings.getOrDefault(key, defaultValue);
+ }
+
+ public V register(K key, V value) {
+ return this.mappings.put(key, value);
+ }
+}
\ No newline at end of file
diff --git a/connector/src/main/java/org/geysermc/connector/registry/BlockRegistries.java b/connector/src/main/java/org/geysermc/connector/registry/BlockRegistries.java
new file mode 100644
index 000000000..bc92f4b93
--- /dev/null
+++ b/connector/src/main/java/org/geysermc/connector/registry/BlockRegistries.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author GeyserMC
+ * @link https://github.com/GeyserMC/Geyser
+ */
+
+package org.geysermc.connector.registry;
+
+import com.google.common.collect.BiMap;
+import com.google.common.collect.HashBiMap;
+import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
+import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
+import it.unimi.dsi.fastutil.ints.IntSet;
+import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
+import org.geysermc.connector.registry.loader.RegistryLoaders;
+import org.geysermc.connector.registry.populator.BlockRegistryPopulator;
+import org.geysermc.connector.registry.type.BlockMapping;
+import org.geysermc.connector.registry.type.BlockMappings;
+
+public class BlockRegistries {
+ public static final VersionedRegistry BLOCKS = VersionedRegistry.create(RegistryLoaders.empty(Int2ObjectOpenHashMap::new));
+
+ public static final SimpleMappedRegistry JAVA_TO_BEDROCK_IDENTIFIERS = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new));
+
+ public static final SimpleMappedRegistry JAVA_BLOCKS = SimpleMappedRegistry.create(RegistryLoaders.empty(Int2ObjectOpenHashMap::new));
+
+ public static final MappedRegistry> JAVA_IDENTIFIERS = MappedRegistry.create(RegistryLoaders.empty(HashBiMap::create));
+
+ public static final SimpleMappedRegistry JAVA_CLEAN_IDENTIFIERS = SimpleMappedRegistry.create(RegistryLoaders.empty(Int2ObjectOpenHashMap::new));
+
+ public static final SimpleRegistry WATERLOGGED = SimpleRegistry.create(RegistryLoaders.empty(IntOpenHashSet::new));
+
+ static {
+ BlockRegistryPopulator.populate();
+ }
+
+ public static void init() {
+ // no-op
+ }
+}
\ No newline at end of file
diff --git a/connector/src/main/java/org/geysermc/connector/registry/MappedRegistry.java b/connector/src/main/java/org/geysermc/connector/registry/MappedRegistry.java
new file mode 100644
index 000000000..41d831f98
--- /dev/null
+++ b/connector/src/main/java/org/geysermc/connector/registry/MappedRegistry.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author GeyserMC
+ * @link https://github.com/GeyserMC/Geyser
+ */
+
+package org.geysermc.connector.registry;
+
+import org.geysermc.connector.registry.loader.RegistryLoader;
+
+import java.util.Map;
+import java.util.function.Supplier;
+
+public class MappedRegistry> extends AbstractMappedRegistry {
+ protected MappedRegistry(I input, RegistryLoader registryLoader) {
+ super(input, registryLoader);
+ }
+
+ public static > MappedRegistry createEmpty() {
+ return new MappedRegistry<>(null, input -> null);
+ }
+
+ public static > MappedRegistry create(RegistryLoader registryLoader) {
+ return new MappedRegistry<>(null, registryLoader);
+ }
+
+ public static > MappedRegistry create(I input, RegistryLoader registryLoader) {
+ return new MappedRegistry<>(input, registryLoader);
+ }
+
+ public static > MappedRegistry create(Supplier> registryLoader) {
+ return new MappedRegistry<>(null, registryLoader.get());
+ }
+
+ public static > MappedRegistry create(I input, Supplier> registryLoader) {
+ return new MappedRegistry<>(input, registryLoader.get());
+ }
+}
\ No newline at end of file
diff --git a/connector/src/main/java/org/geysermc/connector/registry/Registries.java b/connector/src/main/java/org/geysermc/connector/registry/Registries.java
new file mode 100644
index 000000000..cb23e9976
--- /dev/null
+++ b/connector/src/main/java/org/geysermc/connector/registry/Registries.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author GeyserMC
+ * @link https://github.com/GeyserMC/Geyser
+ */
+
+package org.geysermc.connector.registry;
+
+import com.github.steveice10.mc.protocol.data.game.recipe.Recipe;
+import com.github.steveice10.mc.protocol.data.game.recipe.RecipeType;
+import com.github.steveice10.mc.protocol.data.game.world.effect.SoundEffect;
+import com.github.steveice10.mc.protocol.data.game.world.particle.ParticleType;
+import com.nukkitx.nbt.NbtMap;
+import com.nukkitx.protocol.bedrock.data.SoundEvent;
+import com.nukkitx.protocol.bedrock.data.inventory.CraftingData;
+import com.nukkitx.protocol.bedrock.data.inventory.PotionMixData;
+import it.unimi.dsi.fastutil.Pair;
+import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
+import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
+import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
+import org.geysermc.connector.network.translators.collision.translators.BlockCollision;
+import org.geysermc.connector.network.translators.effect.Effect;
+import org.geysermc.connector.network.translators.sound.SoundHandler;
+import org.geysermc.connector.network.translators.sound.SoundInteractionHandler;
+import org.geysermc.connector.network.translators.world.block.entity.BlockEntityTranslator;
+import org.geysermc.connector.registry.loader.BlockEntityRegistryLoader;
+import org.geysermc.connector.registry.loader.CollisionRegistryLoader;
+import org.geysermc.connector.registry.loader.ParticleTypesRegistryLoader;
+import org.geysermc.connector.registry.loader.PotionMixRegistryLoader;
+import org.geysermc.connector.registry.loader.RegistryLoaders;
+import org.geysermc.connector.registry.loader.SoundEffectsRegistryLoader;
+import org.geysermc.connector.registry.loader.SoundHandlerRegistryLoader;
+import org.geysermc.connector.registry.loader.SoundRegistryLoader;
+import org.geysermc.connector.registry.populator.ItemRegistryPopulator;
+import org.geysermc.connector.registry.populator.RecipeRegistryPopulator;
+import org.geysermc.connector.registry.type.ItemMappings;
+import org.geysermc.connector.registry.type.ParticleMapping;
+import org.geysermc.connector.registry.type.SoundMapping;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class Registries {
+ public static final SimpleRegistry BIOMES = SimpleRegistry.create("bedrock/biome_definitions.dat", RegistryLoaders.NBT);
+
+ public static final SimpleMappedRegistry BLOCK_ENTITIES = SimpleMappedRegistry.create("org.geysermc.connector.network.translators.world.block.entity", BlockEntityRegistryLoader::new);
+
+ public static final SimpleMappedRegistry COLLISIONS = SimpleMappedRegistry.create(Pair.of("org.geysermc.connector.network.translators.collision.translators", "mappings/collision.json"), CollisionRegistryLoader::new);
+
+ public static final VersionedRegistry