// Replace grass blocks when they receive a random tick
BlockEvents.randomTick("minecraft:grass_block", (event) => {
event.block.set("biomesoplenty:dried_salt")
})``` is what I'm getting results from, but obviously it's quite... intensive. I'd like to just do a straight 1 to 1 swap, so if the world was supposed to spawn grass, it spawns dried salt instead. Preferably only if it can see-sky (like radiation burned off all living vegetation not protected by a roof) any suggestions? This is a Server script, but I think preferably I want a startup script?
#Help save me from myself - block replacement on worldgen
4 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
I've expanded this out to only run 5% of the time, and then it checks if there is nearby water and doesn't convert, and deals with popping grasses above so that it doesn't cause huge spam, and only runs during the hottest time of the day. Any suggestions?
BlockEvents.randomTick("minecraft:grass_block", (event) => {
// only run 5% of the time
if (Math.random() >= 0.05) {
return;
}
let centerPos = event.block.pos;
let level = event.level;
// Only run during the hottest part of the day (12000-14000 ticks, roughly 12-2 PM)
//
let dayTime = level.getDayTime() % 24000;
if (dayTime < 4000 || dayTime > 8000) {
return; // Exit if not during the hottest part of the day
}
// Check if the center grass block can see sky
let centerSeeSkyPos = centerPos.offset(0, 1, 0);
if (!level.canSeeSky(centerSeeSkyPos)) {
return; // Exit if the center block cannot see sky
}
// Check for water nearby (within 3 block radius)
let waterCheckRadius = 3;
for (let x = -waterCheckRadius; x <= waterCheckRadius; x++) {
for (let y = -2; y <= 2; y++) { // Check a bit above and below
for (let z = -waterCheckRadius; z <= waterCheckRadius; z++) {
let checkPos = centerPos.offset(x, y, z);
let checkBlock = level.getBlock(checkPos);
let blockId = checkBlock.getId().toString();
// Check for water blocks
if (blockId === "minecraft:water" ||
blockId === "minecraft:flowing_water" ||
checkBlock.hasTag("c:water")) {
return; // Exit if water is found nearby
}
}
}
}
let targetBlock = level.getBlock(centerPos);
// Check if the target block is grass or has grass tag AND can see sky
if ((targetBlock.getId().toString() === "minecraft:grass_block" ||
targetBlock.hasTag("minecraft:grass"))) {
// omitting code that checks for flowers/etc for brevity
// Now change the grass block to the replacement block
let replacementBlock = "biomesoplenty:dried_salt";
level.getBlock(centerPos).set(replacementBlock);
}
});```