Agent Fence
Agent Builds a Fence @showdialog
Your helpful Agent will build a fence for your farm animals!
On chat command
Change the ||player:on chat command||
block on the workspace from "run"
to "fence"
.
player.onChat("fence", function () {
})
Teleport your Agent
Drag out the ||agent:agent teleport to player||
block from the Toolbox and drop into the ||player:on chat command||
block.
player.onChat("fence", function () {
agent.teleportToPlayer()
})
Give your Agent fences
Go get an ||agent:agent set block or item||
block and drop it under the ||agent:agent teleport||
block. Click on the grass
block and change it to a fence block that you like. Set the count to 33.
player.onChat("fence", function () {
agent.teleportToPlayer()
agent.setItem(OAK_FENCE, 33, 1)
})
Place blocks as Agent moves
Find the ||agent:agent place on move||
block in the Toolbox, grab and drop it under the ||agent:agent set block or item||
. Change the OFF setting to ON.
player.onChat("fence", function () {
agent.teleportToPlayer()
agent.setItem(OAK_FENCE, 33, 1)
agent.setAssist(PLACE_ON_MOVE, true)
})
Allow Agent to destroy obstacles
Drag out another ||agent:agent place on move||
block and drop it under the previous one. In this block, click on ||agent:place on move||
and change to ||agent:destroy obstacles||
. Then change the OFF setting to ON.
player.onChat("fence", function () {
agent.teleportToPlayer()
agent.setItem(OAK_FENCE, 33, 1)
agent.setAssist(PLACE_ON_MOVE, true)
agent.setAssist(DESTROY_OBSTACLES, true)
})
Add a loop to build each side of the fence
Find the ||loops:repeat||
block, drag and drop it under the ||agent:agent destroy obstacles||
block.
player.onChat("fence", function () {
agent.teleportToPlayer()
agent.setItem(OAK_FENCE, 33, 1)
agent.setAssist(PLACE_ON_MOVE, true)
agent.setAssist(DESTROY_OBSTACLES, true)
for (let index = 0; index < 4; index++) {
}
})
Instruct the Agent to turn before moving
Get an ||agent:agent turn left||
block and drop it inside the ||loops:repeat||
loop.
player.onChat("fence", function () {
agent.teleportToPlayer()
agent.setItem(OAK_FENCE, 33, 1)
agent.setAssist(PLACE_ON_MOVE, true)
agent.setAssist(DESTROY_OBSTACLES, true)
for (let index = 0; index < 4; index++) {
agent.turn(LEFT_TURN)
}
})
Instruct the Agent to move
Grab and drag out the ||agent:agent move||
block and drop it under the ||agent:agent turn left||
block in the loop. Click on the 1 and change to 8.
player.onChat("fence", function () {
agent.teleportToPlayer()
agent.setItem(OAK_FENCE, 33, 1)
agent.setAssist(PLACE_ON_MOVE, true)
agent.setAssist(DESTROY_OBSTACLES, true)
for (let index = 0; index < 4; index++) {
agent.turn(LEFT_TURN)
agent.move(FORWARD, 8)
}
})
Place the last fence post
Drag another ||agent:agent move||
block and drop it after the ||loops:repeat||
block.
player.onChat("fence", function () {
agent.teleportToPlayer()
agent.setItem(OAK_FENCE, 33, 1)
agent.setAssist(PLACE_ON_MOVE, true)
agent.setAssist(DESTROY_OBSTACLES, true)
for (let index = 0; index < 4; index++) {
agent.turn(LEFT_TURN)
agent.move(FORWARD, 8)
}
agent.move(FORWARD, 1)
})
Run your code!
Click on the green Play button to run your code in Minecraft. Move to a flat area and press T to open the chat window. Then type "fence"
to run your code.