I'm trying to add in TileEntity and Entity positions to a map control I am making for MineEdit. However, I've run into a massive snag: Entity and TileEntity positions do not seem to correspond to block positions in any discernible way.
Take, for example, the following log from MineEdit during a map load:
*** Found Entities.
Loaded entity Pig @ <-35.6218825837153, -60.4388267252211, 73>
Loaded 32768 bytes from chunk C:\Users\Rob\AppData\Roaming\.minecraft\saves\World3\1p\1o\c.-3.-4.dat (biggest byte = 0x49).
Knowing that chunks are 16x16x128 (x,y,z), One would assume that the pig would be in chunk (-36/16,-60/16), or (-2,-3). However, we clearly see that the pig is, in fact, in chunk (-3,-4).
TileEntities are even worse, showing up on my map many chunks away from where they are in-game.
What is the correct way to load (tile) entities?
/// <summary>
/// Load default TileEntity properties (Must be called by inheriting classes!)
/// </summary>
/// <param name="CX">Chunk X coord</param>
/// <param name="CY">Chunk Y coord</param>
/// <param name="CS">Chunk horizontal scale</param>
/// <param name="c"></param>
public TileEntity(int CX,int CY,int CS,NbtCompound c)
{
Pos = new Vector3i(
(c["x"] as NbtInt).Value + (CX * CS),
(c["y"] as NbtInt).Value + (CY * CS),
Math.Abs((c["z"] as NbtInt).Value));
id = (c["id"] as NbtString).Value;
orig = c;
}
internal void SetBaseStuff(NbtCompound c)
{
Air = (c["Air"] as NbtShort).Value;
Fire = (c["Fire"] as NbtShort).Value;
FallDistance = (c["FallDistance"] as NbtFloat).Value;
Motion = new Vector3d(c["Motion"] as NbtList);
Pos = new Vector3d(c["Pos"] as NbtList);
Pos = new Vector3d(Pos.X, Pos.Z, Pos.Y);
Rotation = c["Rotation"];
Console.WriteLine("Loaded entity {0} @ {1}", (c["id"] as NbtString).Value, Pos);
}
You're confused on negative numbers. Here, I'll help: Blocks 0 thru 15 are in chunk 0. Blocks -16 thru -1 are in chunk -1. Blocks -32 thru -17 are in chunk -2. Blocks -48 thru -33 are in chunk -3 (this is where -36 is.)
-36/16 comes out to -3 with integer math. It shouldn't be that surprising.
You're confused on negative numbers. Here, I'll help: Blocks 0 thru 15 are in chunk 0. Blocks -16 thru -1 are in chunk -1. Blocks -32 thru -17 are in chunk -2. Blocks -48 thru -33 are in chunk -3 (this is where -36 is.)
-36/16 comes out to -3 with integer math. It shouldn't be that surprising.
No, it was my shitty rounding, and I forgot to swap Y and Z for TileEntities. Accuracy still sucks, but I'll fudge with it more.
Take, for example, the following log from MineEdit during a map load:
Knowing that chunks are 16x16x128 (x,y,z), One would assume that the pig would be in chunk (-36/16,-60/16), or (-2,-3). However, we clearly see that the pig is, in fact, in chunk (-3,-4).
TileEntities are even worse, showing up on my map many chunks away from where they are in-game.
What is the correct way to load (tile) entities?
-36, -60 is in chunk -3,-4.
It can't be -2,-3.. just think about it.
-36/16 comes out to -3 with integer math. It shouldn't be that surprising.
"We will absolutely not keep in mind what external mapeditors will have to do to read data from the disk, that makes no sense whatsoever." - Grum
No, it was my shitty rounding, and I forgot to swap Y and Z for TileEntities. Accuracy still sucks, but I'll fudge with it more.
Thanks for the help.