Move block translations to separate class

This is to be expanded upon further at a later date
This commit is contained in:
Redned 2019-09-15 19:04:54 -05:00 committed by RednedEpic
parent 5d87b7ccab
commit ef7800a739
14 changed files with 39 additions and 36 deletions

View file

@ -79,7 +79,7 @@ public class ChunkCache {
Position blockPosition = chunkPosition.getChunkBlock(position.getX(), position.getY(), position.getZ());
if (chunk != null) {
BlockState blockState = chunk.getBlocks().get(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ());
return TranslatorsInit.getItemTranslator().getBedrockBlock(blockState);
return TranslatorsInit.getBlockTranslator().getBedrockBlock(blockState);
}
return BedrockItem.AIR;

View file

@ -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.BedrockMovePlayerTranslator;
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.InventoryTranslator;
import org.geysermc.connector.network.translators.item.ItemTranslator;
@ -117,6 +118,9 @@ public class TranslatorsInit {
@Getter
private static ItemTranslator itemTranslator;
@Getter
private static BlockTranslator blockTranslator;
@Getter
private static Map<WindowType, InventoryTranslator> inventoryTranslators = new HashMap<WindowType, InventoryTranslator>();
@ -186,6 +190,7 @@ public class TranslatorsInit {
Registry.registerBedrock(MovePlayerPacket.class, new BedrockMovePlayerTranslator());
itemTranslator = new ItemTranslator();
blockTranslator = new BlockTranslator();
registerInventoryTranslators();
}

View file

@ -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;
}
}

View file

@ -23,7 +23,7 @@
* @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 {

View file

@ -23,7 +23,7 @@
* @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;

View file

@ -23,7 +23,7 @@
* @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;

View file

@ -23,7 +23,7 @@
* @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 {

View file

@ -23,7 +23,7 @@
* @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;

View file

@ -1,10 +0,0 @@
package org.geysermc.connector.network.translators.item;
import lombok.Getter;
@Getter
public class CommonItem {
private JavaItem java;
private BedrockItem bedrock;
}

View file

@ -26,7 +26,6 @@
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.world.block.BlockState;
import com.github.steveice10.mc.protocol.data.message.Message;
import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag;
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
@ -85,7 +84,6 @@ public class ItemTranslator {
return bedrockItem;
}
public JavaItem getJavaItem(ItemData data) {
JavaItem javaItem = Remapper.ITEM_REMAPPER.convertToJava(data);
if (javaItem == null) {
@ -96,16 +94,6 @@ public class ItemTranslator {
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) {
CompoundTag javaTag = new CompoundTag(tag.getName());
Map<String, Tag> javaValue = javaTag.getValue();

View file

@ -21,7 +21,7 @@ public class JavaBlockChangeTranslator extends PacketTranslator<ServerBlockChang
record.getPosition().getY(),
record.getPosition().getZ()));
BedrockItem bedrockItem = TranslatorsInit.getItemTranslator().getBedrockBlock(record.getBlock());
BedrockItem bedrockItem = TranslatorsInit.getBlockTranslator().getBedrockBlock(record.getBlock());
updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(bedrockItem.hashCode()));
session.getUpstream().sendPacket(updateBlockPacket);

View file

@ -47,7 +47,7 @@ public class JavaMultiBlockChangeTranslator extends PacketTranslator<ServerMulti
record.getPosition().getY(),
record.getPosition().getZ()));
BedrockItem bedrockItem = TranslatorsInit.getItemTranslator().getBedrockBlock(record.getBlock());
BedrockItem bedrockItem = TranslatorsInit.getBlockTranslator().getBedrockBlock(record.getBlock());
updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(bedrockItem.hashCode()));
session.getUpstream().sendPacket(updateBlockPacket);

View file

@ -34,7 +34,7 @@ public class ChunkUtils {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; 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),
bedrockBlock.getId() << 4 | bedrockBlock.getData());

View file

@ -4,11 +4,11 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.nukkitx.protocol.bedrock.data.ItemData;
import org.geysermc.connector.network.translators.item.BedrockItem;
import org.geysermc.connector.network.translators.item.JavaItem;
import org.geysermc.connector.network.translators.item.block.ColoredBlock;
import org.geysermc.connector.network.translators.item.type.DyeColor;
import org.geysermc.connector.network.translators.item.type.StoneType;
import org.geysermc.connector.network.translators.item.block.WoodBlock;
import org.geysermc.connector.network.translators.item.type.WoodType;
import org.geysermc.connector.network.translators.block.type.ColoredBlock;
import org.geysermc.connector.network.translators.block.type.DyeColor;
import org.geysermc.connector.network.translators.block.type.StoneType;
import org.geysermc.connector.network.translators.block.type.WoodBlock;
import org.geysermc.connector.network.translators.block.type.WoodType;
import java.util.HashMap;
import java.util.Map;