Advertisement
posicat

/cattech/worldServer

Oct 14th, 2024 (edited)
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --File: /worldServer
  2.  
  3. dofile("/cattech/common.lua")
  4. dofile("/cattech/serverops.lua")
  5.  
  6. function putItemsInContainer(x,y,z,items)
  7. local itemsString = table.concat(items,",")
  8. local cmd = "/data merge block " .. x .. " " .. y .. " " .. z .. " {Items:[" .. itemsString .. "]}"
  9. log("debug","putItemInContainer : " .. cmd)
  10. executeCommand(cmd)
  11. end
  12.  
  13. function restockStore()
  14. local items = {}
  15. for slot = 0, 8 do
  16. table.insert(items ,"{Slot:" .. slot .. ",Count:" .. 1 .. ",id:\"minecraft:beef\"}")
  17. table.insert(items ,"{Slot:" .. slot+9 .. ",Count:" .. 1 .. ",id:\"minecraft:mutton\"}")
  18. table.insert(items ,"{Slot:" .. slot+18 .. ",Count:" .. 1 .. ",id:\"minecraft:porkchop\"}")
  19. end
  20. putItemsInContainer(43,88,51,items)
  21.  
  22. items = {}
  23. for slot = 0, 26 do
  24. table.insert(items ,"{Slot:" .. slot .. ",Count:" .. 1 .. ",id:\"minecraft:leather\"}")
  25. end
  26. putItemsInContainer(43,88,50,items)
  27.  
  28. items = {}
  29. for slot = 0, 8 do
  30. table.insert(items ,"{Slot:" .. slot .. ",Count:" .. 1 .. ",id:\"minecraft:rabbit\"}")
  31. table.insert(items ,"{Slot:" .. slot+9 .. ",Count:" .. 1 .. ",id:\"minecraft:rabbit_hide\"}")
  32. table.insert(items ,"{Slot:" .. slot+18 .. ",Count:" .. 1 .. ",id:\"minecraft:rabbit_foot\"}")
  33. end
  34. putItemsInContainer(43,88,49,items)
  35.  
  36. items = {}
  37. for slot = 0, 8 do
  38. table.insert(items ,"{Slot:" .. slot .. ",Count:" .. 1 .. ",id:\"minecraft:ink_sac\"}")
  39. table.insert(items ,"{Slot:" .. slot+9 .. ",Count:" .. 1 .. ",id:\"minecraft:glow_ink_sac\"}")
  40. end
  41. putItemsInContainer(43,88,48,items)
  42.  
  43. items = {}
  44. for slot = 0, 8 do
  45. table.insert(items ,"{Slot:" .. slot .. ",Count:" .. 1 .. ",id:\"minecraft:chicken\"}")
  46. table.insert(items ,"{Slot:" .. slot+9 .. ",Count:" .. 1 .. ",id:\"minecraft:feather\"}")
  47. end
  48. putItemsInContainer(43,88,47,items)
  49.  
  50. items = {}
  51. for slot = 0, 8 do
  52. table.insert(items ,"{Slot:" .. slot .. ",Count:" .. 1 .. ",id:\"waystones:waystone\"}")
  53. end
  54. putItemsInContainer(43,88,45,items)
  55.  
  56. end
  57.  
  58. -- Make sure the modem is open for communication
  59. local modemSide = "top"
  60. rednet.open(modemSide)
  61.  
  62. log("info","Listening as 'worldServer'")
  63.  
  64. local chunkTimeout = 0
  65. local restockTimeout = 0
  66. while true do
  67. local senderId, message, protocol = rednet.receive("worldServer",5)
  68.  
  69. if message then
  70. local processed=false
  71. local cmd,data = string.match(message, "^(%S+)%s+(.+)$")
  72.  
  73. if cmd == "chunkLoad" then
  74. log("debug","Chunkload coordinates received: " .. data)
  75.  
  76. local x, y, z = data:match("(%S+)%s+(%S+)%s+(%S+)")
  77.  
  78. addChunkLoad(tonumber(x),tonumber(y),tonumber(z),5)
  79. chunkTimeout = 0 -- Trigger a new check immediately.
  80.  
  81. processed=true
  82. end
  83.  
  84. if not processed then
  85. log("info","Unhandled [" .. senderId .. "]: " .. message)
  86. end
  87. end
  88.  
  89. io.write(".")
  90.  
  91. if (restockTimeout < deltaTime(0)) then
  92. log("debug","Restocking Store")
  93. restockStore()
  94. restockTimeout = deltaTime(60 * 10) -- Restock every 15 minutres
  95. end
  96.  
  97. log("debug",chunkTimeout .. "=C=" .. deltaTime(0))
  98. if (chunkTimeout < deltaTime(0)) then
  99. log("debug","Chunks Processing")
  100. handleChunkLoad()
  101. chunkTimeout = deltaTime(60 * 1) -- Check in 1 minute to handle chunks
  102. end
  103. end
  104.  
  105.  
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement