Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-04 15:20:09 +01:00
Implement a new registry system (#2306)
Co-authored-by: Camotoy <20743703+Camotoy@users.noreply.github.com>
Dieser Commit ist enthalten in:
Ursprung
887296ef78
Commit
f7ef90278b
@ -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.
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>bootstrap-parent</artifactId>
|
||||
<version>1.4.0-SNAPSHOT</version>
|
||||
<version>1.4.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>bootstrap-bungeecord</artifactId>
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
<dependency>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>connector</artifactId>
|
||||
<version>1.4.0-SNAPSHOT</version>
|
||||
<version>1.4.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>geyser-parent</artifactId>
|
||||
<version>1.4.0-SNAPSHOT</version>
|
||||
<version>1.4.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>bootstrap-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>bootstrap-parent</artifactId>
|
||||
<version>1.4.0-SNAPSHOT</version>
|
||||
<version>1.4.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>bootstrap-spigot</artifactId>
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
<dependency>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>connector</artifactId>
|
||||
<version>1.4.0-SNAPSHOT</version>
|
||||
<version>1.4.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -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<ItemStack, ItemData> 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) {
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>bootstrap-parent</artifactId>
|
||||
<version>1.4.0-SNAPSHOT</version>
|
||||
<version>1.4.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>bootstrap-sponge</artifactId>
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
<dependency>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>connector</artifactId>
|
||||
<version>1.4.0-SNAPSHOT</version>
|
||||
<version>1.4.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>bootstrap-parent</artifactId>
|
||||
<version>1.4.0-SNAPSHOT</version>
|
||||
<version>1.4.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>bootstrap-standalone</artifactId>
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
<dependency>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>connector</artifactId>
|
||||
<version>1.4.0-SNAPSHOT</version>
|
||||
<version>1.4.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>bootstrap-parent</artifactId>
|
||||
<version>1.4.0-SNAPSHOT</version>
|
||||
<version>1.4.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>bootstrap-velocity</artifactId>
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
<dependency>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>connector</artifactId>
|
||||
<version>1.4.0-SNAPSHOT</version>
|
||||
<version>1.4.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>geyser-parent</artifactId>
|
||||
<version>1.4.0-SNAPSHOT</version>
|
||||
<version>1.4.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>common</artifactId>
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>geyser-parent</artifactId>
|
||||
<version>1.4.0-SNAPSHOT</version>
|
||||
<version>1.4.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>connector</artifactId>
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
<dependency>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>1.4.0-SNAPSHOT</version>
|
||||
<version>1.4.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- Jackson JSON and YAML serialization -->
|
||||
@ -57,8 +57,8 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.CloudburstMC.Protocol</groupId>
|
||||
<artifactId>bedrock-v440</artifactId>
|
||||
<version>1656151</version>
|
||||
<artifactId>bedrock-v448</artifactId>
|
||||
<version>ddfa38b</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
* <code>wheat</code>.
|
||||
* @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");
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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<Vector3i, SkullPlayerEntity> skullCache = new ConcurrentHashMap<>();
|
||||
private final Long2ObjectMap<ClientboundMapItemDataPacket> 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?
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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<BlockPic
|
||||
int blockToPick = session.getConnector().getWorldManager().getBlockAt(session, vector.getX(), vector.getY(), vector.getZ());
|
||||
|
||||
// Block is air - chunk caching is probably off
|
||||
if (blockToPick == BlockTranslator.JAVA_AIR_ID) {
|
||||
if (blockToPick == BlockStateValues.JAVA_AIR_ID) {
|
||||
// Check for an item frame since the client thinks that's a block when it's an entity in Java
|
||||
ItemFrameEntity entity = ItemFrameEntity.getItemFrameEntity(session, packet.getBlockPosition());
|
||||
if (entity != null) {
|
||||
@ -60,6 +61,6 @@ public class BedrockBlockPickRequestTranslator extends PacketTranslator<BlockPic
|
||||
return;
|
||||
}
|
||||
|
||||
InventoryUtils.findOrCreateItem(session, BlockTranslator.getBlockMapping(blockToPick).getPickItem());
|
||||
InventoryUtils.findOrCreateItem(session, BlockRegistries.JAVA_BLOCKS.get(blockToPick).getPickItem());
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,7 @@ import org.geysermc.connector.entity.Entity;
|
||||
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.registry.type.ItemMapping;
|
||||
import org.geysermc.connector.utils.InventoryUtils;
|
||||
|
||||
/**
|
||||
@ -107,9 +106,9 @@ public class BedrockEntityPickRequestTranslator extends PacketTranslator<EntityP
|
||||
}
|
||||
|
||||
String fullItemName = "minecraft:" + itemName;
|
||||
ItemEntry entry = ItemRegistry.getItemEntry(fullItemName);
|
||||
ItemMapping mapping = session.getItemMappings().getMapping(fullItemName);
|
||||
// Verify it is, indeed, an item
|
||||
if (entry == null) return;
|
||||
if (mapping == null) return;
|
||||
|
||||
InventoryUtils.findOrCreateItem(session, fullItemName);
|
||||
}
|
||||
|
@ -49,10 +49,11 @@ import org.geysermc.connector.inventory.GeyserItemStack;
|
||||
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.sound.EntitySoundInteractionHandler;
|
||||
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.registry.type.ItemMapping;
|
||||
import org.geysermc.connector.registry.type.ItemMappings;
|
||||
import org.geysermc.connector.utils.BlockUtils;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -74,6 +75,8 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
||||
// Send book updates before opening inventories
|
||||
session.getBookEditCache().checkForSend();
|
||||
|
||||
ItemMappings mappings = session.getItemMappings();
|
||||
|
||||
switch (packet.getTransactionType()) {
|
||||
case NORMAL:
|
||||
if (packet.getActions().size() == 2) {
|
||||
@ -123,7 +126,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
||||
}
|
||||
|
||||
// Bedrock sends block interact code for a Java entity so we send entity code back to Java
|
||||
if (session.getBlockTranslator().isItemFrame(packet.getBlockRuntimeId())) {
|
||||
if (session.getBlockMappings().isItemFrame(packet.getBlockRuntimeId())) {
|
||||
Entity itemFrameEntity = ItemFrameEntity.getItemFrameEntity(session, packet.getBlockPosition());
|
||||
if (itemFrameEntity != null) {
|
||||
int entityId = (int) itemFrameEntity.getEntityId();
|
||||
@ -183,9 +186,9 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
||||
Block place checks end - client is good to go
|
||||
*/
|
||||
|
||||
if (packet.getItemInHand() != null && ItemRegistry.SPAWN_EGGS.contains(packet.getItemInHand().getId())) {
|
||||
if (packet.getItemInHand() != null && session.getItemMappings().getSpawnEggIds().contains(packet.getItemInHand().getId())) {
|
||||
int blockState = session.getConnector().getWorldManager().getBlockAt(session, packet.getBlockPosition());
|
||||
if (blockState == BlockTranslator.JAVA_WATER_ID) {
|
||||
if (blockState == BlockStateValues.JAVA_WATER_ID) {
|
||||
// Otherwise causes multiple mobs to spawn - just send a use item packet
|
||||
// TODO when we fix mobile bucket rotation, use it for this, too
|
||||
ClientPlayerUseItemPacket itemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
|
||||
@ -204,12 +207,12 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
||||
|
||||
if (packet.getItemInHand() != null) {
|
||||
// Otherwise boats will not be able to be placed in survival and buckets won't work on mobile
|
||||
if (ItemRegistry.BOATS.contains(packet.getItemInHand().getId())) {
|
||||
if (session.getItemMappings().getBoatIds().contains(packet.getItemInHand().getId())) {
|
||||
ClientPlayerUseItemPacket itemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
|
||||
session.sendDownstreamPacket(itemPacket);
|
||||
}
|
||||
// Check actions, otherwise buckets may be activated when block inventories are accessed
|
||||
else if (ItemRegistry.BUCKETS.contains(packet.getItemInHand().getId())) {
|
||||
else if (session.getItemMappings().getBucketIds().contains(packet.getItemInHand().getId())) {
|
||||
// Let the server decide if the bucket item should change, not the client, and revert the changes the client made
|
||||
InventorySlotPacket slotPacket = new InventorySlotPacket();
|
||||
slotPacket.setContainerId(ContainerId.INVENTORY);
|
||||
@ -228,8 +231,8 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
||||
if (packet.getActions().isEmpty()) {
|
||||
if (session.getOpPermissionLevel() >= 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<Inve
|
||||
}
|
||||
}
|
||||
|
||||
ItemEntry handItem = ItemRegistry.getItem(packet.getItemInHand());
|
||||
ItemMapping handItem = mappings.getMapping(packet.getItemInHand());
|
||||
if (handItem.isBlock()) {
|
||||
session.setLastBlockPlacePosition(blockPos);
|
||||
session.setLastBlockPlacedId(handItem.getJavaIdentifier());
|
||||
@ -262,16 +265,17 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
||||
}
|
||||
|
||||
// Handled when sneaking
|
||||
if (session.getPlayerInventory().getItemInHand().getJavaId() == ItemRegistry.SHIELD.getJavaId()) {
|
||||
if (session.getPlayerInventory().getItemInHand().getJavaId() == mappings.getStoredItems().shield().getJavaId()) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Handled in ITEM_USE if the item is not milk
|
||||
if (packet.getItemInHand() != null) {
|
||||
if (ItemRegistry.BUCKETS.contains(packet.getItemInHand().getId()) &&
|
||||
packet.getItemInHand().getId() != ItemRegistry.MILK_BUCKET.getBedrockId()) {
|
||||
if (session.getItemMappings().getBucketIds().contains(packet.getItemInHand().getId()) &&
|
||||
packet.getItemInHand().getId() != session.getItemMappings().getStoredItems().milkBucket().getBedrockId()) {
|
||||
// Handled in case 0 if the item is not milk
|
||||
break;
|
||||
} else if (ItemRegistry.SPAWN_EGGS.contains(packet.getItemInHand().getId())) {
|
||||
} else if (session.getItemMappings().getSpawnEggIds().contains(packet.getItemInHand().getId())) {
|
||||
// Handled in case 0
|
||||
break;
|
||||
}
|
||||
@ -303,9 +307,9 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
||||
LevelEventPacket blockBreakPacket = new LevelEventPacket();
|
||||
blockBreakPacket.setType(LevelEventType.PARTICLE_DESTROY_BLOCK);
|
||||
blockBreakPacket.setPosition(packet.getBlockPosition().toFloat());
|
||||
blockBreakPacket.setData(session.getBlockTranslator().getBedrockBlockId(blockState));
|
||||
blockBreakPacket.setData(session.getBlockMappings().getBedrockBlockId(blockState));
|
||||
session.sendUpstreamPacket(blockBreakPacket);
|
||||
session.setBreakingBlock(BlockTranslator.JAVA_AIR_ID);
|
||||
session.setBreakingBlock(BlockStateValues.JAVA_AIR_ID);
|
||||
|
||||
Entity itemFrameEntity = ItemFrameEntity.getItemFrameEntity(session, packet.getBlockPosition());
|
||||
if (itemFrameEntity != null) {
|
||||
@ -389,14 +393,14 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
||||
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
|
||||
updateBlockPacket.setDataLayer(0);
|
||||
updateBlockPacket.setBlockPosition(blockPos);
|
||||
updateBlockPacket.setRuntimeId(session.getBlockTranslator().getBedrockBlockId(javaBlockState));
|
||||
updateBlockPacket.setRuntimeId(session.getBlockMappings().getBedrockBlockId(javaBlockState));
|
||||
updateBlockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
|
||||
session.sendUpstreamPacket(updateBlockPacket);
|
||||
|
||||
UpdateBlockPacket updateWaterPacket = new UpdateBlockPacket();
|
||||
updateWaterPacket.setDataLayer(1);
|
||||
updateWaterPacket.setBlockPosition(blockPos);
|
||||
updateWaterPacket.setRuntimeId(BlockTranslator.isWaterlogged(javaBlockState) ? session.getBlockTranslator().getBedrockWaterId() : session.getBlockTranslator().getBedrockAirId());
|
||||
updateWaterPacket.setRuntimeId(BlockRegistries.WATERLOGGED.get().contains(javaBlockState) ? session.getBlockMappings().getBedrockWaterId() : session.getBlockMappings().getBedrockAirId());
|
||||
updateWaterPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
|
||||
session.sendUpstreamPacket(updateWaterPacket);
|
||||
|
||||
|
@ -33,7 +33,6 @@ import com.nukkitx.protocol.bedrock.packet.MobEquipmentPacket;
|
||||
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;
|
||||
import org.geysermc.connector.utils.CooldownUtils;
|
||||
import org.geysermc.connector.utils.InteractiveTagManager;
|
||||
|
||||
@ -58,7 +57,7 @@ public class BedrockMobEquipmentTranslator extends PacketTranslator<MobEquipment
|
||||
ClientPlayerChangeHeldItemPacket changeHeldItemPacket = new ClientPlayerChangeHeldItemPacket(packet.getHotbarSlot());
|
||||
session.sendDownstreamPacket(changeHeldItemPacket);
|
||||
|
||||
if (session.isSneaking() && session.getPlayerInventory().getItemInHand().getJavaId() == ItemRegistry.SHIELD.getJavaId()) {
|
||||
if (session.isSneaking() && session.getPlayerInventory().getItemInHand().getJavaId() == session.getItemMappings().getStoredItems().shield().getJavaId()) {
|
||||
// Activate shield since we are already sneaking
|
||||
// (No need to send a release item packet - Java doesn't do this when swapping items)
|
||||
// Required to do it a tick later or else it doesn't register
|
||||
|
@ -43,8 +43,9 @@ import org.geysermc.connector.inventory.PlayerInventory;
|
||||
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;
|
||||
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.registry.type.ItemMapping;
|
||||
import org.geysermc.connector.utils.BlockUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -104,10 +105,11 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
||||
|
||||
// Toggle the shield, if relevant
|
||||
PlayerInventory playerInv = session.getPlayerInventory();
|
||||
if ((playerInv.getItemInHand().getJavaId() == ItemRegistry.SHIELD.getJavaId()) ||
|
||||
(playerInv.getOffhand().getJavaId() == ItemRegistry.SHIELD.getJavaId())) {
|
||||
ItemMapping shield = session.getItemMappings().getMapping("minecraft:shield");
|
||||
if ((playerInv.getItemInHand().getJavaId() == shield.getJavaId()) ||
|
||||
(playerInv.getOffhand().getJavaId() == shield.getJavaId())) {
|
||||
ClientPlayerUseItemPacket useItemPacket;
|
||||
if (playerInv.getItemInHand().getJavaId() == ItemRegistry.SHIELD.getJavaId()) {
|
||||
if (playerInv.getItemInHand().getJavaId() == shield.getJavaId()) {
|
||||
useItemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
|
||||
} else {
|
||||
// Else we just assume it's the offhand, to simplify logic and to assure the packet gets sent
|
||||
@ -167,7 +169,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
||||
LevelEventPacket startBreak = new LevelEventPacket();
|
||||
startBreak.setType(LevelEventType.BLOCK_START_BREAK);
|
||||
startBreak.setPosition(vector.toFloat());
|
||||
double breakTime = BlockUtils.getSessionBreakTime(session, BlockTranslator.getBlockMapping(blockState)) * 20;
|
||||
double breakTime = BlockUtils.getSessionBreakTime(session, BlockRegistries.JAVA_BLOCKS.get(blockState)) * 20;
|
||||
startBreak.setData((int) (65535 / breakTime));
|
||||
session.setBreakingBlock(blockState);
|
||||
session.sendUpstreamPacket(startBreak);
|
||||
@ -176,7 +178,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
||||
// Account for fire - the client likes to hit the block behind.
|
||||
Vector3i fireBlockPos = BlockUtils.getBlockPosition(packet.getBlockPosition(), packet.getFace());
|
||||
int blockUp = session.getConnector().getWorldManager().getBlockAt(session, fireBlockPos);
|
||||
String identifier = BlockTranslator.getJavaIdBlockMap().inverse().get(blockUp);
|
||||
String identifier = BlockRegistries.JAVA_IDENTIFIERS.get().inverse().get(blockUp);
|
||||
if (identifier.startsWith("minecraft:fire") || identifier.startsWith("minecraft:soul_fire")) {
|
||||
ClientPlayerActionPacket startBreakingPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, new Position(fireBlockPos.getX(),
|
||||
fireBlockPos.getY(), fireBlockPos.getZ()), BlockFace.values()[packet.getFace()]);
|
||||
@ -196,7 +198,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
||||
Vector3f vectorFloat = vector.toFloat();
|
||||
LevelEventPacket continueBreakPacket = new LevelEventPacket();
|
||||
continueBreakPacket.setType(LevelEventType.PARTICLE_CRACK_BLOCK);
|
||||
continueBreakPacket.setData((session.getBlockTranslator().getBedrockBlockId(session.getBreakingBlock())) | (packet.getFace() << 24));
|
||||
continueBreakPacket.setData((session.getBlockMappings().getBedrockBlockId(session.getBreakingBlock())) | (packet.getFace() << 24));
|
||||
continueBreakPacket.setPosition(vectorFloat);
|
||||
session.sendUpstreamPacket(continueBreakPacket);
|
||||
|
||||
@ -204,7 +206,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
||||
LevelEventPacket updateBreak = new LevelEventPacket();
|
||||
updateBreak.setType(LevelEventType.BLOCK_UPDATE_BREAK);
|
||||
updateBreak.setPosition(vectorFloat);
|
||||
double breakTime = BlockUtils.getSessionBreakTime(session, BlockTranslator.getBlockMapping(session.getBreakingBlock())) * 20;
|
||||
double breakTime = BlockUtils.getSessionBreakTime(session, BlockRegistries.JAVA_BLOCKS.get(session.getBreakingBlock())) * 20;
|
||||
updateBreak.setData((int) (65535 / breakTime));
|
||||
session.sendUpstreamPacket(updateBreak);
|
||||
break;
|
||||
@ -227,7 +229,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
||||
stopBreak.setType(LevelEventType.BLOCK_STOP_BREAK);
|
||||
stopBreak.setPosition(vector.toFloat());
|
||||
stopBreak.setData(0);
|
||||
session.setBreakingBlock(BlockTranslator.JAVA_AIR_ID);
|
||||
session.setBreakingBlock(BlockStateValues.JAVA_AIR_ID);
|
||||
session.sendUpstreamPacket(stopBreak);
|
||||
break;
|
||||
case STOP_BREAK:
|
||||
|
@ -40,7 +40,6 @@ import org.geysermc.connector.entity.living.animal.horse.AbstractHorseEntity;
|
||||
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;
|
||||
import org.geysermc.connector.utils.InteractiveTagManager;
|
||||
|
||||
@Translator(packet = InteractPacket.class)
|
||||
@ -60,7 +59,7 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
|
||||
|
||||
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(),
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<SoundEffect, Effect> SOUND_EFFECTS = new HashMap<>();
|
||||
public static final Int2ObjectMap<SoundEvent> RECORDS = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
/**
|
||||
* Java particle type to Bedrock level event
|
||||
*/
|
||||
private static final Map<ParticleType, LevelEventType> PARTICLE_TO_LEVEL_EVENT = new HashMap<>();
|
||||
/**
|
||||
* Java particle type to Bedrock namespaced string ID
|
||||
*/
|
||||
private static final Map<ParticleType, String> 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<Map.Entry<String, JsonNode>> particlesIterator = particleEntries.fields();
|
||||
try {
|
||||
while (particlesIterator.hasNext()) {
|
||||
Map.Entry<String, JsonNode> 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<Map.Entry<String, JsonNode>> effectsIterator = effects.fields();
|
||||
while (effectsIterator.hasNext()) {
|
||||
Map.Entry<String, JsonNode> 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);
|
||||
}
|
||||
}
|
@ -843,7 +843,7 @@ public abstract class InventoryTranslator {
|
||||
for (int slot : affectedSlots) {
|
||||
BedrockContainerSlot bedrockSlot = javaSlotToBedrockContainer(slot);
|
||||
List<ItemStackResponsePacket.ItemEntry> 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<ItemStackResponsePacket.ContainerEntry> 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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<String> 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<String> 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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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<ItemData> 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: {
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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<ItemData> 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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<String, ItemEntry> 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<String> JAVA_ONLY_ITEMS;
|
||||
|
||||
public static final ItemData[] CREATIVE_ITEMS;
|
||||
|
||||
public static final List<StartGamePacket.ItemEntry> ITEMS = new ArrayList<>();
|
||||
public static final Int2ObjectMap<ItemEntry> 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<ItemData> 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<List<JsonNode>> itemEntriesType = new TypeReference<List<JsonNode>>() {
|
||||
};
|
||||
|
||||
// Used to get the Bedrock namespaced ID (in instances where there are small differences)
|
||||
Int2ObjectMap<String> bedrockIdToIdentifier = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
List<String> itemNames = new ArrayList<>();
|
||||
|
||||
List<JsonNode> 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<String> bedrockBlockIdOverrides = new Object2IntOpenHashMap<>();
|
||||
Object2IntMap<String> 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<ItemData> 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<Map.Entry<String, JsonNode>> iterator = items.fields();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, JsonNode> 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<String, Integer> 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<String, Object> 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<String, Object> 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<String, Object> 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<NbtMap> 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<String> 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;
|
||||
});
|
||||
}
|
||||
}
|
@ -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<ItemEntry> appliedItems = itemStackTranslator.getAppliedItems();
|
||||
for (ItemEntry item : appliedItems) {
|
||||
List<ItemMapping> 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<ItemEntry> getAppliedItems() {
|
||||
public List<ItemMapping> 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<ItemEntry> getAppliedItems();
|
||||
public abstract List<ItemMapping> 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())));
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<String, ItemMapping> 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<String, ItemMapping> itemMappings, String cleanIdentifier) {
|
||||
ItemMapping mapping = itemMappings.get("minecraft:" + cleanIdentifier);
|
||||
if (mapping == null) {
|
||||
throw new RuntimeException("Could not find item " + cleanIdentifier);
|
||||
}
|
||||
|
||||
return mapping;
|
||||
}
|
||||
}
|
@ -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<ItemEntry> appliedItems;
|
||||
private final List<ItemMapping> 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<ItemEntry> getAppliedItems() {
|
||||
public List<ItemMapping> getAppliedItems() {
|
||||
return appliedItems;
|
||||
}
|
||||
}
|
||||
|
@ -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<ItemEntry> appliedItems;
|
||||
private final List<ItemMapping> 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<ItemEntry> getAppliedItems() {
|
||||
public List<ItemMapping> getAppliedItems() {
|
||||
return appliedItems;
|
||||
}
|
||||
}
|
||||
|
@ -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<ItemEntry> appliedItems;
|
||||
private final List<ItemMapping> 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<ItemEntry> getAppliedItems() {
|
||||
public List<ItemMapping> getAppliedItems() {
|
||||
return appliedItems;
|
||||
}
|
||||
}
|
||||
|
@ -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<ItemEntry> appliedItems;
|
||||
private final List<ItemMapping> 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<ItemEntry> getAppliedItems() {
|
||||
public List<ItemMapping> getAppliedItems() {
|
||||
return appliedItems;
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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<Tag> 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;
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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<String> 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());
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -95,6 +95,8 @@ public class JavaAdvancementsTranslator extends PacketTranslator<ServerAdvanceme
|
||||
titlePacket.setFadeOutTime(3);
|
||||
titlePacket.setFadeInTime(3);
|
||||
titlePacket.setStayTime(3);
|
||||
titlePacket.setXuid("");
|
||||
titlePacket.setPlatformOnlineId("");
|
||||
session.sendUpstreamPacket(titlePacket);
|
||||
}
|
||||
}
|
||||
|
@ -48,8 +48,7 @@ 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.Enchantment;
|
||||
import org.geysermc.connector.network.translators.item.ItemRegistry;
|
||||
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
||||
import org.geysermc.connector.registry.BlockRegistries;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -133,7 +132,7 @@ public class JavaDeclareCommandsTranslator extends PacketTranslator<ServerDeclar
|
||||
}
|
||||
|
||||
// Get and parse all params
|
||||
CommandParamData[][] params = getParams(nodes[nodeIndex], nodes);
|
||||
CommandParamData[][] params = getParams(session, nodes[nodeIndex], nodes);
|
||||
|
||||
// Insert the alias name into the command list
|
||||
commands.computeIfAbsent(params, index -> new HashSet<>()).add(node.getName().toLowerCase());
|
||||
@ -168,11 +167,12 @@ public class JavaDeclareCommandsTranslator extends PacketTranslator<ServerDeclar
|
||||
/**
|
||||
* Build the command parameter array for the given command
|
||||
*
|
||||
* @param session the session
|
||||
* @param commandNode The command to build the parameters for
|
||||
* @param allNodes Every command node
|
||||
* @return An array of parameter option arrays
|
||||
*/
|
||||
private static CommandParamData[][] getParams(CommandNode commandNode, CommandNode[] allNodes) {
|
||||
private static CommandParamData[][] getParams(GeyserSession session, CommandNode commandNode, CommandNode[] allNodes) {
|
||||
// Check if the command is an alias and redirect it
|
||||
if (commandNode.getRedirectIndex() != -1) {
|
||||
GeyserConnector.getInstance().getLogger().debug("Redirecting command " + commandNode.getName() + " to " + allNodes[commandNode.getRedirectIndex()].getName());
|
||||
@ -182,7 +182,7 @@ public class JavaDeclareCommandsTranslator extends PacketTranslator<ServerDeclar
|
||||
if (commandNode.getChildIndices().length >= 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<CommandParamData[]> treeData = rootParam.getTree();
|
||||
|
||||
@ -195,10 +195,11 @@ public class JavaDeclareCommandsTranslator extends PacketTranslator<ServerDeclar
|
||||
/**
|
||||
* Convert Java edition command types to Bedrock edition
|
||||
*
|
||||
* @param session the session
|
||||
* @param parser Command type to convert
|
||||
* @return Bedrock parameter data type
|
||||
*/
|
||||
private static Object mapCommandType(CommandParser parser) {
|
||||
private static Object mapCommandType(GeyserSession session, CommandParser parser) {
|
||||
if (parser == null) {
|
||||
return CommandParam.STRING;
|
||||
}
|
||||
@ -243,10 +244,10 @@ public class JavaDeclareCommandsTranslator extends PacketTranslator<ServerDeclar
|
||||
return CommandParam.OPERATOR;
|
||||
|
||||
case BLOCK_STATE:
|
||||
return BlockTranslator.getAllBlockIdentifiers();
|
||||
return BlockRegistries.JAVA_TO_BEDROCK_IDENTIFIERS.get().keySet().toArray(new String[0]);
|
||||
|
||||
case ITEM_STACK:
|
||||
return ItemRegistry.ITEM_NAMES;
|
||||
return session.getItemMappings().getItemNames();
|
||||
|
||||
case ITEM_ENCHANTMENT:
|
||||
return Enchantment.JavaEnchantment.ALL_JAVA_IDENTIFIERS;
|
||||
@ -287,9 +288,10 @@ public class JavaDeclareCommandsTranslator extends PacketTranslator<ServerDeclar
|
||||
/**
|
||||
* Build the array of all the child parameters (recursive)
|
||||
*
|
||||
* @param session the session
|
||||
* @param allNodes Every command node
|
||||
*/
|
||||
public void buildChildren(CommandNode[] allNodes) {
|
||||
public void buildChildren(GeyserSession session, CommandNode[] allNodes) {
|
||||
for (int paramID : paramNode.getChildIndices()) {
|
||||
CommandNode paramNode = allNodes[paramID];
|
||||
|
||||
@ -322,7 +324,7 @@ public class JavaDeclareCommandsTranslator extends PacketTranslator<ServerDeclar
|
||||
}
|
||||
} else {
|
||||
// Put the non-enum param into the list
|
||||
Object mappedType = mapCommandType(paramNode.getParser());
|
||||
Object mappedType = mapCommandType(session, paramNode.getParser());
|
||||
CommandEnumData enumData = null;
|
||||
CommandParam type = null;
|
||||
if (mappedType instanceof String[]) {
|
||||
@ -339,7 +341,7 @@ public class JavaDeclareCommandsTranslator extends PacketTranslator<ServerDeclar
|
||||
|
||||
// Recursively build all child options
|
||||
for (ParamInfo child : children) {
|
||||
child.buildChildren(allNodes);
|
||||
child.buildChildren(session, allNodes);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@ package org.geysermc.connector.network.translators.java;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||
import com.github.steveice10.mc.protocol.data.game.recipe.Ingredient;
|
||||
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.recipe.data.ShapedRecipeData;
|
||||
import com.github.steveice10.mc.protocol.data.game.recipe.data.ShapelessRecipeData;
|
||||
import com.github.steveice10.mc.protocol.data.game.recipe.data.StoneCuttingRecipeData;
|
||||
@ -42,11 +43,16 @@ import lombok.EqualsAndHashCode;
|
||||
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.*;
|
||||
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.utils.InventoryUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.geysermc.connector.utils.InventoryUtils.LAST_RECIPE_NET_ID;
|
||||
|
||||
/**
|
||||
* Used to send all valid recipes from Java to Bedrock.
|
||||
*
|
||||
@ -54,12 +60,23 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Translator(packet = ServerDeclareRecipesPacket.class)
|
||||
public class JavaDeclareRecipesTranslator extends PacketTranslator<ServerDeclareRecipesPacket> {
|
||||
/**
|
||||
* Required to use the specified cartography table recipes
|
||||
*/
|
||||
private static final List<CraftingData> 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<RecipeType, List<CraftingData>> 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<Recipe> recipeMap = new Int2ObjectOpenHashMap<>(RecipeRegistry.ALL_CRAFTING_RECIPES);
|
||||
int netId = InventoryUtils.LAST_RECIPE_NET_ID + 1;
|
||||
|
||||
Int2ObjectMap<Recipe> recipeMap = new Int2ObjectOpenHashMap<>(Registries.RECIPES.forVersion(session.getUpstream().getProtocolVersion()));
|
||||
Int2ObjectMap<List<StoneCuttingRecipeData>> unsortedStonecutterData = new Int2ObjectOpenHashMap<>();
|
||||
CraftingDataPacket craftingDataPacket = new CraftingDataPacket();
|
||||
craftingDataPacket.setCleanRecipes(true);
|
||||
@ -94,55 +111,6 @@ public class JavaDeclareRecipesTranslator extends PacketTranslator<ServerDeclare
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// These recipes are enabled by sending a special recipe
|
||||
case CRAFTING_SPECIAL_BOOKCLONING: {
|
||||
craftingDataPacket.getCraftingData().add(RecipeRegistry.BOOK_CLONING_RECIPE_DATA);
|
||||
break;
|
||||
}
|
||||
case CRAFTING_SPECIAL_REPAIRITEM: {
|
||||
craftingDataPacket.getCraftingData().add(RecipeRegistry.TOOL_REPAIRING_RECIPE_DATA);
|
||||
break;
|
||||
}
|
||||
case CRAFTING_SPECIAL_MAPCLONING: {
|
||||
craftingDataPacket.getCraftingData().add(RecipeRegistry.MAP_CLONING_RECIPE_DATA);
|
||||
break;
|
||||
}
|
||||
case CRAFTING_SPECIAL_MAPEXTENDING: {
|
||||
craftingDataPacket.getCraftingData().add(RecipeRegistry.MAP_EXTENDING_RECIPE_DATA);
|
||||
break;
|
||||
}
|
||||
case CRAFTING_SPECIAL_BANNERDUPLICATE: {
|
||||
craftingDataPacket.getCraftingData().add(RecipeRegistry.BANNER_DUPLICATING_RECIPE_DATA);
|
||||
break;
|
||||
}
|
||||
|
||||
// Java doesn't actually tell us the recipes so we need to calculate this ahead of time.
|
||||
case CRAFTING_SPECIAL_FIREWORK_ROCKET: {
|
||||
craftingDataPacket.getCraftingData().addAll(RecipeRegistry.FIREWORK_ROCKET_RECIPES);
|
||||
break;
|
||||
}
|
||||
case CRAFTING_SPECIAL_FIREWORK_STAR: {
|
||||
craftingDataPacket.getCraftingData().addAll(RecipeRegistry.FIREWORK_STAR_RECIPES);
|
||||
break;
|
||||
}
|
||||
case CRAFTING_SPECIAL_SHULKERBOXCOLORING: {
|
||||
craftingDataPacket.getCraftingData().addAll(RecipeRegistry.SHULKER_BOX_DYEING_RECIPES);
|
||||
break;
|
||||
}
|
||||
case CRAFTING_SPECIAL_SUSPICIOUSSTEW: {
|
||||
craftingDataPacket.getCraftingData().addAll(RecipeRegistry.SUSPICIOUS_STEW_RECIPES);
|
||||
break;
|
||||
}
|
||||
case CRAFTING_SPECIAL_TIPPEDARROW: {
|
||||
craftingDataPacket.getCraftingData().addAll(RecipeRegistry.TIPPED_ARROW_RECIPES);
|
||||
break;
|
||||
}
|
||||
case CRAFTING_SPECIAL_ARMORDYE: {
|
||||
// This one's even worse since it's not actually on Bedrock, but it still works!
|
||||
craftingDataPacket.getCraftingData().addAll(RecipeRegistry.LEATHER_DYEING_RECIPES);
|
||||
break;
|
||||
}
|
||||
case STONECUTTING: {
|
||||
StoneCuttingRecipeData stoneCuttingData = (StoneCuttingRecipeData) recipe.getData();
|
||||
ItemStack ingredient = stoneCuttingData.getIngredient().getOptions()[0];
|
||||
@ -153,20 +121,26 @@ public class JavaDeclareRecipesTranslator extends PacketTranslator<ServerDeclare
|
||||
}
|
||||
data.add(stoneCuttingData);
|
||||
// Save for processing after all recipes have been received
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
List<CraftingData> 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<IntList> stonecutterRecipeMap = new Int2ObjectOpenHashMap<>();
|
||||
for (Int2ObjectMap.Entry<List<StoneCuttingRecipeData>> 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<ServerDeclare
|
||||
GroupedItem groupedItem = entry.getKey();
|
||||
int idCount = 0;
|
||||
//not optimal
|
||||
for (ItemEntry itemEntry : ItemRegistry.ITEM_ENTRIES.values()) {
|
||||
if (itemEntry.getBedrockId() == groupedItem.id) {
|
||||
for (ItemMapping mapping : session.getItemMappings().getItems().values()) {
|
||||
if (mapping.getBedrockId() == groupedItem.id) {
|
||||
idCount++;
|
||||
}
|
||||
}
|
||||
@ -244,7 +218,7 @@ public class JavaDeclareRecipesTranslator extends PacketTranslator<ServerDeclare
|
||||
squashedOptions.computeIfAbsent(optionSet, k -> new IntOpenHashSet()).add(i);
|
||||
}
|
||||
int totalCombinations = 1;
|
||||
for (Set optionSet : squashedOptions.keySet()) {
|
||||
for (Set<ItemData> optionSet : squashedOptions.keySet()) {
|
||||
totalCombinations *= optionSet.size();
|
||||
}
|
||||
if (totalCombinations > 500) {
|
||||
|
@ -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<ServerEntityStatusPacket> {
|
||||
@ -98,7 +97,7 @@ public class JavaEntityStatusTranslator extends PacketTranslator<ServerEntitySta
|
||||
if (entity.getEntityType() == EntityType.THROWN_EGG) {
|
||||
LevelEventPacket particlePacket = new LevelEventPacket();
|
||||
particlePacket.setType(LevelEventType.PARTICLE_ITEM_BREAK);
|
||||
particlePacket.setData(ItemRegistry.EGG.getBedrockId() << 16);
|
||||
particlePacket.setData(session.getItemMappings().getStoredItems().egg().getBedrockId() << 16);
|
||||
particlePacket.setPosition(entity.getPosition());
|
||||
for (int i = 0; i < 6; i++) {
|
||||
session.sendUpstreamPacket(particlePacket);
|
||||
|
Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden Mehr anzeigen
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren