Closed SamB440 closed 2 years ago
I've taken a look at the code, and it seems the actual position is passed into the CraftBlock, but world is null.
However, it seems that you can directly access x/y/z from a Block using getX etc.
getLocation fails because every time you do that it is creating a new location object with the world.
Accessing the position directly works and can be used to apply the required offset:
final Block sourceBlock = part.getSourceBlock();
final int x = sourceBlock.getX();
final int y = sourceBlock.getY();
final int z = sourceBlock.getZ();
player.sendBlockChange(part.getTargetBlock().getLocation().add(x, y, z), part.getSourceBlock().getBlockData());
Closing as this fixes the issue - perhaps edge cases like this should be documented for future reference though?
Hi,
I was looking at a way to visualise the structure before pasting it within the world, and get locations after paste, but it seems like this is not possible with the current API.
I noticed entities have a
getSourceLocation
tied to them, however blocks do not, and usingpart.getTargetBlock().getLocation()
always returns the origin location specified in theat
method.Attempting to get the location from the source block results in the following error:
It would be nice if there could be a method added similar to what entities have, or to fix the target block location, or the source location (so you can then do Location#add for offset).