if (hasTilePosition) {
Vector tilePosition = new Vector(tag.asInt("TileX"), tag.asInt("TileY"), tag.asInt("TileZ"));
Vector newTilePosition = transform.apply(tilePosition.subtract(from)).add(to);
CompoundTagBuilder builder = tag.createBuilder()
.putInt("TileX", newTilePosition.getBlockX())
.putInt("TileY", newTilePosition.getBlockY())
.putInt("TileZ", newTilePosition.getBlockZ());
if (hasDirection || hasLegacyDirection) {
int d = hasDirection ? tag.asInt("Direction") : MCDirections.fromLegacyHanging((byte) tag.asInt("Dir"));
Direction direction = MCDirections.fromHanging(d);
if (direction != null) {
Vector vector = transform.apply(direction.toVector()).subtract(transform.apply(Vector.ZERO)).normalize();
Direction newDirection = Direction.findClosest(vector, Flag.CARDINAL);
builder.putByte("Direction", (byte) MCDirections.toHanging(newDirection));
builder.putByte("Dir", MCDirections.toLegacyHanging(MCDirections.toHanging(newDirection)));
}
}
return new BaseEntity(state.getTypeId(), builder.build());
}
}
return state;
}