Advertisement
jaklsfjlsak

智能简化激光护盾 可用

Mar 29th, 2025 (edited)
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.61 KB | None | 0 0
  1. local OffsetValue = -3
  2. local shield = peripheral.find("warpdriveForceFieldProjector")
  3. local lasers = peripheral.getNames()
  4. local lever = "front"
  5. local lastLx, lastLy, lastLz = 0, 0, 0
  6.  
  7. -- Calculate the offset position (still using OffsetValue)
  8. function shieldOffset(lx, ly, lz, fx, fy, fz)
  9.     local dx = lx - fx
  10.     local dy = ly - fy
  11.     local dz = lz - fz
  12.     local distance = math.sqrt(dx * dx + dy * dy + dz * dz)
  13.     dx = dx / distance
  14.     dy = dy / distance
  15.     dz = dz / distance
  16.     local t1x = lx + dx * OffsetValue
  17.     local t1y = ly + dy * OffsetValue
  18.     local t1z = lz + dz * OffsetValue
  19.     return t1x, t1y, t1z, distance
  20. end
  21.  
  22. -- Download configuration file if missing.
  23. if not fs.exists("conf") then
  24.     shell.run("pastebin get 38M5cNbZ conf")
  25.     term.clear()
  26. end
  27.  
  28. -- Filter peripherals: keep only warpdriveLaserCameras and set their beam frequency.
  29. for i = #lasers, 1, -1 do
  30.     if peripheral.getType(lasers[i]) ~= "warpdriveLaserCamera" then
  31.         table.remove(lasers, i)
  32.     else
  33.         peripheral.wrap(lasers[i]).beamFrequency(1420)
  34.     end
  35. end
  36.  
  37. print("Control System Online, Toggle Redstone To Toggle Shields, Press C to Configure")
  38.  
  39. -- Determine shield range based on upgrades.
  40. local _, upgrades = shield.getUpgrades()
  41. local Size
  42. if upgrades:match("1/4 x Range") then
  43.     Size = 16
  44. elseif upgrades:match("2/4 x Range") then
  45.     Size = 32
  46. elseif upgrades:match("3/4 x Range") then
  47.     Size = 48
  48. elseif upgrades:match("4/4 x Range") then
  49.     Size = 64
  50. elseif upgrades:match("0/4 x Range") then
  51.     Size = 0
  52. end
  53.  
  54. while true do
  55.     local event, keyOrLaser, lx, ly, lz, block, _, _, _, type, metadata, resistance = os.pullEvent()
  56.  
  57.     if event == "laserScanning" then
  58.         lastLx, lastLy, lastLz = tonumber(lx), tonumber(ly), tonumber(lz)
  59.         local fx, fy, fz = shield.getLocalPosition()
  60.         local t1x, t1y, t1z, distance = shieldOffset(lastLx, lastLy, lastLz, fx, fy, fz)
  61.  
  62.         local tx = (t1x - fx) / Size
  63.         local ty = (t1y - fy) / Size
  64.         local tz = (t1z - fz) / Size
  65.  
  66.         shield.translation(tx, ty, tz)
  67.         print("Laser Coordinates: (" .. lastLx .. ", " .. lastLy .. ", " .. lastLz .. ")")
  68.         print("Translated to: (" .. tx .. ", " .. ty .. ", " .. tz .. ")")
  69.        
  70.     elseif event == "redstone" then
  71.         local on = redstone.getAnalogInput(lever)
  72.         if on > 6 then
  73.             shield.enable(true)
  74.         elseif on < 5 then
  75.             shield.enable(false)
  76.         end
  77.     elseif event == "key" and keyOrLaser == 46 then
  78.         print("C key pressed, running 'conf' script...")
  79.         shell.run("conf")
  80.     end
  81. end
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement