3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-25 15:50:14 +01:00

Move block translations to separate class

This is to be expanded upon further at a later date
Dieser Commit ist enthalten in:
Redned 2019-09-15 19:04:54 -05:00 committet von RednedEpic
Ursprung 5d87b7ccab
Commit ef7800a739
14 geänderte Dateien mit 39 neuen und 36 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -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 {

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -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 {

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -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();

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -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());

Datei anzeigen

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