Can you disable the repair cost increasing in Minecraft 1.8?
As you might know, starting with Minecraft 1.8, the repair cost for an item goes up the more it was previously repaired, to the point where the item can no longer be repaired.
Is there a way to revert this change using command blocks?
The repair cost of an item is saved in the items NBT data, specifically the RepairCost
tag. Knowing this, we can easily create a command block contraption that resets this tag.
Simple version:
Create a redstone clock inside your spawn-chunks (I suggest placing it inside a bedrock box), and use it to power a command block with the following command:
/entitydata @e[type=Item] {tag:{RepairCost:0}}
This will add the RepairCost
tag to every item that is lying on the ground, including those who never had it, or for which it makes no sense, such as Cobblestone or Logs. I can't think of a better, non-tedious method, however.
Updated version from 1.13+
Some commands have been reworked in 1.13, and /entitydata
doesn't exist anymore.
Here is a modern, up-to-date solution (works as of 1.16 snapshots even!) using /execute
and /data
:
/execute as @e[type=item] run data remove entity @s Item.tag.RepairCost
This has the advantage of only removing the RepairCost
tag without making any unnecessary changes.
Usage
Drop items, run command, pick items up again, cleared of repair penalty. Optionally stick the command into a command block with a button, drop items, push button, pick up.
How it works:
/execute as @e[type=item] run
/execute
causes a command to be run for every item selected by the selector (here @e[type=item]
: all entities of a type "item" - dropped items are entities of this exact type)
as
makes the command's "executor" the actual entity targeted (as opposed to the player/server who runs it, this will be important later on
run
specifies that the rest is the actual command to execute
Now every dropped item "runs" the following:
/data remove entity @s Item.tag.RepairCost
/data
is the new command for all your entity and block data manipulation needs, it has very many complex options...
remove
specifies we will be removing something
entity
specifies we are targeting an entity, you can also target a block or "storage", I am guessing you can use this to store data for later use without tying it to an entity - sort of like included in your world's savefile.
@s
targets "self", or the entity executing the command (that's why the as
in /execute
is important - it makes it so now @s
actually selects the specific dropped item).
Item.tag.RepairCost
-this simply selects what we want to target for remove
to do its work. You can run the command with get
instead of remove to show how it works - it will display that particular item's repair cost if it has any. In case of RepairCost, it is stored under the Inventory Item's "tag" list, which also can contain enchantments, damage values, and other extra data, while the Inventory Item itself is stored as an "Item" object on the actual minecraft:item entity.
As a bonus, the command provides instant feedback with the changes that actually occurred - if no items were modified, there is no output, and otherwise a line per item modified is shown.
More details/rambling
The below screenshot documents some of my poking around; lines saying "such and such has the following entity data" are where I used get
instead of remove
to get a hang of the structure. The first few lines with eggs and salmon items I targeted simply Item
, which then returns the typename of the Inventory Item; then I ran Item.tag
which technically ran on the salmon and eggs, too, but since they did not have any tags on their Item
no message was shown; the Enchanted book had a tag
containing a list StoredEnchantments
and a RepairCost
(getting closer!). Next was the entire command, just with get
instead of remove
, confirming items with a RepairCost
of "1". Next messages ("Modified entity data") is where I ran remove - afterwards the get
command did not result in messages as all items with RepairCost
were gone now. As a test, I ran the get
command with Item.tag
as target to see if my pickaxe had a repair cost tacked on, and it didn't - it did nicely show the Damage
value and the list of Enchantments
.