I like to set a Block at the Location where the Player is “looking at”, just like if as an end-user you right clicked. How do you correctly do this, given Entity’s Location getLocation() + Vector3d getRotation() ?
I’ve found @ddos reply about using Quaternions (whatever they are) in this thread, and have peeked into BlockRay and tried that for my Turtle class here, but it doesn’t quite work, it’s always “off” and too close… help appreciated.
PS: Perhaps a method for this would be a useful addition to the API?
BlockRay is the correct thing to use.
It looks like you’re using
BlockRay.ONLY_AIR_FILTER, but I think (not certain) your need the inverse. Try
BlockRay.from(entity).filter(Predicates.not(BlockRay.ONLY_AIR_FILTER), BlockRay.maxDistanceFilter(entity.getLocation().getPosition(), 100)).end();
only leads to:
java.util.NoSuchElementException: Filter limit reached
at org.spongepowered.api.util.blockray.BlockRay.advance(BlockRay.java:300) ~[BlockRay.class:?]
at org.spongepowered.api.util.blockray.BlockRay.end(BlockRay.java:338) ~[BlockRay.class:?]
at org.spongepowered.api.util.blockray.BlockRay$BlockRayBuilder.end(BlockRay.java:623) ~[BlockRay$BlockRayBuilder.class:?]
PS: I’m on API 74446aa with SpongeVanilla 453c4a9, both from 6 weeks ago… any particular reason to think that this may have been broken then, and work better on current HEAD? (I’ll upgrade when I’m somewhere with a faster Internet.)
When the data API is implemented this should work as expected. Eye height offset is missing because of it.