Painting positioning #2088
-
I've written a modified // ...
public class Entities {
public static void handle(NBTCompound data, Instance world){
switch (data.getString("id")) {
// ...
case "minecraft:painting":
initPainting(data, world);
break;
default:
break;
}
}
// ...
private static Vec vecFromList(NBTList<NBTDouble> list){
return new Vec(list.get(0).getValue(),list.get(1).getValue(),list.get(2).getValue());
}
private static net.minestom.server.entity.metadata.other.PaintingMeta.Orientation paintingOrientation(NBTCompound data){
int num = data.getByte("facing");
net.minestom.server.entity.metadata.other.PaintingMeta.Orientation[] list = {net.minestom.server.entity.metadata.other.PaintingMeta.Orientation.SOUTH, net.minestom.server.entity.metadata.other.PaintingMeta.Orientation.WEST, net.minestom.server.entity.metadata.other.PaintingMeta.Orientation.NORTH, net.minestom.server.entity.metadata.other.PaintingMeta.Orientation.EAST};
return list[num];
}
private static Variant paintingVariant(NBTCompound data){
String name = data.getString("variant");
return Variant.fromNamespaceId(name);
}
private static void initPainting(NBTCompound data, Instance world){
NBTList<NBTFloat> rot = data.getList("Rotation");
Pos pos;
Entity painting = new Entity(EntityType.PAINTING);
PaintingMeta pmeta = (PaintingMeta) painting.getEntityMeta();
var orientation = paintingOrientation(data);
pmeta.setOrientation(orientation);
var variant = paintingVariant(data);
pos = new Pos(vecFromList(data.getList("Pos")), rot.get(0).getValue(), rot.get(1).getValue());
pmeta.setVariant(variant);
painting.setInstance(world, pos);
}
// ...
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
After scouring GitHub (turns out almost nobody uses paintings) I found the answer - it did turn out to be quite simple private static void initPainting(NBTCompound data, Instance world){
Entity painting = new Entity(EntityType.PAINTING);
NBTList<NBTDouble> pos = data.getList("Pos");
PaintingMeta pmeta = (PaintingMeta) painting.getEntityMeta();
net.minestom.server.entity.metadata.other.PaintingMeta.Orientation o = paintingOrientation(data);
pmeta.setOrientation(o);
pmeta.setVariant(paintingVariant(data));
boolean ceilZ = false;
if(o == net.minestom.server.entity.metadata.other.PaintingMeta.Orientation.WEST || o == net.minestom.server.entity.metadata.other.PaintingMeta.Orientation.EAST) ceilZ = true;
painting.setInstance(world, new Pos(pos.get(0).getValue(), Math.ceil(pos.get(1).getValue()) - 1, ceilZ?(Math.ceil(pos.get(2).getValue()) + 1):(pos.get(2).getValue())));
} |
Beta Was this translation helpful? Give feedback.
-
It turns out, my previous answer was entirely wrong (I only tested thoroughly with paintings facing a certain direction). It's as simple as this: in Minestom a painting's position is stored as the bottom left corner, and in Minecraft it is stored as the center. So, this is what worked for me (also updated to 1.20.6): private static void initPainting(CompoundBinaryTag data, Instance world){
Entity painting = new Entity(EntityType.PAINTING);
Vec pos = vecFromDoubles(data.getList("Pos"));
ListBinaryTag rot = data.getList("Rotation");
PaintingMeta meta = (PaintingMeta) painting.getEntityMeta();
net.minestom.server.entity.metadata.other.PaintingMeta.Orientation orientation = paintingOrientation(data);
meta.setOrientation(orientation);
Variant variant = Variant.fromNamespaceId(data.getString("variant"));
meta.setVariant(variant);
if(orientation == net.minestom.server.entity.metadata.other.PaintingMeta.Orientation.WEST || orientation == net.minestom.server.entity.metadata.other.PaintingMeta.Orientation.EAST){
pos = pos.withZ(pos.z() + (variant.width()/32)*(orientation == net.minestom.server.entity.metadata.other.PaintingMeta.Orientation.WEST ? -1 : 0));
} else {
pos = pos.withX(pos.x() + (variant.width()/32)*(orientation == net.minestom.server.entity.metadata.other.PaintingMeta.Orientation.SOUTH ? -1 : 0));
}
pos = pos.withY(pos.y() - variant.height()/32);
painting.setInstance(world, new Pos(pos, rot.getFloat(0), rot.getFloat(1)));
} |
Beta Was this translation helpful? Give feedback.
It turns out, my previous answer was entirely wrong (I only tested thoroughly with paintings facing a certain direction). It's as simple as this: in Minestom a painting's position is stored as the bottom left corner, and in Minecraft it is stored as the center. So, this is what worked for me (also updated to 1.20.6):