Posts: 166
Threads: 14
Joined: Nov 2015
Thanks: 13
Given 14 thank(s) in 12 post(s)
Currently I'm trying to block item use, and even though it seems to work fine for preventing flint and steel use, any bucket just refuses.
No matter if I return true (preventing use) or false (allowing use) using HOOK_PLAYER_USING_ITEM, the bucket is used.
If it's a waterbucket the water is placed, if it's a lavabucket the lava is placed, if it's an empty bucket then whatever fluid was there before is now in the bucket.
Again, I can prevent flint and steel fine with this method, and Player:GetEquippedItem() does show the proper bucket when logged.
I'm not sure what's happening here, is it a bug in Cuberite?
Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
Try the OnPlayerRightClick hook instead. I do believe we should call the OnPlayerUsingItem hook when the bucket is used though.
Posts: 166
Threads: 14
Joined: Nov 2015
Thanks: 13
Given 14 thank(s) in 12 post(s)
09-10-2016, 04:38 AM
(This post was last modified: 09-10-2016, 04:54 AM by PureTryOut.)
Well it is called, that's the thing. The action is just not prevented. I'll try OnPlayerRightClick though.
EDIT: Bucket use can't be prevented using that hook either.
Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
Could you upload the code?
Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
OnPlayerRightClick (Maybe OnPlayerUsingItem as well) gets called twice. Once with a BLOCK_FACE_NONE parameter. Perhaps the LOG('test') is called from that?
Posts: 166
Threads: 14
Joined: Nov 2015
Thanks: 13
Given 14 thank(s) in 12 post(s)
Yeah I just found that out, OnPlayerUsingItem gets called twice as well. If I LOG(town) then the first time it returns fine, the second time time will be a nil value. It seems the second time BlockX and BlockY both return -1 instead of the actual block that is being changed, meaning the query won't find anything, meaning it will return false at the first conditional statement.
Why exactly is it called twice? And how would I now prevent buckets from being placed like this?
Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
It's called twice because the client sends it twice. This allows things like fishing since you don't have a block selected in the world as well. It also makes the compass tool in WorldEdit possible.