You want to do this with scoreboards. My solution won't prevent getting diamond swords, but it will prevent crafting them and using them, i.e. a player can have a diamond sword in their inventory, as long as they never use it. How it gets there without crafting it, though, is pretty much impossible without cheats.
First, you need to set up 2 scoreboard objectives, one for crafting, and one for using:
/scoreboard objectives add craftedDiamondSword stat.craftItem.276
/scoreboard objectives add usedDiamondSword stat.useItem.276
Next, you need to set up two nearly identical chains of command blocks, one for each scoreboard objective. This will run on a clock like you already have. I'll only give the commands for using, so just replace that in the second chain with the crafting objective.
First, clear those players inventories:
clear @a[score_usedDiamondSword_min=1] 276
Next, tell the players that used a diamond sword to not use it, and reset their score:
tell @a[score_usedDiamondSword_min=1] Don't use diamond swords!
scoreboard players set @a[score_usedDiamondSword_min=1] usedDiamondSword 0
This last command block doesn't really need the [score_usedDiamondSword_min=1]
but it's useful.
I got this to work in a single line of command blocks with redstone over top for the uses chain, but it wouldn't work for the crafting. The solution is to pipe the result from the clear command block into the tell and set scoreboard command blocks with comparators. Here's a pic of the two setups:
Use whatever clock you want.
Additionally, if you never, ever want players to have a diamond sword, even in their inventory, and even if they don't use it, you can still clear from @a
, and then just say
to not use diamond swords if one is found.
Update for added 1.8 functionality:
The 1.8 snapshots have added the option to match players against the Inventory
NBT tag when setting or incrementing a scoreboard objective. This means we can set up a dummy scoreboard objective to track whenever someone has a Diamond Sword in their inventory, regardless if they've used it or crafted it. First, set up the scoreboard objective:
/scoreboard objectives add hasDiamondSword dummy
Next, we need to run two command blocks on the same clock; one to set players scores, and another to check those player's scores and clear the diamond swords:
scoreboard players add @a hasDiamondSword 1 {Inventory:[{id:"minecraft:diamond_sword"}]}
clear @a[score_hasDiamondSword_min=1] minecraft:diamond_sword
The second command is fairly similar to the old commands, except instead of using the old ID number, I'm using the name instead. The first is a bit more complicated, so let's walk through it. Basically it says add to all players on their hasDiamondSword
objective the value 1 if that player has an inventory and that inventory contains a diamond sword. So, for anyone that has a diamond sword in their inventory, their hasDiamondSword
objective will be incremented.
Finally, like in the old version, we need to tell
the players to not use diamond swords, and to reset their hasDiamondSword
objective:
tell @a[score_hasDiamondSword_min=1] Don't use diamond swords!
scoreboard players set @a[score_hasDiamondSword_min=1] hasDiamondSword 0
I stacked these two command blocks (with the tell
on bottom) and fed them with a comparator from the clear
command block. This is what it all looks like in the end:
The /execute
command is used to execute another command relative to something, the syntax you'll need is:
/execute <entity> <x> <y> <z> <command>
You should use target selectors with selector arguments to select to entity you want to execute from.
To summon TNT from an item drop, you could do:
/execute @e[type=Item] ~ ~ ~ /summon PrimedTnt
(Be careful with this command, as all item drops will act as a grenade)
Best Answer
Assuming you have the "sentry gun" shooting arrows, you would use the command:
/summon Arrow x y z {damage:1,Motion:[x.0,y.0,z.0]}
You would have to plug into the first set of coordinates where you want the arrows to be shooting from, and the direction the arrows are shooting in the second. TIP: The higher the number you set for your direction (second set of coordinates, the faster the arrow will travel! You can set anything for the damage (except dont get too crazy :P)
As for your "Tool Box" Idea, you can do the test for command on a redstone ticker:
testfor @e[x,y,z,r,type=Item] {Item:{id:minecraft:iron_block}}
(Unfortunately, you cant test for a custom named block/entity - at least to my knowledge) Run a comparator out of this command block, to another command block (does not NEED to be a command block). This will start a fast ticking redstone clock on another command block. This command block will have the command:
testfor @e[x,y+1,z,r,type=Item] {Item:{id:minecraft: ... }}
Make sure that the coordinates you plug into the last testfor command have y+1 the y coordinate of the testfor command before that. This means it will test for the item on top of your "tool box". Run a comparator out of that command block to start the /summon Arrow command, or in other words, start up your sentry! (The arrows are seen only as little black dots in this photo, but thats because I have the speed ramped up :)
Basically, its a system of Testing positive for an iron block at x y z - starting ticker to test for ... entity at x y+1 z - testing positive for ... entity at x y+1 z - starting ticker to shoot "sentry gun"
Hope this helps