#How to detect whether crops are ripened by bone meal?

11 messages · Page 1 of 1 (latest)

oak igloo
#

I try to let the crop rot when ripe for a period of time after not harvesting
Now I have a problem, CropGrowEvent does not seem to include bone meal ripening
So I want to know if there are any event where crops are bone meal ripening?
here my script

const $CropBlock = Java.loadClass("net.minecraft.world.level.block.CropBlock")
const $CocoaBlock = Java.loadClass("net.minecraft.world.level.block.CocoaBlock")
const $BerryBlock = Java.loadClass("net.minecraft.world.level.block.SweetBerryBushBlock")

global.CropGrowEvent = (event) => {
    const { level, pos } = event
    const block = level.getBlock(pos)

    if (
        (block.hasTag("minecraft:crops") && event.getState().getValue($CropBlock.AGE) == $CropBlock.MAX_AGE) ||
        (block.id == "minecraft:cocoa" && event.getState().getValue($CocoaBlock.AGE) == $CocoaBlock.MAX_AGE) ||
        (block.id == "minecraft:sweet_berry_bush" && event.getState().getValue($BerryBlock.AGE) == $BerryBlock.MAX_AGE)
    ) {
        level.server.scheduleInTicks(100, () => {
            block.set("air")
        })
    }
}

ForgeEvents.onEvent("net.minecraftforge.event.level.BlockEvent$CropGrowEvent$Post", global.CropGrowEvent)
wintry prismBOT
#

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

oak igloo
#

just use BonemealEvent

/** @param {Internal.BonemealEvent} event */
global.BonemealEvent = (event) => {
    const { block } = event
    if (block.getValue($CropBlock.AGE) == $CropBlock.MAX_AGE) {
        event.entity.tell("1")
    }
}
ForgeEvents.onEvent("net.minecraftforge.event.entity.player.BonemealEvent", global.BonemealEvent)
oak igloo
#

This can only detect bone meal use after the crop is ripe

#

I really can't find a good way, hmmm....

tiny sparrow
#

try setting block to e.level.getBlock(e.pos)? the block you are getting from event should be the block before any processing, at least i think based on the doc.

#

or even test if max_age -1 is the value, as rn you are testing if bonemeal is used on a fully grown crop, as i said before the bonemeal event returns the block as it is before any processing of age is involved. "This event is called when a player attempts to use Bonemeal on a block. It can be canceled to completely prevent any further processing"

oak igloo
#

Thanks
I still don't have a good idea
so I'll set bone-meal ripening crops won't rot