Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Add Position

Open Machine-Maker opened this issue 3 years ago • 2 comments

Position should be the eventual long-term replacement for lots of Location stuff. But for the moment, it shouldn't hurt to add it and start using it in new API where appropriate.

Feedback very encouraged as this interface will be used quite a bit.

Am not 💯 on the "aboveBlock, belowBlock, above, below" methods. I pretty much just took them from nms' BlockPos class, but Position isn't exactly the same since it has to account for more than just int block positions.

An alternative is to literally just have a BlockPos. I'm not sure if there are use cases for double coordinates separate from the world. Like NMS doesn't have that as a type anyways

Machine-Maker avatar Mar 20 '22 18:03 Machine-Maker

I think both the fine/block position interfaces should override a lot more methods (like both the isBlock/is fine methods and the various toX methods) just to avoid unnecessary instanceofs and new object creation?

kezz avatar Mar 21 '22 10:03 kezz

@kezz ok, I moved the isFine, isBlock methods, and the toBlock impl. but I don't see any other methods that would benefit from that? could you clarify (if there are indeed more of them)

Machine-Maker avatar Mar 21 '22 15:03 Machine-Maker

Rebased for 1.19.3 and added javadocs explaining the Experimental annotation

Machine-Maker avatar Dec 10 '22 23:12 Machine-Maker

Is it going to be immutable?! 😍

jaylawl avatar Dec 11 '22 16:12 jaylawl

It is

olijeffers0n avatar Dec 11 '22 16:12 olijeffers0n

Is it going to be immutable?! heart_eyes

Well, it's still up to implementation. While new default implementations are indeed immutable, Location now implements Position too, so x() and other getters may return different results each call.

imDaniX avatar Dec 12 '22 14:12 imDaniX

Is it going to be immutable?! heart_eyes

Well, it's still up to implementation. While new default implementations are indeed immutable, Location now implements Position too, so x() and other getters may return different results each call.

In any case this is a step in the right direction. Despite being aware of mutability of locations, vectors, and bounding boxes, "accidental mutation" that was hard to find in the code, just keeps on happening. I've always wished all those classes were immutable.

jaylawl avatar Dec 13 '22 13:12 jaylawl