Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- -- Compas
- -- Get Turtle orientation (facing north, east, south or west)
- -- ComputerCraft 1.76
- -- Require Turtle
- --
- -- author: SukaiPoppuGo
- -- licence: CC BY-NC-SA 4.0
- -- https://creativecommons.org/licenses/by-nc-sa/4.0/
- --
- slot = ...
- if not slot or not tonumber(slot) or not turtle.select(tonumber(slot)) then
- print([[Usage: compas <slot>
- slot provided by a block with facing block.state]])
- return false
- end
- --setup
- turtle.select(tonumber(slot))
- turtle.placeUp()
- local b,d,s = turtle.inspectUp()
- if not b then
- print(s)
- return false
- end
- local dir2num = {
- ["north"]=1,
- ["east"]=2,
- ["south"]=3,
- ["west"]=4,
- }
- local num2dir = {
- "north",
- "east",
- "south",
- "west",
- }
- --Database
- local tip = {
- --forward
- ["minecraft:brick_stairs"]=0,
- ["minecraft:sandstone_stairs"]=0,
- ["minecraft:red_sandstone_stairs"]=0,
- ["minecraft:stone_brick_stairs"]=0,
- ["minecraft:nether_brick_stairs"]=0,
- ["minecraft:oak_stairs"]=0,
- ["minecraft:dark_oak_stairs"]=0,
- ["minecraft:acacia_stairs"]=0,
- ["minecraft:spruce_stairs"]=0,
- ["minecraft:birch_stairs"]=0,
- ["minecraft:jungle_stairs"]=0,
- ["minecraft:quartz_stairs"]=0,
- --inverted
- ["minecraft:chest"]=2,
- ["minecraft:furnace"]=2,
- ["minecraft:trapped_chest"]=2,
- ["minecraft:ender_chest"]=2,
- ["minecraft:dropper"]=2,
- ["minecraft:dispenser"]=2,
- ["minecraft:powered_repeater"]=2,
- ["minecraft:unpowered_repeater"]=2,
- ["minecraft:unpowered_comparator"]=2,
- ["minecraft:pumpkin"]=2,
- ["minecraft:lit_pumpkin"]=2,
- ["computercraft:CC-Computer"]=2,
- ["computercraft:CC-command_computer"]=2,
- ["computercraft:CC-Peripheral"]=2,
- --ccw
- ["minecraft:anvil"]=-1,
- ["computercraft:CC-Turtle"]=-1,
- ["computercraft:CC-TurtleAdvanced"]=-1,
- }
- if d and d.state and d.state.facing then
- if tip[d.name] then
- -- local sDir = num2dir[((dir2num[d.state.facing]+tip[d.name]-1)%4)+1]
- local nRawDir = dir2num[d.state.facing] -- as north=1, east=2, south=3, west=4
- -- Correction according to how the block is positioned
- local nCorrect = nRawDir + tip[d.name]
- -- Determine the correct index by modulo
- local sDir = num2dir[((nCorrect-1)%4)+1]
- print(sDir)
- return sDir
- else
- print(string.format("Please update database with %s", d.name))
- return false
- end
- else
- print(string.format("%s has no block.state.facing property", d.name))
- return false
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement