I need two players always have the same items in their main hands. If one player changes the item he holds, then the second player's item becomes the same.
Is it possible to find out what exactly item the player holds in his hand, and then give it to the second player?
Or I will have to go through all the possible options, like:
EXECUTE IF player1 has stone RUN give player2 stone EXECUTE IF player1 has andesite RUN give player2 andesite EXECUTE IF player1 has granite RUN give player2 granite .... and so on until all minecraft items are over.
I have no other idea how to do this.
The next command give me the ID that I need ("minecraft:stone", for example):
data get entity @p[name=player1] SelectedItem.id
I need to paste this ID into the command:
/replaceitem entity @p[name=player2] weapon.mainhand ID 1
But there's no variables in Minecraft so I can't save the ID to use it further.
And the "execute store" command doesn't support string types — just numbers.
The Meaning of Life, the Universe, and Everything.
Location:
Quebec
Join Date:
6/29/2014
Posts:
50
Minecraft:
Avarthar
Member Details
If you are on 1.14 (Or 1.13 I think should work too.)
Here is what I got to work as simple as I could:
Run both of these commands on a clock. (Or with datapack ticks.)
scoreboard players set @a holdingstone 0
execute if entity @p[nbt={SelectedItem:{"id":"minecraft:stone"}}] run scoreboard players set @a holdingstone 1
With the selector @p if the closest player holds a stone, it sets the score to 1.
Then the check command looks like so. (To run the command you want.)
execute as @p if entity @s[scores={holdingstone=1}] run say test
And because I like doing those, here is an in-action gif: (I did not have the third command in this gif, but you can simply add a chain command block on top and it will work just fine or run it through a datapack function with the rest of the commands.)
Rollback Post to RevisionRollBack
Most of my replies are boring at best, but you cannot say I did not try. Just like this signature for example.
So if I don't know what exactly item the first player holds, I'll have to try all the options:
execute if entity @p[nbt={SelectedItem: {id:"minecraft:stone"}}] run scoreboard players set @a holdingitem 1
execute if entity @p[nbt={SelectedItem: {id:"minecraft:granite"}}] run scoreboard players set @a holdingitem 2
execute if entity @p[nbt={SelectedItem: {id:"minecraft:cobblestone"}}] run scoreboard players set @a holdingitem 3
execute if entity @p[nbt={SelecteItems: {id:"minecraft:coal"}}] run scoreboard players set @a holdingitem 4
...
execute if entity @p[nbt={SelectedItem: {id:"minecraft:tripwire_hook"}}] run scoreboard players set @a holdingitem 100
execute if entity @p[nbt={SelectedItem: {id:"minecraft:redstone_block"}}] run scoreboard players set @a holdingitem 101
execute if entity @p[nbt={SelectedItem: {id:"minecraft:dark_oak_door"}}] run scoreboard players set @a holdingitem 102
...
etc
And then
execute as @p if entity @s[scores={holdingitem=1}] run give @p[name=player2] minecraft:stone 1
execute as @p if entity @s[scores={holdingitem=2}] run give @p[name=player2] minecraft:granite 1
execute as @p if entity @s[scores={holdingitem=3}] run give @p[name=player2] minecraft:cobblestone 1
execute as @p if entity @s[scores={holdingitem=4}] run give @p[name=player2] minecraft:coal 1
...
execute as @p if entity @s[scores={holdingitem=100}] run give @p[name=player2] minecraft:tripwire_hook 1
execute as @p if entity @s[scores={holdingitem=101}] run give @p[name=player2] minecraft:redstone_block 1
execute as @p if entity @s[scores={holdingitem=102}] run give @p[name=player2] minecraft:dark_oak_door 1
...
etc
The Meaning of Life, the Universe, and Everything.
Location:
Quebec
Join Date:
6/29/2014
Posts:
50
Minecraft:
Avarthar
Member Details
For the first post yes, you will have to make a check for every item you want to check for.
There is probably a way to assign a command to an item directly, like an on-drop, but you will probably need to check for some tag, id, or anything else to differenciate the items, no matter what method you use. (I wished we had more control on that since the in-game commands are pretty much a programming language anyways, but until we get some kind of variables to store what we want, we cannot do much different ^^'. Arrays, lists, integers, and so on would be more than welcome in my opinion.)
For me, writing the few lines I posted you is not super hard since I run commands through functions in my datapack (It is way easier for me to write in a proper programming tool than write from the in-game's chat bar.)
But if you prefer not using datapacks, each command must be ran in a chain command block, except for the first one which needs to be a repeating command block. (If you want those to run every tick like it currently does.)
For the second post, if it works well, there is no need to use the scoreboard ^^.
Personally I prefer using scoreboards as to provide a way to see if the detection went through correctly or not.
But that's only a debugging habit I got from my programming past ^^.
I need two players always have the same items in their main hands. If one player changes the item he holds, then the second player's item becomes the same.
Is it possible to find out what exactly item the player holds in his hand, and then give it to the second player?
Or I will have to go through all the possible options, like:
I have no other idea how to do this.
The next command give me the ID that I need ("minecraft:stone", for example):
I need to paste this ID into the command:
But there's no variables in Minecraft so I can't save the ID to use it further.
And the "execute store" command doesn't support string types — just numbers.
If you are on 1.14 (Or 1.13 I think should work too.)
Here is what I got to work as simple as I could:
Run both of these commands on a clock. (Or with datapack ticks.)
With the selector @p if the closest player holds a stone, it sets the score to 1.
Then the check command looks like so. (To run the command you want.)
And because I like doing those, here is an in-action gif: (I did not have the third command in this gif, but you can simply add a chain command block on top and it will work just fine or run it through a datapack function with the rest of the commands.)
Most of my replies are boring at best, but you cannot say I did not try. Just like this signature for example.
So if I don't know what exactly item the first player holds, I'll have to try all the options:
And then
Is there another way?
Why do I need the scoreboard?
It's easier to write:
For the first post yes, you will have to make a check for every item you want to check for.
There is probably a way to assign a command to an item directly, like an on-drop, but you will probably need to check for some tag, id, or anything else to differenciate the items, no matter what method you use. (I wished we had more control on that since the in-game commands are pretty much a programming language anyways, but until we get some kind of variables to store what we want, we cannot do much different ^^'. Arrays, lists, integers, and so on would be more than welcome in my opinion.)
For me, writing the few lines I posted you is not super hard since I run commands through functions in my datapack (It is way easier for me to write in a proper programming tool than write from the in-game's chat bar.)
But if you prefer not using datapacks, each command must be ran in a chain command block, except for the first one which needs to be a repeating command block. (If you want those to run every tick like it currently does.)
For the second post, if it works well, there is no need to use the scoreboard ^^.
Personally I prefer using scoreboards as to provide a way to see if the detection went through correctly or not.
But that's only a debugging habit I got from my programming past ^^.
Most of my replies are boring at best, but you cannot say I did not try. Just like this signature for example.
Ok.
Thanks.