I'm trying to create a script to change how bonemeal works on grass blocks, so I can modify which blocks are placed by it based on the biome it's used in. I'm not at the biome-checking point yet, but rather, at the beginning.
Surprisingly, the following code loads with "no errors", but obviously it doesn't work, or else I wouldn't be posting to support.
let grass_blocks = ["minecraft:grass_block","botania:dry_grass","botania:golden_grass","botania:vivid_grass","botania:scorched_grass","botania:infused_grass","botania:mutated_grass","naturesaura:nether_grass","byg:lush_grass_block","byg:lush_grass_path","minecraft:crimson_nylium","minecraft:warped_nylium","byg:wailing_nylium","byg:sythian_nylium","byg:embur_nylium"]
for (let i = 0; i <grass_blocks.length;i++) {
if(event.block.id == grass_blocks[i] && event.item.id == "minecraft:bone_meal") {
event.cancel()
let attempts = 24
for (let j = 0; j < attempts; j++) {
let positional_attempts = 16
let temppos = event.block.pos
let airpos = temppos
for (let k = 0; k < positional_attempts;k++){
temppos.x += Math.floor(Math.random()*3)-1
temppos.z += Math.floor(Math.random()*3)-1
let ychoices = [-1,0,0,0,0,1]
temppos.y += ychoices[Math.floor(Math.random()*6)]
airpos = temppos
airpos.y += 1
if (temppos.block == grass_blocks[i] && airpos.block == "minecraft:air") break
}
if (temppos.block == grass_blocks[i] && airpos.block == "minecraft:air") {
//put block placement code here
console.log(temppos)
}
}
}
}
})```
I'm pretty sure temppos.block and airpos.block are incorrect, but how would I actually get the block at the positions of temppos and airpos?