#Disable Planting of some Crops

24 messages · Page 1 of 1 (latest)

stone tinsel
#

I want to prevent some crops from being placed on the farmland. The code below does this, but the crop appears on the farmland for a moment and then disappears immediately. The problem is that after that the crop does not drop on the ground. This means that someone in survival mode will completely lose their items while trying to put them in farmland. How can I make the item I tried to put in Farmland (and failed) drop on the ground after the process?

BlockEvents.rightClicked( event => {
    if ((event.item.id == 'minecraft:potato' || event.item.id == 'minecraft:potato') && event.block.id == 'minecraft:farmland') event.cancel()
})```
leaden ploverBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

surreal ruin
#

Are you sure they don't get the items? They probably do and it's just a visual vug

#

*bug

#

I can't remember if there is a way to fix that slight server-client desync where it flashes briefly, I very much doubt it tbh

#

If someone more experienced comes along and corrects me that's fine

#

But I'm pretty sure that code should work

#

Though it's not the best way to do it

#

Iirc you can filter the actual right Clicked event rather than having an if statement

#

You could then make that a helper function

#

And do something like blockCrop("minecraft:potato")

stone tinsel
#

It was really a visual bug. It is fixed when I looked at another gui

surreal ruin
#

Yup... just a server client desync

#

Not much you can do about that

stone tinsel
surreal ruin
#

ItemEvents.rightClicked

#

You pass in the item name as a parameter before event =>

#
ItemEvents.rightClicked("minecraft:potato", event => {
  if (event.block.id == "minecraft:farmland") event.cancel()
})```
#

iirc, might have messed something up as I'm typing on mobile

stark temple
#

you can fix this by putting the same script into client_scripts

#

just be careful not to do any inventory manipulation there, or other things that will cause a desync. as a rule of thumb client is for displaying things ad server is for doing things

stone tinsel
#

It works perfectly now

#

thank you so much