`CastingEnvironment#assertPosInRange` should check the center of the block instead of the corner
Closed this issue ยท 0 comments
This is the current implementation of assertPosInRange and assertPosInRangeForEditing:
vec.getX(), vec.getY(), vec.getZ() returns the lower-north-west corner of the block. This is arguably very confusing behaviour. Raycasts return the center of the block, so the most intuitive way to check if a pattern will have ambit (subtracting from your position) may fail in some edge cases.
Additionally, this has a nasty interaction with canEditBlockAt, because that method checks the center of the block:
This means that when using assertPosInRangeForEditing for certain positions on the very edge of your ambit, the assertVecInRange check succeeds but the canEditBlockAt check fails, resulting in the "forbidden to you" mishap being incorrectly thrown instead of the "out of range" mishap.
To fix this, we should just make assertPosInRange and assertPosInRangeForEditing check if Vec3.atCenterOf(vec) is in range, like canEditBlockAt already does.