SHOW:
|
|
- or go back to the newest paste.
1 | #after launching the program, the agent is teleported to the player | |
2 | agent.teleport_to_player() | |
3 | ||
4 | ''' | |
5 | Project specifications: | |
6 | ||
7 | slot 1 - rails | |
8 | slot 2 - powered rails | |
9 | slot 3 - stone | |
10 | slot 4 - redstone | |
11 | ''' | |
12 | ||
13 | def refillBlocks(): | |
14 | #adding 64 rails in slot 1 to the agent | |
15 | agent.set_item(RAIL, 64, 1) | |
16 | agent.set_item(POWERED_RAIL, 64, 2) | |
17 | agent.set_item(STONE, 64, 3) | |
18 | agent.set_item(REDSTONE_BLOCK, 64, 4) | |
19 | ||
20 | ||
21 | def rollerCoasterBuilding(railAmount): | |
22 | #the varialbe storing the current number of built rails, when calling the function we can decide how many rails we want to build | |
23 | currentRailAmount = 0 | |
24 | #function refilling agent's slots with proper blocks so he can keep building | |
25 | refillBlocks() | |
26 | #teleporting the agent, we care about his direction which we will modify later | |
27 | agent.teleport(agent.get_position(),SOUTH) | |
28 | #when moving, agent will place blocks from the selected spot | |
29 | agent.set_assist(PLACE_ON_MOVE, True) | |
30 | #when moving, agent destroys blocks in his way | |
31 | agent.set_assist(DESTROY_OBSTACLES, True) | |
32 | ||
33 | #the loop works until the correct amount of rails is built | |
34 | while currentRailAmount < railAmount: | |
35 | #clearing path before and after the track | |
36 | if agent.detect(AgentDetection.BLOCK, UP) or agent.detect(AgentDetection.BLOCK, FORWARD): | |
37 | agent.destroy(UP) | |
38 | ||
39 | #if the agent detects that he is in the air and there is nothing to build on, he will place stone block | |
40 | elif agent.inspect(AgentInspection.BLOCK, DOWN) == 0 or agent.inspect(AgentInspection.BLOCK, DOWN) == 9: | |
41 | agent.set_slot(3) | |
42 | agent.place(DOWN) | |
43 | else: | |
44 | #if there are no obstacles, setting the slot to rails and moving forward. | |
45 | agent.set_slot(1) | |
46 | agent.move(FORWARD, 1) | |
47 | ||
48 | currentRailAmount += 1 | |
49 | ||
50 | player.say("building finished!") | |
51 | player.on_chat("b",rollerCoasterBuilding) |