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()
- #this varialbe will be overwritten in the function which will let us build the rails up and down in the correct direction
- lastDirection = CompassDirection.SOUTH
- '''
- 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, direction, railType):
- #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()
- # creating a global variable in which we will store the last direction of agent
- global lastDirection
- #defining the direction of agent
- if direction == 1:
- currentAgentDirection = CompassDirection.SOUTH
- elif direction == 2:
- currentAgentDirection = CompassDirection.NORTH
- elif direction == 3:
- currentAgentDirection = CompassDirection.EAST
- elif direction == 4:
- currentAgentDirection = CompassDirection.WEST
- #direction 5 - down, 6 - up
- else:
- currentAgentDirection = lastDirection
- #teleporting the agent, we care about his direction which we will modify later
- agent.teleport(agent.get_position(),currentAgentDirection)
- #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:
- if railType == 1:
- agent.set_slot(3)
- else:
- agent.set_slot(4)
- agent.place(DOWN)
- else:
- #if there are no obstacles, setting the slot to rails and moving forward.
- if railType == 1:
- agent.set_slot(1)
- else:
- agent.set_slot(2)
- # building the rail down
- if direction == 5:
- agent.move(FORWARD, 1)
- agent.destroy(UP)
- agent.set_assist(PLACE_ON_MOVE, False)
- agent.move(DOWN, 1)
- agent.set_assist(PLACE_ON_MOVE, True)
- currentRailAmount += 1
- # building the rail up
- elif direction == 6:
- agent.move(FORWARD, 1)
- agent.destroy(UP)
- agent.set_assist(PLACE_ON_MOVE, False)
- agent.move(UP,2)
- agent.destroy(UP)
- agent.move(DOWN,1)
- agent.set_assist(PLACE_ON_MOVE, True)
- currentRailAmount += 1
- else:
- agent.move(FORWARD, 1)
- currentRailAmount += 1
- player.say("building finished!")
- player.on_chat("b",rollerCoasterBuilding)
Add Comment
Please, Sign In to add comment