sponge 8.0
How can I prevent place water ?
Please help me.
sponge 8.0
How can I prevent place water ?
Please help me.
Just doubled checked your work, i found that the event is cancelled yet water still spawns
@Listener
public void delMe(InteractBlockEvent.Secondary event, @First ServerPlayer player) {
HandType hand = event.context().get(EventContextKeys.USED_HAND).get();
ItemStack stack = player.itemInHand(hand);
if (stack.type().equals(ItemTypes.WATER_BUCKET.get())) {
event.setCancelled(true);
}
}
I could cancel it with this though
@Listener
public void delMeSecond(InteractItemEvent.Secondary event, @First ServerPlayer player) {
if (event.itemStack().type().equals(ItemTypes.WATER_BUCKET.get())) {
event.setCancelled(true);
}
}
Thank you so much. but How can I check the target block in InteractItemEvent.Secondary that player has interacted ?
Could probably get it out of the context with EventContextKeys.BLOCK_HIT
Thank for you care!
not working.
e.context().get(EventContextKeys.BLOCK_HIT).orElse(null) is always null. not exists.
Ill take a look when i get a sec
If it’s ergent you could get the block the player is looking at using RayTrace
Please send me an example code to get the block the player is looking at using RayTrace
Something like
ServerPlayer player;
Optional<RayTraceResult<LocatableBlock>> opTrace = RayTrace
.block()
.continueWhileBlock(RayTrace.nonAir())
.sourceEyePosition(player)
.direction(player)
.limit(7)
.execute();
if(opTrace.isEmpty()){
//player is not looking at a block
return;
}
LocatableBlock lookingAt = opTrace.get().selectedObject();
error in this line.
.sourceEyePosition(player)
Cannot resolve method ‘sourceEyePosition’ in ‘Predicate’
Is it api 8.0 or 8.1? its in 8.0 too
Here is the javadocs for it
Just reread the docs
Its meant to be
RayTrace.block().continueWhileBlock(RayTrace.nonAir())
My bad
edit:
i have updated my code example
Thank for you care!