Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #after launching the program, the agent is teleported to the player
- agent.teleport_to_player()
- '''
- Project specifications:
- slot 1 - rails
- slot 2 - powered rails
- slot 3 - stone
- slot 4 - redstone
- '''
- def refillBlocks():
- #adding 64 rails in slot 1 to the agent
- agent.set_item(RAIL, 64, 1)
- agent.set_item(POWERED_RAIL, 64, 2)
- agent.set_item(STONE, 64, 3)
- agent.set_item(REDSTONE_BLOCK, 64, 4)
- def rollerCoasterBuilding(railAmount):
- #the varialbe storing the current number of built rails, when calling the function we can decide how many rails we want to build
- currentRailAmount = 0
- #function refilling agent's slots with proper blocks so he can keep building
- refillBlocks()
- #teleporting the agent, we care about his direction which we will modify later
- agent.teleport(agent.get_position(),SOUTH)
- #when moving, agent will place blocks from the selected spot
- agent.set_assist(PLACE_ON_MOVE, True)
- #when moving, agent destroys blocks in his way
- agent.set_assist(DESTROY_OBSTACLES, True)
- #the loop works until the correct amount of rails is built
- while currentRailAmount < railAmount:
- #clearing path before and after the track
- if agent.detect(AgentDetection.BLOCK, UP) or agent.detect(AgentDetection.BLOCK, FORWARD):
- agent.destroy(UP)
- #if the agent detects that he is in the air and there is nothing to build on, he will place stone block
- elif agent.inspect(AgentInspection.BLOCK, DOWN) == 0 or agent.inspect(AgentInspection.BLOCK, DOWN) == 9:
- agent.set_slot(3)
- agent.place(DOWN)
- else:
- #if there are no obstacles, setting the slot to rails and moving forward.
- agent.set_slot(1)
- agent.move(FORWARD, 1)
- currentRailAmount += 1
- player.say("building finished!")
- player.on_chat("b",rollerCoasterBuilding)
Add Comment
Please, Sign In to add comment