add basic displays

This commit is contained in:
Sen 2025-07-06 17:51:22 +02:00
parent 2fbdfde2ee
commit b0f33c3be1
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
40 changed files with 249 additions and 197 deletions

View file

@ -49,12 +49,8 @@ public class CommandBlock extends Command {
if(tile != null) {
TagObject te = new TagObject();
tile.writeTags(te);
tag.setString("id", te.getString("id"));
tag.setInt("x", position.getX());
tag.setInt("y", position.getY());
tag.setInt("z", position.getZ());
te.merge(tag);
TileEntity newTile = TileEntity.createAndLoadEntity(te);
TileEntity newTile = TileEntity.createAndLoadEntity(world, world.getChunk(position), position, te);
if(newTile != null) {
world.removeTileEntity(position);
world.setTileEntity(position, newTile);

View file

@ -111,7 +111,6 @@ import common.entity.item.EntityMinecart;
import common.init.BlockRegistry;
import common.init.Blocks;
import common.init.EntityRegistry;
import common.init.TileRegistry;
import common.log.Log;
import common.rng.Random;
import common.tags.TagObject;
@ -310,7 +309,7 @@ public abstract class Converter {
private static final Random RANDOM = new Random();
private static final Map<String, String> ENTITY_MAP = Maps.newHashMap();
private static final Map<String, String> TILE_MAP = Maps.newHashMap();
private static final Map<String, Class<? extends TileEntity>> TILE_MAP = Maps.newHashMap();
private static final State[] BLOCK_MAP = new State[65536];
private static final DyeColor[] COLOR_LOOKUP = new DyeColor[] {
DyeColor.WHITE, DyeColor.ORANGE, DyeColor.MAGENTA, DyeColor.LIGHT_BLUE, DyeColor.YELLOW, DyeColor.LIME, DyeColor.PINK, DyeColor.GRAY,
@ -325,9 +324,8 @@ public abstract class Converter {
}
private static void mapTile(Class<? extends TileEntity> clazz, String ... names) {
String name = TileRegistry.CLASS_TO_NAME.get(clazz);
for(String oldname : names) {
TILE_MAP.put(oldname, name);
TILE_MAP.put(oldname, clazz);
}
}
@ -1717,9 +1715,9 @@ public abstract class Converter {
return (NbtTag)read(in, (byte)10);
}
private static TagObject convertTile(NbtTag ent, String id) {
private static TagObject convertTile(NbtTag ent, Class<? extends TileEntity> clazz) {
TagObject nent = new TagObject();
if("Sign".equals(id)) {
if(clazz == TileEntitySign.class) {
String[] signText = new String[4];
for(int i = 0; i < 4; ++i) {
signText[i] = ent.getString("Text" + (i + 1));
@ -1754,7 +1752,7 @@ public abstract class Converter {
nent.setString("Text" + (i + 1), signText[i]);
}
}
else if("Comparator".equals(id)) {
else if(clazz == TileEntityComparator.class) {
nent.setInt("OutputSignal", ent.getInt("OutputSignal"));
}
return nent;
@ -1883,13 +1881,12 @@ public abstract class Converter {
entities = Lists.newArrayList();
for(NbtTag ent : ents) {
TagObject nent = new TagObject();
String mapped = TILE_MAP.get(trimColon(ent.getString("id")));
Class<? extends TileEntity> mapped = TILE_MAP.get(trimColon(ent.getString("id")));
if(mapped != null) {
nent = convertTile(ent, mapped);
nent.setString("id", mapped);
nent.setInt("x", ent.getInt("x"));
nent.setInt("y", ent.getInt("y"));
nent.setInt("z", ent.getInt("z"));
nent.setByte("x", (byte)(ent.getInt("x") & 15));
nent.setShort("y", (short)ent.getInt("y"));
nent.setByte("z", (byte)(ent.getInt("z") & 15));
entities.add(nent);
}
}

View file

@ -36,6 +36,7 @@ import common.util.NibbleArray;
import common.util.Util;
import common.world.BlockArray;
import common.world.State;
import common.world.World;
public class Region {
private static boolean makeMap(TagObject tag) {
@ -632,7 +633,13 @@ public class Region {
if(tiles != null) {
for(int n = 0; n < tiles.size(); ++n) {
TagObject tile = tiles.get(n);
TileEntity tileentity = TileEntity.createAndLoadEntity(tile);
BlockPos pos = new BlockPos(tile.getByte("x"), tile.getShort("y"), tile.getByte("z"));
if(pos.getX() < 0 || pos.getX() >= 16 || pos.getZ() < 0 || pos.getZ() >= 16 || pos.getY() < -World.MAX_SIZE_Y || pos.getY() >= World.MAX_SIZE_Y) {
Log.TICK.warn("Ignoriere Block-Objekt mit ungültigen Koordinaten %d, %d, %d in Chunk %d, %d", pos.getX(), pos.getY(), pos.getZ(), chunk.xPos, chunk.zPos);
continue;
}
pos = new BlockPos(chunk.xPos << 4 | pos.getX(), pos.getY(), chunk.zPos << 4 | pos.getZ());
TileEntity tileentity = TileEntity.createAndLoadEntity(world, chunk, pos, tile);
if(tileentity != null) {
chunk.addTileEntity(tileentity);
@ -752,6 +759,9 @@ public class Region {
for(TileEntity tileentity : chunk.getTiles().values()) {
TagObject tile = new TagObject();
tileentity.writeTags(tile);
tile.setByte("x", (byte)(tileentity.getPos().getX() & 15));
tile.setShort("y", (short)tileentity.getPos().getY());
tile.setByte("z", (byte)(tileentity.getPos().getZ() & 15));
tiles.add(tile);
}

View file

@ -2186,11 +2186,7 @@ public final class WorldServer extends AWorldServer {
if(block.getData() != null) {
this.removeTileEntity(pos);
TagObject tag = block.getData();
tag.setString("id", tag.getString("id"));
tag.setInt("x", pos.getX());
tag.setInt("y", pos.getY());
tag.setInt("z", pos.getZ());
TileEntity tileEntity = TileEntity.createAndLoadEntity(tag);
TileEntity tileEntity = TileEntity.createAndLoadEntity(this, chunk, pos, tag);
if(tileEntity != null) {
this.setTileEntity(pos, tileEntity);
}