#Make Items Behave Like Vanilla / mimic vanilla item behaviour (eg stripping logs with an axe)
1 messages · Page 1 of 1 (latest)
Make Items Behave Like Vanilla / mimic vanilla item behaviour (eg stripping logs with an axe)
For that, you'd need to use a script. Here's the relevant event: https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/playerinteractwithblockafterevent?view=minecraft-bedrock-stable
You'd need to check if the certain block is the right block for the item the player is holding. If so, set the corresponding stripped or path block
Thanks! Is there a way to play the swing animation as per vanilla also?
You could probably use the /playanimation command
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)
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)
}
})
Maybe the string in tillable doesn't quite match what block.type returns. Try printing block.type with world.sendMessage
just realised i meant typeId lol, which is what I’ve been trying to use
Ah, yeah it's always little mistakes XD
nah, it wasn't that, that was just me sending you some code messed up during a test lol
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
Ah, glad you figured it out
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
Hi, so, I'm literally having this exact problem right now, I joined the server because of it lol.
How did you figure out the swing animation on right click?
There’s no swing animation, just the durability use animation which plays when durability is lost on a tool automatically. Couldn’t find a way to have a normal swing animation