#3x3 Tool Template

1 messages · Page 1 of 1 (latest)

outer vessel
#

As the name implies, this template shows how you can easily make a 3x3 tool!

Features:

  • silktouch support;
  • fortune support;
  • unbreaking support;
  • deal durability damage based on amount of broken blocks;
  • blacklist blocks;
  • creative supported (tool doesn't take durability damage if player is in creative mode);
  • added comments to help you understand the code better;
  • highly customizable;
  • item custom component;
half junco
#

@outer vessel it supports deny?

outer vessel
#

?

stone hatch
trim crow
# stone hatch just put it on blacklist

He means the deny block, you don't know how it works? Is a block that don't allows anyone to break every blocks that are upwards it, from its "y" coords to the sky unless there are an allow block between its "y" coords and the sky

#

(in survival)

outer vessel
#

I see

stone hatch
woeful pulsar
outer vessel
#

Well, you could create another set array and list blocks which shouldn't trigger the 3x3 ability
ex.

const ignoreBlocks = new Set([
"minecraft:torch", "minecraft:soul_torch"
)];

Then just return early if the block object matches with the ignoreBlocks typeId

 if (ignoreBlocks.has(block.typeId)) return;
//then you can continue with the rest of the code
let blockCount = 0;
...
woeful pulsar
#
world.beforeEvents.worldInitialize.subscribe(({ itemComponentRegistry }) => {
    itemComponentRegistry.registerCustomComponent(
        "mts:3x3", {
        onMineBlock({ itemStack, source, block }) {
            if (ignoreBlocks.has(block.typeId)) return;
            let blockCount = 0;
            for (let dx = -1; dx <= 1; dx++) {
                for (let dy = -1; dy <= 1; dy++) {
                    for (let dz = -1; dz <= 1; dz++) {
                        if (dx === 0 && dy === 0 && dz === 0) continue; 

                        const neighbor = block.offset({ x: dx, y: dy, z: dz });
                        if (unbreakableBlocks.has(neighbor.typeId)) continue;
                        blockCount = blockCount + 1;
                        source.runCommand(`execute as @s run loot spawn ${neighbor.location.x} ${neighbor.location.y} ${neighbor.location.z} mine ${neighbor.location.x} ${neighbor.location.y} ${neighbor.location.z} mainhand`);
                        neighbor.setType('air');
                    }
                }
            }
            damageItem(itemStack, source, blockCount); 
        }
    });
});
outer vessel
#

So the issue seems to be that it tests the block after it was broken, which results in the broken block always being air

woeful pulsar
outer vessel
#

I don't think that's possible, but you could use PlayerBreakBlockBeforeEvent

half junco
#

@outer vessel dont work anymore

glacial dew
#

what's the error

#

/problem

half junco
glacial dew
#

change it to worldLoad

half junco
half junco
glacial dew
#

which error

half junco
#

im using "@minecraft/server", "version": "1.18.0"

glacial dew
#

ah wait

#

does that even exist?

#

I though latest was 1.19.0

half junco
#

pretty sure

glacial dew
#

right?

half junco
#

yh

half junco
#

but another error

glacial dew
#

it was removed in 1.19.0

glacial dew
half junco
#

Or even tomorrow

glacial dew
#

whenever

#

you want

half junco
trim crow
#

For beta-2.0.0: system.afterEvents.startup

#
import { system } from '@minecraft/server';

system.beforeEvents.startup.subscribe(ev =>{

});
#

Also worldInitialize stills working on API 1.18.0

stone hatch
#

@outer vessel (so sorry to ping you) can I use your damage tool function on this template for my addon?? Just asking to be sure.

mortal socket
#

Is this something i can learn from to make my own 3x3 tool?