0

I am making a map that relies on currency and other custom things like a shop. But the issue is that I'd like the player to be able to sell for example 16 chorus fruits for 20 Coins. Now keep in mind I'm building the map on the latest snapshot of Minecraft 1.9 and thus I'm using the brand new command blocks. There are some limitations to what I can use. For example I'm only able to use a total of 4 command block for every item because of lack of space.

And if you have a way of making it possible I'd love you to explain the command and how it works so that I can have a better understanding of what I'm doing.

EDIT: I'm aware that I'll probably have to use /testfor and I found this online:

/testfor @p[r=10] {Inventory:[{id:"minecraft:emerald",Count:2b}]}

keep in mind I have no idea how to make it so that I can /testfor a certain amount of an item. The youtuber who posted it as dragnoz so take a look there for even more info.

7
  • Are you asking us to make this for you? Please keep in mind that we tend to reward questions that have had some research effort put into them. What have you tried so far?
    – user114997
    Jan 23 '16 at 13:43
  • 1
    Have you made any attempt to solve this yourself? Arqade works better when askers show effort to solve their own problems; we see that you have a problem you've worked on, and answerers respond to that. You also get a more specific answer that's tailored exactly to the part you're stuck, and Arqade gets a very specific question. Everybody wins!
    – Frank
    Jan 23 '16 at 14:20
  • Why is your space limited? You can always chuck the commandblocks down beneath bedrock at y=1, or similarly hidden far away from all players.
    – MrLemon
    Jan 23 '16 at 15:04
  • I have searched online for about 3 hours with no succes efore i osted my question
    – Palestina
    Jan 23 '16 at 15:16
  • I would make villager shops instead of commandblocks, they are good enough for item to item trading. Jan 23 '16 at 15:48
3

The issue with checking for the Count tag is that it checks for an exact match rather than minimum. The player must have a stack of exactly 2 emeralds in a slot in their inventory, otherwise they cannot match.

To circumvent that, you will have to use CommandStats, which are a set of triggers that can set a target's scoreboard score based on the success of the command. For example, the "SuccessCount" trigger sets a score equal to the number of times a command was successfully processed (such as /testfor @e[type=Creeper] resulting in a score equal to the number of creepers).

For item detection, "AffectedItems" will be used.

Prerequisites

Objective to hold each player's "AffectedItems" return value.

/scoreboard objectives add ITEMS dummy

In order for CommandStats to modify a target's score, that target must be tracked prior. This may need to run on a clock in the event new players can join at any time.

/scoreboard players add @a ITEMS 0

Clock commands

The following will need to be run on a clock.

CommandStat trigger applied to all players, who will set their own "ITEMS" score based on commands that they run. This needs to run on a clock because it is being removed during detection.

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

Detection

The following must be run in numerical order each time you want the player to sell an item. You may need to change target selectors to target a specific player, such as using x/y/z/r parameters depending on your setup.

  1. Cause players to use /clear to remove 0 of the specified item. While this does not remove any items, the stored "AffectedItems" trigger will receive the number of items that could have been cleared, which would be equal to the number of emeralds across the player's inventory. Their "ITEMS" score will be set to that number.

    /execute @p[x=0,y=0,z=0,r=0] ~ ~ ~ /clear @a[c=1] minecraft:emerald 0 0
    
  2. If a player had at least 16 emeralds ("ITEMS" score of 16+), then remove their "AffectedItems" trigger to preserve their score. If a /give or /clear command is used instead, their "ITEMS" score will be modified and thus can no longer reliably be used.

    /stats entity @p[x=0,y=0,z=0,r=0,score_ITEMS_min=16] clear AffectedItems
    
  3. Provide the player with necessary item if they have an "ITEMS" score of 16+, which means they have 16+ emeralds.

    /give @p[x=0,y=0,z=0,r=0,score_ITEMS_min=16] minecraft:stone
    
  4. Remove the 16 emeralds from the player's inventory.

    /clear @p[x=0,y=0,z=0,r=0,score_ITEMS_min=16] minecraft:emerald 0 16
    

Summary

You will repeat the "Detection" command set for each item you want to sell. Make sure to change the coordinates for each section.

CommandStats guide.

General info on commands.

2
  • Thanks for the answer but unfortunately this didn't work for me..probably because im using a 1.9 snapshot but honestly idk anywasy i ahve given up oon the idea of making a shop with command blocks and have made a shop using villagers as suggested by a player iwithing the comments section here in stackexchange so your answer is not needed anymore but thank you alot anyways it really makes me proud of the gaming community to see posts like yours.
    – Palestina
    Jan 28 '16 at 18:01
  • @Palestina If you are having issues you should post exact errors here and I could determine the problem you're having (although when CommandStats are involved, it would probably just be easier to provide a world download). 1.9's changes does not affect the system above, and does work in 1.9.
    – Skylinerw
    Jan 28 '16 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.