To teleport an armorstand to an item, as you say in your title:
/tp @e[type=ArmorStand,name=Red] @e[type=Item,...]
Where ...
is whatever you're using to identify the item (name? scoreboard value? location?).
To spawn an armorstand at an item, as you say in your question:
/execute @e[type=Item,...] ~ ~ ~ /summon ArmorStand ~ ~ ~ {CustomName:"Red"}
Again, where ...
is however you're identifying the item. I'd recommend using a scoreboard value based on their item ID, like this:
/scoreboard players set @e[type=Item] isRedWool 1 {Item:{id:"minecraft:wool",Damage:14s}}
Where isRedWool is a dummy objective.
Running score method: Primitive, simple, but not as good as others
Min |
Max |
-2147483648 |
2147483647 |
Details
The simplest solution is not to use an actual random generator at all, because it's not really needed. The randomness can come from a user input instead.
What I mean by that is that you can have a rapidly changing scoreboard objective, and evaluate the score at the moment a button is pressed.
First set up your randomness objective using
scoreboard objectives add RNG dummy
There used to be a stat.playOneMinute
which would automatically increase it by 1 every single game tick without another command needed, and it will not be the same for every player (if that is not desired, resetting it for everyone works). However, because updates have removed this statistic, we would need to implement our own commands to increase it by one tick.
1.13+ : scoreboard players add @a[scores={RNG=9..}] RNG 1
1.12- : scoreboard players add @a[score_RNG_min=9] RNG 1
Now create a fill/setblock clock and have it run
1.13+ : scoreboard players set @a[scores={RNG=9..}] RNG 0
1.12- : scoreboard players set @a[score_RNG_min=9] RNG 0
and you're done. To use your random numbers, make one command block for every single outcome and include [score_RNG=X,score_RNG_min=X]
with your target selector arguments, where X
is the score to use, running from 0 to 8(!). Trigger all of these at the same time. For example
...
/give @a[score_RNG=4,score_RNG_min=4,team=PlayingTheGame] diamond_sword
/give @a[score_RNG=5,score_RNG_min=5,team=PlayingTheGame] dirt
...
If your command does not use a target selector argument, you can (ab)use execute
for that, e.g.
/execute @a[score_RNG=4,score_RNG_min=4] ~ ~ ~ setblock 1 2 3 stone
Nowadays in 1.13+, it is advised not to use this as there are much better alternatives and it requires a running function. This is however the most easy way to generate random numbers.
Best Answer
You can create a loot table that contains all the different items you want the item dropper to drop.
Go to minecraft.tools/en/loots.php to create a loot table with all of the items you want in it. Because loot tables are random (you don’t get the same exact drops and amounts of those drops when you kill mobs), loot tables can be used to generate random drops, but can be controlled enough to decide probabilities and amounts if you so desire.
If you don’t know how to create loot tables, there are plenty of examples on the internet that explain how.
Once you create your loot table, copy it to your clipboard and go to your world saves folder (the world saves folder’s name is default to “world” on servers) and then navigate to the folder called
data
. Create a folder calledloot_tables
inside of it if it doesn’t already exist. Inside of that folder, create a folder calledcustom_drops
. Inside of the custom_drops folder, create a folder calledentities
. Then in that folder create a text file calleditem_dropper.json
with your loot table pasted inside of it.In your minecraft world, use this command to summon the armor stand:
Then kill the armor stand with the command
/kill @e[type=armor_stand,name=item_dropper]
right after you summon it (with chain command blocks you could do this on the same tick).This will summon an armor stand with the loot table created, and then kill it to make it drop the items in the loot table.
Keep in mind that the mob loot gamerule must be on for this to work. Use
/gamerule doMobLoot true
to toggle mob loot to true.