#Make Items Behave Like Vanilla / mimic vanilla item behaviour (eg stripping logs with an axe)

1 messages · Page 1 of 1 (latest)

sullen pawn
#

How do I mimick proper axe/shovel/hoe functionality when they interact with blocks (making paths, tilling farmland, stripping logs)?

sullen pawn
#

Make Items Behave Like Vanilla / mimic vanilla item behaviour (eg stripping logs with an axe)

ruby zodiac
sullen pawn
ruby zodiac
#

You could probably use the /playanimation command

sullen pawn
#

I thought that too, but it seems vanilla tools don’t use an animation, so idk how to replicate it (update: simply losing durability at least gives it some animation, so not too high priority)

sullen pawn
# ruby zodiac You could probably use the /playanimation command

Hey, thanks to your help I've got most of my script working, however I can't seem to get the syntax for checking the input block id correctly. If I remove the check for minecraft:dirt, the script otherwise works fine, at least. Any chance you'd be able to show me what I've been doing wrong?

const hoes = [
    'progression_reborn:copper_hoe'
]
const tillable = [
    'minecraft:dirt'
]

world.afterEvents.playerInteractWithBlock.subscribe(event => {
    const { itemStack, block, player } = event
    if (!itemStack) return;
    if (!hoes.includes(itemStack.typeId)) return;
    if (!tillable.includes(block.typeId)) return; // i think this is the line where i've been going wrong
    try {
        const unbreakingLvl = itemStack.getComponent('enchantable').getEnchantment('unbreaking')?.level ?? 0
        const breakingPercentageChance = 100 / (unbreakingLvl + 1)
        const breakingRandomChance = (Math.random() * 100)
        if (breakingPercentageChance < breakingRandomChance) return;
        itemStack.getComponent('durability').damage += 1
        player.playSound('use.gravel', { pitch: 1, location: player.location, volume: 1 })
        player.getComponent('inventory').container.setItem(player.selectedSlot, itemStack)
    } catch (error) {
        player.playSound('random.break', { pitch: 1, location: player.location, volume: 1 })
        player.getComponent('inventory').container.setItem(player.selectedSlot)
    }
})
ruby zodiac
#

Maybe the string in tillable doesn't quite match what block.type returns. Try printing block.type with world.sendMessage

sullen pawn
#

just realised i meant typeId lol, which is what I’ve been trying to use

ruby zodiac
#

Ah, yeah it's always little mistakes XD

sullen pawn
#

as it turns out it was because i'm using afterEvents

#

so a different little mistake

#

as the block was already farmland by then

#

is there a way to place a small delay before a script or part of a script runs again?

#

otherwise me holding the block may trigger twice before it updates to farmland

#

noo if i use beforeEvents then i don't have required privleges, apparently

#

and if i use after then you can infinitely lose durability

#

tf

#

is there any way to use beforeEvents without losing "required priveleges" for setItem and playSound?

#

with the current code, it will infinitely lose durability by interacting with farmland due to being after the event, and not before, yet beforeEvents has no priveleges?

#

i've tried await null; however it doesn't work anymore for some reason

#

nvm, got it, need to not register as a hoe and do the tilling manually

ruby zodiac
#

Ah, glad you figured it out

sullen pawn
#

thanks for the help. will make my scripts a public resource as always, in case anyone else wants to make tools, just so that there are complete scripts available for toolsets for those that either don't want to spend the time making it themselves or don't know how scripting works
let's forget the part where i started scripting and javascript yesterday

light granite
sullen pawn
light granite
#

I understand

#

I've been on it for a bit too

#

Thought about using the attack animation on source player when interacting with one of the blocks

#

Like when you convert grass to farmland