Last active
February 16, 2020 20:52
-
-
Save Xayer/3ab91f5eb22f595674faea4469cee2b9 to your computer and use it in GitHub Desktop.
Minerbot made in Minecraft MakeCode - Javascript code. Still need to figure out what to do, if the block you're destroying is sand or gravel, as it falls down.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function GoHomeWithLoot () { | |
LastMiningPosition = agent.getPosition() | |
agent.teleport(Home, WEST) | |
agent.dropAll(DOWN) | |
agent.teleport(LastMiningPosition, WEST) | |
player.say("start mining") | |
} | |
function CheckForGravel () { | |
while (blocks.testForBlock(GRASS, positions.add( | |
agent.getPosition(), | |
pos(0, 0, -1) | |
))) { | |
agent.destroy(FORWARD) | |
CheckForGravel() | |
} | |
} | |
player.onChat("start mining", function (num1) { | |
while (true) { | |
for (let index = 0; index < 100; index++) { | |
WalkAndAvoidLava() | |
} | |
GoHomeWithLoot() | |
} | |
}) | |
player.onChat("back", function () { | |
player.teleport(lastPlayerPosition) | |
mobs.clearEffect(mobs.target(LOCAL_PLAYER)) | |
}) | |
function MakeStaircase () { | |
for (let index = 0; index < 1; index++) { | |
if (agent.detect(AgentDetection.Block, FORWARD)) { | |
while (agent.detect(AgentDetection.Block, FORWARD)) { | |
agent.destroy(FORWARD) | |
} | |
} | |
if (agent.detect(AgentDetection.Block, DOWN)) { | |
agent.destroy(DOWN) | |
} | |
agent.move(DOWN, 1) | |
agent.move(FORWARD, 1) | |
} | |
} | |
function MakeTunnel () { | |
CheckForGravel() | |
if (agent.detect(AgentDetection.Block, FORWARD)) { | |
agent.destroy(FORWARD) | |
} | |
TestForLavaAndRemoveIfFound() | |
if (agent.detect(AgentDetection.Block, LEFT)) { | |
agent.destroy(LEFT) | |
} | |
TestForLavaAndRemoveIfFound() | |
agent.move(LEFT, 1) | |
if (agent.detect(AgentDetection.Block, UP)) { | |
agent.destroy(UP) | |
} | |
TestForLavaAndRemoveIfFound() | |
agent.move(UP, 1) | |
if (agent.detect(AgentDetection.Block, RIGHT)) { | |
agent.destroy(RIGHT) | |
} | |
TestForLavaAndRemoveIfFound() | |
agent.move(RIGHT, 1) | |
agent.move(DOWN, 1) | |
agent.move(FORWARD, 1) | |
} | |
/** | |
* Makes a 2 wide and 2 tall tunnel and moves 1 forward | |
*/ | |
function TestForLavaAndRemoveIfFound () { | |
if (blocks.testForBlock(LAVA, positions.add( | |
agent.getPosition(), | |
pos(0, -1, -1) | |
))) { | |
player.say("my Agent found lava!") | |
agent.setItem(WATER, 1, 1) | |
blocks.place(WATER, positions.add( | |
agent.getPosition(), | |
pos(0, 0, -1) | |
)) | |
loops.pause(500) | |
blocks.place(AIR, positions.add( | |
agent.getPosition(), | |
pos(0, 0, -1) | |
)) | |
} | |
} | |
player.onChat("tptome", function () { | |
agent.teleportToPlayer() | |
}) | |
player.onChat("gohome", function () { | |
GoHomeWithLoot() | |
}) | |
function CollectResources () { | |
agent.collectAll() | |
} | |
player.onChat("stop mining", function () { | |
player.tell(mobs.target(LOCAL_PLAYER), "I'll wait") | |
}) | |
player.onChat("tominer", function () { | |
lastPlayerPosition = player.position() | |
player.teleport(agent.getPosition()) | |
mobs.applyEffect(NIGHT_VISION, mobs.target(LOCAL_PLAYER), 600, 255) | |
}) | |
function WalkAndAvoidLava () { | |
TestForLavaAndRemoveIfFound() | |
MinerLogic() | |
} | |
function MinerLogic () { | |
if (agent.getPosition().getValue(Axis.Y) == 12) { | |
MakeTunnel() | |
CollectResources() | |
} else { | |
MakeStaircase() | |
} | |
} | |
player.onChat("home", function () { | |
Home = player.position() | |
}) | |
let lastPlayerPosition: Position = null | |
let Home: Position = null | |
let LastMiningPosition: Position = null | |
LastMiningPosition = agent.getPosition() | |
agent.teleport(LastMiningPosition, NORTH) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment