I have two possible solutions for you.
First Solution
If you are trying to select a player using the selector relative to where the player is located from a specific coordinate, the selector code doesn't except the '~' character like many commands do to communicate relative coordinates. Instead use dx, dy, & dz. As an example, using the numbers from your execute command
execute @p[x=X,y=Y,z=Z,dx=10,dy=0,dz=15] ~ ~ ~ setblock 400 15 400 dirt 0 replace
This will select a player remotely, as you described above, if your command block is far away (within 16 loaded chunks I believe), and will set up a "volume" or a "box" that is x=~10, dy=~0, and dz=~15 that has an origin (starting corner) at the specific coordinate x=X, y=Y, & z=Z, where X, Y, & Z are positive or negative integers: decimal numbers are not excepted.
As long as the location/zone where the player needs to be detected isn't moving to some other location in the world, this should work just fine.
Second Solution
If the player walking over blue stained glass, for example, could be used to trigger your event instead, here's how you might accomplish that.
execute @a ~ ~ ~ detect ~ ~-1 ~ minecraft:stained_glass 11 setblock 400 15 400 dirt 0 replace
The documentation from the official minecraft wiki looks like this
execute <entity> <x> <y> <z> detect <x2> <y2> <z2> <block> <data> <command …>
where <data>
is where you would enter the data value of the color of glass you wish to use to trigger a specific event (11 being blue). <x2> <y2> <z2>
are just the coordinates of the block you'd like to detect. In the example I used ~ ~-1 ~
which just detects for a blue stained glass block below all players (which the all players @a selector can be replaced with whatever selector you happen find best to use).
Hopefully this helps.
As a Warning
Based on what I have read from the wiki, it may cause the execute command to fail if a player who does not have permission to execute the specified command is selected. Which means, if your players are meant to be in survival or adventure mode, you may have to use the execute command on an invisible entity (such as an armor stand with NBT tags set to {Marker:1,Inivisible:1}
) to detect whether a player has entered the specified area, and then trigger the event that way.
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.
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
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
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
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.
Best Answer
What you are asking for isn't a simple
/fill
, but a system that can generate a cube of stone filled with ores. Imagine the cube just being a bunch of stacked layers that each have been randomly filled with ores.Summon an armorstand in the bottom corner at the -x -z side of the mine and name it `Layer
This will be the pointer of the current layer.
We will also need some armorstands to mark the ores
You can name some of the armorstands
GoldOre
orDiamondOre
ect for diffrent ores (The more armorstands summoned, the more ores per layer)We will first of all fill the layer with stone. (our mine will be 11*11 in this example)
now spread the armorstands randomly along the layer
make the Ore armorstands place some ores below them (do this for all ore types)
Tp The ore armorstands to
Layer
and finally tp
Layer
one block up and repeat