I'm making a parkour map and my construction site fence is made out of iron bars and I want to make a pickaxe which the player could use inside the construction site but couldn't break the fence. I want to make an obstacle inside the construction site out of iron bars which could be broken with an iron pickaxe that can break iron bars inside the construction site, but not outside of it.
-
As I understand from no responses, it's impossible to make that kind of pickaxe.– KarolisCommented Feb 8, 2021 at 12:57
-
it takes more than 2 hours to get a good reply usually– TopcodeCommented Feb 8, 2021 at 13:38
-
Could we please get a bit more information on what you wish to accomplish? For example, the size of the obstacle, the size of the fence, does the player have to place any blocks? And how familiar are you with commands?– User 12692182Commented Feb 8, 2021 at 15:10
-
1I'm making this map for singleplayer, the obstacle is just a 5x4 iron bars wall and the construction size is about 75x125, the player doesn't have to place any blocks he just needs to break the obstacle, but not the construction site's fence. I know commands quite a bit but not that good at it.– KarolisCommented Feb 8, 2021 at 18:07
-
1I counted the exact size of the construction size: 78x108.– KarolisCommented Feb 9, 2021 at 10:44
1 Answer
This can be done with 2 repeating command blocks. First command gives the closest player the item:
give @p minecraft:iron_pickaxe{CanDestroy:["iron_bars"],tag:1}
The first command executes only if a player is inside the area in which the pickaxe should work, that's what is determined in the x=... y=... z=... as well as dx=... dy=... dz=...
x y z is the cords and dx dy dz is the size (x=10 and dx=2 would put the starting x at 10 and the end at 12). This is the area in which the obstacle is in, don't make it too small so the player needs to hug the iron bars to destroy them, but not too big so they can reach unwanted iron bars.
The command replaces the player's held item only if the item is a pickaxe and has the tag tag:1
. The tag is necessary so the command doesn't continuously give the player a new pickaxe. Then the command /replaceitem
replaces the held item with a pickaxe that can break iron bars.
This command needs to be in a repeating command block:
execute if entity @a[x=-12,y=56,z=8,dx=-7,dy=1,dz=-2] as @a[nbt={SelectedItem:
{id:"minecraft:iron_pickaxe",tag:{tag:1}}}] if entity @s
run replaceitem entity @s weapon.mainhand iron_pickaxe{CanDestroy:["iron_bars"]}
The next command basically does everything opposite of the first command. It only runs for players that aren't in the specified area (make sure you enter the same x y z and dx dy dz in both commands), it then tests for a held pickaxe that can break iron bars and lastly runs the command /replaceitem
and gives the player a normal pickaxe with the tag tag:1
.
This one does need to be in a repeating command block as well:
execute unless entity @a[x=-12,y=56,z=8,dx=-7,dy=1,dz=-2]
as @a[nbt={SelectedItem:{id:"minecraft:iron_pickaxe",tag:
{CanDestroy:["iron_bars"]}}}] if entity @s run replaceitem
entity @s weapon.mainhand iron_pickaxe{tag:1}
The commands don't affect a player that doesn't have the special pickaxe, so you can create different ones later on with different tags.
Important note
/replaceitem
will be removed in 1.17 and replaced with /item
. However, you can easily convert to the new command, instead of:
/replaceitem entity @s weapon.mainhand iron_pickaxe{tag:1}
it will be:
/item entity @s weapon.mainhand replace iron_pickaxe{tag:1}
-
This is pretty cool thanks for your help, but I want to make it so that the player collects different tools around the city from chest (they would be regular tools, they couldn't break anything), and when the player enters a certain area how to replace their regular tools with the ones that can break certain blocks. Could you type the command that when you enter that certain area it replaces your tools with the ones that break those blocks. I would appreciate it.– KarolisCommented Mar 14, 2021 at 19:17
-
1Sure, you just need to remove the
,tag:{tag:1}
in this commandexecute if entity @a[x=-12,y=56,z=8,dx=-7,dy=1,dz=-2] as @a[nbt={SelectedItem: {id:"minecraft:iron_pickaxe",tag:{tag:1}}}] if entity @s run replaceitem entity @s weapon.mainhand iron_pickaxe{CanDestroy:["iron_bars"]}
Commented Mar 15, 2021 at 12:39 -