#How to detect when a block is placed but not by a player or lava?

5 messages · Page 1 of 1 (latest)

narrow pendant
#

So I have a mod in my modpack that makes zombies bridge and build up with cobblestone but it doesn't have an option to change what block they place and I would like to do that.

So I want to detect whenever cobblestone is placed, and if it wasn't by a player or by water/lava, replace it with whatever else.

outer locustBOT
#

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

narrow pendant
#

bump

narrow pendant
#

bump

narrow pendant
#

ok it took me a really long time to figure out (about 3 hours of searching and testing) and I kinda figured it out, I wrote a script that detects when cobblestone is placed and if there is a hostile mob within 3 blocks it will replace it with a custom block

ForgeEvents.onEvent("net.minecraftforge.event.level.BlockEvent$NeighborNotifyEvent", event =>{
    global.thing(event)
})
global.thing = event => {
    let block = event.level.getBlock(event.pos)
    
    if (block.toString() == "minecraft:cobblestone") {
        let nearbyBaddie = false
        let box = AABB.of(event.pos.x - 3, event.pos.y - 3, event.pos.z - 3, event.pos.x + 3, event.pos.y + 3, event.pos.z + 3)
        let nearbyEntities = event.level.getEntitiesWithin(box)
        
        nearbyEntities.forEach(entity => {
            if (entity.isMonster()) {
                nearbyBaddie = true
            }
        })

        if (nearbyBaddie) {
            block.set("kubejs:dreadstone")
        }
    }
}