mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Start work on block entities (More commits will follow)
This commit is contained in:
parent
68b9f66e88
commit
fda98a7ead
2 changed files with 124 additions and 0 deletions
|
|
@ -0,0 +1,79 @@
|
||||||
|
package org.geysermc.connector.utils;
|
||||||
|
|
||||||
|
import com.nukkitx.nbt.tag.CompoundTag;
|
||||||
|
import com.nukkitx.nbt.tag.Tag;
|
||||||
|
|
||||||
|
public class BlockEntityUtils {
|
||||||
|
public static final String CHEST = "Chest";
|
||||||
|
public static final String ENDER_CHEST = "EnderChest";
|
||||||
|
public static final String FURNACE = "Furnace";
|
||||||
|
public static final String SIGN = "Sign";
|
||||||
|
public static final String MOB_SPAWNER = "MobSpawner";
|
||||||
|
public static final String ENCHANT_TABLE = "EnchantTable";
|
||||||
|
public static final String SKULL = "Skull";
|
||||||
|
public static final String FLOWER_POT = "FlowerPot";
|
||||||
|
public static final String BREWING_STAND = "BrewingStand";
|
||||||
|
public static final String DAYLIGHT_DETECTOR = "DaylightDetector";
|
||||||
|
public static final String MUSIC = "Music";
|
||||||
|
public static final String CAULDRON = "Cauldron";
|
||||||
|
public static final String BEACON = "Beacon";
|
||||||
|
public static final String PISTON_ARM = "PistonArm";
|
||||||
|
public static final String COMPARATOR = "Comparator";
|
||||||
|
public static final String HOPPER = "Hopper";
|
||||||
|
public static final String BED = "Bed";
|
||||||
|
public static final String JUKEBOX = "Jukebox";
|
||||||
|
public static final String SHULKER_BOX = "ShulkerBox";
|
||||||
|
public static final String BANNER = "Banner";
|
||||||
|
|
||||||
|
public static final String MINECRAFT = "minecraft:";
|
||||||
|
|
||||||
|
public static String getBedrockID(String java) {
|
||||||
|
java = java.replace(MINECRAFT, "");
|
||||||
|
|
||||||
|
if(java.equalsIgnoreCase("chest"))
|
||||||
|
return CHEST;
|
||||||
|
if(java.equalsIgnoreCase("ender_chest"))
|
||||||
|
return ENDER_CHEST;
|
||||||
|
if(java.equalsIgnoreCase("furnace"))
|
||||||
|
return FURNACE;
|
||||||
|
//Signs are special
|
||||||
|
if(java.contains("sign"))
|
||||||
|
return SIGN;
|
||||||
|
if(java.equalsIgnoreCase("mob_spawner"))
|
||||||
|
return MOB_SPAWNER;
|
||||||
|
if(java.equalsIgnoreCase("enchanting_table"))
|
||||||
|
return ENCHANT_TABLE;
|
||||||
|
if(java.equalsIgnoreCase("skull"))
|
||||||
|
return SKULL;
|
||||||
|
if(java.equalsIgnoreCase("flower_pot"))
|
||||||
|
return FLOWER_POT;
|
||||||
|
if(java.equalsIgnoreCase("brewing_stand"))
|
||||||
|
return BREWING_STAND;
|
||||||
|
if(java.equalsIgnoreCase("daylight_detector"))
|
||||||
|
return DAYLIGHT_DETECTOR;
|
||||||
|
if(java.equalsIgnoreCase("note_block"))
|
||||||
|
return MUSIC;
|
||||||
|
if(java.equalsIgnoreCase("cauldron"))
|
||||||
|
return CAULDRON;
|
||||||
|
if(java.equalsIgnoreCase("beacon"))
|
||||||
|
return BEACON;
|
||||||
|
if(java.equalsIgnoreCase("piston_head"))
|
||||||
|
return PISTON_ARM;
|
||||||
|
if(java.equalsIgnoreCase("comparator"))
|
||||||
|
return COMPARATOR;
|
||||||
|
if(java.equalsIgnoreCase("hopper"))
|
||||||
|
return HOPPER;
|
||||||
|
if(java.equalsIgnoreCase("bed"))
|
||||||
|
return BED;
|
||||||
|
if(java.equalsIgnoreCase("jukebox"))
|
||||||
|
return JUKEBOX;
|
||||||
|
if(java.equalsIgnoreCase("shulker_box"))
|
||||||
|
return SHULKER_BOX;
|
||||||
|
if(java.equalsIgnoreCase("banner"))
|
||||||
|
return BANNER;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//public static Tag<?> getExtraData(CompoundTag tag)
|
||||||
|
}
|
||||||
|
|
@ -3,10 +3,20 @@ package org.geysermc.connector.utils;
|
||||||
import com.github.steveice10.mc.protocol.data.game.chunk.Chunk;
|
import com.github.steveice10.mc.protocol.data.game.chunk.Chunk;
|
||||||
import com.github.steveice10.mc.protocol.data.game.chunk.Column;
|
import com.github.steveice10.mc.protocol.data.game.chunk.Column;
|
||||||
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
|
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import com.nukkitx.nbt.NbtUtils;
|
||||||
|
import com.nukkitx.nbt.stream.NBTOutputStream;
|
||||||
|
import com.nukkitx.nbt.tag.IntTag;
|
||||||
|
import com.nukkitx.nbt.tag.StringTag;
|
||||||
|
import com.nukkitx.nbt.tag.Tag;
|
||||||
import org.geysermc.connector.network.translators.TranslatorsInit;
|
import org.geysermc.connector.network.translators.TranslatorsInit;
|
||||||
import org.geysermc.connector.network.translators.block.BlockEntry;
|
import org.geysermc.connector.network.translators.block.BlockEntry;
|
||||||
import org.geysermc.connector.world.chunk.ChunkSection;
|
import org.geysermc.connector.world.chunk.ChunkSection;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class ChunkUtils {
|
public class ChunkUtils {
|
||||||
|
|
||||||
public static ChunkData translateToBedrock(Column column) {
|
public static ChunkData translateToBedrock(Column column) {
|
||||||
|
|
@ -16,6 +26,41 @@ public class ChunkUtils {
|
||||||
int chunkSectionCount = chunks.length;
|
int chunkSectionCount = chunks.length;
|
||||||
chunkData.sections = new ChunkSection[chunkSectionCount];
|
chunkData.sections = new ChunkSection[chunkSectionCount];
|
||||||
|
|
||||||
|
|
||||||
|
for(CompoundTag tag : column.getTileEntities()) {
|
||||||
|
System.out.println(tag.get("id").getValue());
|
||||||
|
}
|
||||||
|
//Start work on block entities
|
||||||
|
try {
|
||||||
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
|
NBTOutputStream nbtStream = NbtUtils.createNetworkWriter(stream);
|
||||||
|
|
||||||
|
for (CompoundTag tag : column.getTileEntities()) {
|
||||||
|
Map<String, Tag<?>> map = new HashMap<>();
|
||||||
|
|
||||||
|
int x = ((Number) tag.getValue().get("x").getValue()).intValue();
|
||||||
|
int y = ((Number) tag.getValue().get("y").getValue()).intValue();
|
||||||
|
int z = ((Number) tag.getValue().get("z").getValue()).intValue();
|
||||||
|
|
||||||
|
String id = BlockEntityUtils.getBedrockID((String) tag.get("id").getValue());
|
||||||
|
|
||||||
|
System.out.println(id);
|
||||||
|
|
||||||
|
map.put("x", new IntTag("x", x));
|
||||||
|
map.put("y", new IntTag("y", y));
|
||||||
|
map.put("z", new IntTag("z", z));
|
||||||
|
|
||||||
|
map.put("id", new StringTag("id", id));
|
||||||
|
|
||||||
|
nbtStream.write(new com.nukkitx.nbt.tag.CompoundTag("", map));
|
||||||
|
}
|
||||||
|
|
||||||
|
chunkData.blockEntities = stream.toByteArray();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
for (int chunkY = 0; chunkY < chunkSectionCount; chunkY++) {
|
for (int chunkY = 0; chunkY < chunkSectionCount; chunkY++) {
|
||||||
chunkData.sections[chunkY] = new ChunkSection();
|
chunkData.sections[chunkY] = new ChunkSection();
|
||||||
Chunk chunk = chunks[chunkY];
|
Chunk chunk = chunks[chunkY];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue