#how to replace an item with another specific item?

1 messages · Page 1 of 1 (latest)

desert hare
#

For example, I want to replace an oak sapling with a diamond in any of the player's slots, and everytime it detects an oak sapling, it replaces it with a diamond.

leaden jackal
#

You can clear it and /give

desert hare
# leaden jackal You can clear it and /give

I found this /replaceitem command and I should now only select the mainhand slot to improve performance so it should only be replaced when equipped on the mainhand slot and run it in a function file every tick but I don't know the syntax nor the item data for all the saplings

#

It should only replace that specific item and only when equipped on the mainhand

arctic wasp
#

Try something like this:

[main.mcfunction]
execute as @a[hasitem={item=minecraft:stick}] run function replace_stick

[replace_stick.mcfunction]

replaceitem entity @s[hasitem={item=stick,location=slot.inventory,slot=0}] slot.inventory 0 apple
replaceitem entity @s[hasitem={item=stick,location=slot.inventory,slot=1}] slot.inventory 1 apple

This would only work with non-stackable items though, I would recommend using scripting instead of commands.

leaden jackal
desert hare
#

I'll give it a try

arctic wasp
#

Yeah, probably. It depends how much the slot that its placed in matters. But clear would be more accurate. You could also use a binary based system to speed it up

desert hare
leaden jackal
desert hare
#

How about the item data though? Saplings to be exact

desert hare
#

I managed to make it work using this

#

I ran this on the tick.json
execute as @a[hasitem={item=minecraft:emerald, location=slot.weapon.mainhand}] run function replace_item

and then run this everytime that command returns true:
replaceitem entity @a slot.weapon.mainhand 0 destroy diamond 1 0

desert hare
#

It removes the item that is to be replaced from the inventory

desert hare
leaden jackal
#

oh wait nvm

#

whats this for?

desert hare
#

Replacing an item with another item base on count

leaden jackal
#

i mean like as a whole since i feel like theres a better solution

desert hare
#

Oh, I want to replace the oak sapling item with a custom oak sapling item since the sapling block is hardcoded and the tree that grows from the original block doesn't have leaves because I have modified the feature file for it for my apocalyptic landscape. I also can't make a custom oak tree feature because /placefeature doesn't work and I want that custom feature to grow with my custom oak sapling block

#

So when a player finds an oak sapling item, it will be replaced with the custom oak tree item the moment they equip it on their main hand

desert hare
#

I think this is the more efficient way rather than using server animation and animation controllers

leaden jackal
desert hare
#

Yeah but they won't decay

leaden jackal