Chest Item Spawning and Gold as a Currency
Solution 1:
Note that for all arguments [within square brackets]
, an appropriate value should be inserted instead. Also, commands contained within Command Blocks do not need to be prefixed with a forward slash (/
).
How to specify coordinates:
A coordinate can be specified in one of two ways (with the exception of the execute
command, which is off-topic): either via absolute or relative coordinates. Absolute coordinates are simply integers referencing a particular block. An absolute coordinate can be found by looking at the Debug Menu, which can be opened by pressing F3
. Relative coordinates are integers also, but instead of being measured from 0
, 0
, 0
of the map, they are instead measured from the caller (in this case, a Command Block). From a Command Block, the relative coordinate of 0
, 0
, 0
refers to the Command Block itself; whilst 0
, 1
, 0
would be the block directly above the Command Block; and 2
, 4
, -7
would refer to the block 2 blocks in the positive X
direction, 4 blocks up, and 7 blocks in the negative Z
direction.
How to spawn items in chests per set interval of time:
There are a few available options for this, one of the best of which is outlined as follows:
Replacing an item slot
For this to work, the Command Block would need to be attached to a Clock which has a pulse length equivalent to the cooldown time of the item replacement.
The following code should be used, with arguments as detailed afterwards:
replaceitem block [xCoord] [yCoord] [zCoord] [slotNumber] [itemId] [amount]
-
replaceitem
is the command name, do not change this. -
block
denotes that a block is having its contents edited, do not change this. -
[xCoord]
,[yCoord]
, and[zCoord]
should be replaced by the coordinates at which the block to be edited may be found (see above, how to specify coordinates). -
[slotNumber]
should be replaced by the slot number of thetileEntity
(block with inventory) to be edited. For Chests, there are 36 slots, numbered0
to35
. These read from left to right, beginning at the first row and ending at the last. A graphical representation of this would look similar to as follows, with each line being a row of the chest's inventory, and each box containing the number for the specified slot:[0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28] [29] [30] [31] [32] [33] [34] [35]
[itemId]
should be replaced by the Item ID of the new item (in this case, the item to be available after a cooldown). Item IDs are in the format ofminecraft:[item_name]
, more details can be found on this excellent list, as well as on the Minecraft Wiki page on Item Ids (link not posted as rep is not high enough).-
Optional:
[amount]
should be replaced by the required number of items. If left blank, only one item will be added. - Another two arguments, [data] and [dataTag] exist, intended for editing the NBT (attributes, name, lore and other things) of the item. However, they are rather out of scope of this question, however if required information may be found at the Minecraft Wiki page on Commands.
How to create a currency system:
There are many ways to achieve this, far too many to be listed here. Also, the question does not make it clear as to whether or not the 'Gold' aforementioned is real - Gold Bars in Item form - or a virtual currency defined via scoreboards, which is sold and bought with Command Blocks. So, the simpler option of the two will be described here: the Scoreboard Virtual Currency.
Firstly, the scoreboard variable must be initialised. Do this by typing in chat:
/scoreboard objectives add gold dummy Gold
Next, as I am unaware of the layout/setup of your server map, I will simply give you the commands to increment and decrement the gold score of a player. To increment, issue the following command (either in chat or in a Command Block):
scoreboard players add [selector] gold [integer to increase by]
and to decrement:
scoreboard players remove [selector] gold [integer to decrease by]
Note that the selector
aforementioned is a special expression used to match against specific entities. An example of this would be @p
, which targets the nearest player. To read up further, look here: minecraft.gamepedia.com/Selector#Target_selectors (hyperlink not included due to not enough rep).
Also note that the score would not be visible, to counteract this issue the command of:
scoreboard objectives setdisplay [slot] gold
Here the slot
is either list
for the tab
menu, sidebar
for a sidebar, or belowName
which is shown in SMP under players' nametags.