Minecraft – Testing for a Certain Structure

minecraft-commandsminecraft-java-edition

I'm trying to make a sentry gun in minecraft, I've made the shooting system already (wich shoots at entities) but the problem is that the "sentry gun" works in an area around the main command block, I wanted to make a structure to work as the sentry instead of the main command block.

I've tried testing for an iron block named "Tool Box", I wanted to make something like placing the Tool Box and activating it using a dropped item on top of it or maybe even an item (I tried with a hoe for example) but I got no idea how to do it.

The Shooting System works like this:

It'll trigger at any entity that enters the area of the main command, except for players and arrows, when something enters the area it starts spawning arrows on d dtop of it that fall aneal damage, so basically I got the system working on a command, all I have to do is change so that command triggers at a certain structure.

Main command:

/execute @e[score_sentryKill_min=1,r=10] ~ ~2 ~ summon Arrow {damage:10.0}

Basically all other commands are "Don't target Players, don't target arrows, kill the arrows when they hit the ground"

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}} enter image description here

(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: ... }} enter image description here

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! enter image description here (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