How do I create a command to make me stay at one stack of an item?

How do I create a command to make me stay at one stack of an item? - Unrecognizable crop African American female pouring essential oil in glass bottle while making liquid incense at table

I would like to make a command that keeps me at one stack of arrows.

How can I do this?



Best Answer

1. CommandStats

Using CommandStats allows you to detect the number of specific items in a player's inventory no matter how they are arranged. This both allows you to accurately provide arrows until they reach exactly 64 as well as remove arrows if they have more than 64.

Prerequisites

Objective to hold the number of relevant items.

/scoreboard objectives add ArrowCount dummy

"AffectedItems" CommandStat trigger to apply to players, who will target their own "ArrowCount" score. This may need to run on a clock if new players may join at any time.

/stats entity @a set AffectedItems @a[c=1] ArrowCount

In order for CommandStats to modify a target's score, that target must be tracked prior. This may also need to run on a clock for the same reason.

/scoreboard players add @a ArrowCount 0

Clock commands

The following must be run in numerical order on a clock.

  1. Cause players to run a /clear command that looks for a specific item. The maximum amount is set to 0, which means no items will be removed but the "AffectedItems" trigger will be sent the total number of that item the player has in their inventory. You can add to this command to look for an exact arrow rather than generic arrows.

    /execute @a ~ ~ ~ /clear @a[c=1] minecraft:arrow 0 0
    
  2. Players that have 63 or fewer arrows will be given a new arrow.

    /give @a[score_ArrowCount=63] minecraft:arrow
    
  3. Players with 65 or more arrows will have the extra arrows removed.

    /clear @a[score_ArrowCount_min=65] minecraft:arrow 0 1
    

The final result is the player never having more or less than 64 of that specific arrow in their inventory.

2. Statistics

The stat.useItem.bow objective-type will increase when the bow is used, and you can use that to provide the player with the appropriate number of arrows.

/scoreboard objectives add UseBow stat.useItem.minecraft.bow

And the following would run in numerical order on a clock.

  1. Provide relevant players with an arrow after they have used their bow.

    /give @a[score_UseBow_min=1] minecraft:arrow
    
  2. Reduce their "UseBow" score by 1.

    /scoreboard players remove @a[score_UseBow_min=1] UseBow 1
    

The downside is you will not be able to differentiate between special arrows that have been removed, such as tipped arrows, and normal arrows. As well, the player can pick up more than the allotted 64 arrows since this only provides new arrows rather than removing extra.




Pictures about "How do I create a command to make me stay at one stack of an item?"

How do I create a command to make me stay at one stack of an item? - Concentrated redhead female wearing light apron kneading clay in baking pan while creating in modern apartment
How do I create a command to make me stay at one stack of an item? - Crop black woman with trimmer preparing candles with wicks
How do I create a command to make me stay at one stack of an item? - Senior male artisan creating bag together with female assistant



How do you stack commands in Minecraft?

To make your command block run multiple commands, you will need to summon FallingSand or falling_block (depending on your version of Minecraft) with command blocks and redstone blocks for each command. The command blocks will be stacked one on top of the other and contain the individual command.

How do you activate a command block by holding an item?

The only way to get an "infinite stack" of anything would be to set up a clock that drops an item, constantly. You can't hold an "infinite" stack of anything in Minecraft. So, set up a command block to drop a fire charge in a certain location, then hook it up to a red-stone clock.



How to get 64 of 1 item/stack of items in minecraft




More answers regarding how do I create a command to make me stay at one stack of an item?

Answer 2

Simply put the following commands in a repeat/chain command block line:

/scoreboard players tag @a[tag=arrows] remove arrows
/scoreboard players tag @a[tag=!arrows] add arrows {Inventory:[{id:minecraft:arrow,Count:63}]}
/give @a[tag=arrows] minecraft:arrow

Note that you must start off with either 63 or 64 arrows for this command to work.

When you fire an arrow, it is instantly replaced.

Answer 3

Set a command block to (clock)

testfor @e[type=arrow,r=radiusInBlocks]

then have a comparator going out of it connecting to two command blocks (needs redstone) with

give player minecraft:arrow

and after some delay...

kill @e[type=arrow]

Then if you start with 64 arrows, you shoot one, you gain one! :D

Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Anna Shvets, Monstera, Anna Shvets, Andrea Piacquadio