I'm currently trying to make a system for allowing crops to be grown in certain conditions, especially biomes.
onForgeEvent('net.minecraftforge.event.world.BlockEvent$CropGrowEvent$Pre', event => {
const { x, y, z } = event.pos
const { world } = event
let level = Utils.getLevel(event.world)
let block = level.getBlock(x, y, z)
let hasTag = /kubejs:croprequire\/.*/
block.tags.forEach(tag => {
if (!hasTag.test(tag)
|| event.isCanceled()
|| !tag.contains('/')) {
event.setResult('allow'); return
}
if (hasTag.test(tag)) {
let aa = tag.split(':')[1]
let ba = aa.split('/')[1]
let ca = ba.replace('.', ':')
let cb = ca.split(':')
let cc = cb[0]
let cd = cb[1]
if (world.getBiome(BlockPos(x, y, z)).value().getRegistryName() == new ResourceLocation(cc, cd)) {
event.setResult('allow')
} else {
event.setResult('deny')
}
}
})
})
Above is my current code, in which @past basin has said here that it has some things wrong with it. I can definitely see the problems, but I don't know how I'll get started fixing them or even getting it working in the first place.