mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Move block translations to separate class
This is to be expanded upon further at a later date
This commit is contained in:
parent
5d87b7ccab
commit
ef7800a739
14 changed files with 39 additions and 36 deletions
|
@ -79,7 +79,7 @@ public class ChunkCache {
|
||||||
Position blockPosition = chunkPosition.getChunkBlock(position.getX(), position.getY(), position.getZ());
|
Position blockPosition = chunkPosition.getChunkBlock(position.getX(), position.getY(), position.getZ());
|
||||||
if (chunk != null) {
|
if (chunk != null) {
|
||||||
BlockState blockState = chunk.getBlocks().get(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ());
|
BlockState blockState = chunk.getBlocks().get(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ());
|
||||||
return TranslatorsInit.getItemTranslator().getBedrockBlock(blockState);
|
return TranslatorsInit.getBlockTranslator().getBedrockBlock(blockState);
|
||||||
}
|
}
|
||||||
|
|
||||||
return BedrockItem.AIR;
|
return BedrockItem.AIR;
|
||||||
|
|
|
@ -73,6 +73,7 @@ import org.geysermc.connector.network.translators.bedrock.BedrockCommandRequestT
|
||||||
import org.geysermc.connector.network.translators.bedrock.BedrockMobEquipmentTranslator;
|
import org.geysermc.connector.network.translators.bedrock.BedrockMobEquipmentTranslator;
|
||||||
import org.geysermc.connector.network.translators.bedrock.BedrockMovePlayerTranslator;
|
import org.geysermc.connector.network.translators.bedrock.BedrockMovePlayerTranslator;
|
||||||
import org.geysermc.connector.network.translators.bedrock.BedrockTextTranslator;
|
import org.geysermc.connector.network.translators.bedrock.BedrockTextTranslator;
|
||||||
|
import org.geysermc.connector.network.translators.block.BlockTranslator;
|
||||||
import org.geysermc.connector.network.translators.inventory.GenericInventoryTranslator;
|
import org.geysermc.connector.network.translators.inventory.GenericInventoryTranslator;
|
||||||
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
|
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
|
||||||
import org.geysermc.connector.network.translators.item.ItemTranslator;
|
import org.geysermc.connector.network.translators.item.ItemTranslator;
|
||||||
|
@ -117,6 +118,9 @@ public class TranslatorsInit {
|
||||||
@Getter
|
@Getter
|
||||||
private static ItemTranslator itemTranslator;
|
private static ItemTranslator itemTranslator;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private static BlockTranslator blockTranslator;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private static Map<WindowType, InventoryTranslator> inventoryTranslators = new HashMap<WindowType, InventoryTranslator>();
|
private static Map<WindowType, InventoryTranslator> inventoryTranslators = new HashMap<WindowType, InventoryTranslator>();
|
||||||
|
|
||||||
|
@ -186,6 +190,7 @@ public class TranslatorsInit {
|
||||||
Registry.registerBedrock(MovePlayerPacket.class, new BedrockMovePlayerTranslator());
|
Registry.registerBedrock(MovePlayerPacket.class, new BedrockMovePlayerTranslator());
|
||||||
|
|
||||||
itemTranslator = new ItemTranslator();
|
itemTranslator = new ItemTranslator();
|
||||||
|
blockTranslator = new BlockTranslator();
|
||||||
|
|
||||||
registerInventoryTranslators();
|
registerInventoryTranslators();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package org.geysermc.connector.network.translators.block;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
|
||||||
|
import org.geysermc.connector.network.translators.item.BedrockItem;
|
||||||
|
import org.geysermc.connector.utils.Remapper;
|
||||||
|
|
||||||
|
// Class for future expansion
|
||||||
|
public class BlockTranslator {
|
||||||
|
|
||||||
|
public BedrockItem getBedrockBlock(BlockState state) {
|
||||||
|
BedrockItem bedrockItem = Remapper.BLOCK_REMAPPER.convertToBedrockB(new ItemStack(state.getId()));
|
||||||
|
if (bedrockItem == null) {
|
||||||
|
// GeyserLogger.DEFAULT.debug("Missing mapping for java block " + state.getId());
|
||||||
|
return BedrockItem.AIR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bedrockItem;
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,7 +23,7 @@
|
||||||
* @link https://github.com/GeyserMC/Geyser
|
* @link https://github.com/GeyserMC/Geyser
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geysermc.connector.network.translators.item.block;
|
package org.geysermc.connector.network.translators.block.type;
|
||||||
|
|
||||||
public enum ColoredBlock {
|
public enum ColoredBlock {
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
* @link https://github.com/GeyserMC/Geyser
|
* @link https://github.com/GeyserMC/Geyser
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geysermc.connector.network.translators.item.type;
|
package org.geysermc.connector.network.translators.block.type;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
* @link https://github.com/GeyserMC/Geyser
|
* @link https://github.com/GeyserMC/Geyser
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geysermc.connector.network.translators.item.type;
|
package org.geysermc.connector.network.translators.block.type;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
* @link https://github.com/GeyserMC/Geyser
|
* @link https://github.com/GeyserMC/Geyser
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geysermc.connector.network.translators.item.block;
|
package org.geysermc.connector.network.translators.block.type;
|
||||||
|
|
||||||
public enum WoodBlock {
|
public enum WoodBlock {
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
* @link https://github.com/GeyserMC/Geyser
|
* @link https://github.com/GeyserMC/Geyser
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geysermc.connector.network.translators.item.type;
|
package org.geysermc.connector.network.translators.block.type;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
package org.geysermc.connector.network.translators.item;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class CommonItem {
|
|
||||||
|
|
||||||
private JavaItem java;
|
|
||||||
private BedrockItem bedrock;
|
|
||||||
}
|
|
|
@ -26,7 +26,6 @@
|
||||||
package org.geysermc.connector.network.translators.item;
|
package org.geysermc.connector.network.translators.item;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||||
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
|
|
||||||
import com.github.steveice10.mc.protocol.data.message.Message;
|
import com.github.steveice10.mc.protocol.data.message.Message;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag;
|
import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
|
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
|
||||||
|
@ -85,7 +84,6 @@ public class ItemTranslator {
|
||||||
return bedrockItem;
|
return bedrockItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public JavaItem getJavaItem(ItemData data) {
|
public JavaItem getJavaItem(ItemData data) {
|
||||||
JavaItem javaItem = Remapper.ITEM_REMAPPER.convertToJava(data);
|
JavaItem javaItem = Remapper.ITEM_REMAPPER.convertToJava(data);
|
||||||
if (javaItem == null) {
|
if (javaItem == null) {
|
||||||
|
@ -96,16 +94,6 @@ public class ItemTranslator {
|
||||||
return javaItem;
|
return javaItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BedrockItem getBedrockBlock(BlockState state) {
|
|
||||||
BedrockItem bedrockItem = Remapper.BLOCK_REMAPPER.convertToBedrockB(new ItemStack(state.getId()));
|
|
||||||
if (bedrockItem == null) {
|
|
||||||
// GeyserLogger.DEFAULT.debug("Missing mapping for java block " + state.getId());
|
|
||||||
return BedrockItem.AIR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return bedrockItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CompoundTag translateToJavaNBT(com.nukkitx.nbt.tag.CompoundTag tag) {
|
private CompoundTag translateToJavaNBT(com.nukkitx.nbt.tag.CompoundTag tag) {
|
||||||
CompoundTag javaTag = new CompoundTag(tag.getName());
|
CompoundTag javaTag = new CompoundTag(tag.getName());
|
||||||
Map<String, Tag> javaValue = javaTag.getValue();
|
Map<String, Tag> javaValue = javaTag.getValue();
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class JavaBlockChangeTranslator extends PacketTranslator<ServerBlockChang
|
||||||
record.getPosition().getY(),
|
record.getPosition().getY(),
|
||||||
record.getPosition().getZ()));
|
record.getPosition().getZ()));
|
||||||
|
|
||||||
BedrockItem bedrockItem = TranslatorsInit.getItemTranslator().getBedrockBlock(record.getBlock());
|
BedrockItem bedrockItem = TranslatorsInit.getBlockTranslator().getBedrockBlock(record.getBlock());
|
||||||
updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(bedrockItem.hashCode()));
|
updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(bedrockItem.hashCode()));
|
||||||
|
|
||||||
session.getUpstream().sendPacket(updateBlockPacket);
|
session.getUpstream().sendPacket(updateBlockPacket);
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class JavaMultiBlockChangeTranslator extends PacketTranslator<ServerMulti
|
||||||
record.getPosition().getY(),
|
record.getPosition().getY(),
|
||||||
record.getPosition().getZ()));
|
record.getPosition().getZ()));
|
||||||
|
|
||||||
BedrockItem bedrockItem = TranslatorsInit.getItemTranslator().getBedrockBlock(record.getBlock());
|
BedrockItem bedrockItem = TranslatorsInit.getBlockTranslator().getBedrockBlock(record.getBlock());
|
||||||
updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(bedrockItem.hashCode()));
|
updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(bedrockItem.hashCode()));
|
||||||
|
|
||||||
session.getUpstream().sendPacket(updateBlockPacket);
|
session.getUpstream().sendPacket(updateBlockPacket);
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class ChunkUtils {
|
||||||
for (int y = 0; y < 16; y++) {
|
for (int y = 0; y < 16; y++) {
|
||||||
for (int z = 0; z < 16; z++) {
|
for (int z = 0; z < 16; z++) {
|
||||||
BlockState block = storage.get(x, y, z);
|
BlockState block = storage.get(x, y, z);
|
||||||
BedrockItem bedrockBlock = TranslatorsInit.getItemTranslator().getBedrockBlock(block);
|
BedrockItem bedrockBlock = TranslatorsInit.getBlockTranslator().getBedrockBlock(block);
|
||||||
|
|
||||||
section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z),
|
section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z),
|
||||||
bedrockBlock.getId() << 4 | bedrockBlock.getData());
|
bedrockBlock.getId() << 4 | bedrockBlock.getData());
|
||||||
|
|
|
@ -4,11 +4,11 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||||
import com.nukkitx.protocol.bedrock.data.ItemData;
|
import com.nukkitx.protocol.bedrock.data.ItemData;
|
||||||
import org.geysermc.connector.network.translators.item.BedrockItem;
|
import org.geysermc.connector.network.translators.item.BedrockItem;
|
||||||
import org.geysermc.connector.network.translators.item.JavaItem;
|
import org.geysermc.connector.network.translators.item.JavaItem;
|
||||||
import org.geysermc.connector.network.translators.item.block.ColoredBlock;
|
import org.geysermc.connector.network.translators.block.type.ColoredBlock;
|
||||||
import org.geysermc.connector.network.translators.item.type.DyeColor;
|
import org.geysermc.connector.network.translators.block.type.DyeColor;
|
||||||
import org.geysermc.connector.network.translators.item.type.StoneType;
|
import org.geysermc.connector.network.translators.block.type.StoneType;
|
||||||
import org.geysermc.connector.network.translators.item.block.WoodBlock;
|
import org.geysermc.connector.network.translators.block.type.WoodBlock;
|
||||||
import org.geysermc.connector.network.translators.item.type.WoodType;
|
import org.geysermc.connector.network.translators.block.type.WoodType;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
Loading…
Reference in a new issue