Larvix

map/entity

Dec 16th, 2023 (edited)
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.08 KB | None | 0 0
  1. tileset = {
  2. Enderman = {"E",2,colors.purple},
  3. Zombie = {"Z",1,colors.green},
  4. ZombieVillager = {"Z",1,colors.green},
  5. ZombiePigman = {"Z",1,colors.orange},
  6. Blaze = {"B",0,colors.yellow},
  7. Slime = {"S",0,colors.green},
  8. Creeper = {"C",1,colors.green},
  9. Skeleton = {"S",1,colors.lightGray},
  10. WitherSkeleton = {"W",1,colors.lightGray},
  11. Spider = {"S",0,colors.gray},
  12. Witch = {"W",1,colors.green},
  13. Villager = {"v",1,colors.brown},
  14. Cow = {"c",1,colors.brown},
  15. Chicken = {"c",0,colors.white},
  16. Pig = {"p",0,colors.pink},
  17. Sheep = {"s",1,colors.white},
  18. Dog = {"d",0,colors.white},
  19. Cat = {"c",0,colors.yellow},
  20. Wolf = {"w",0,colors.white},
  21. Ozelot = {"o",0,colors.yellow},
  22. Horse = {"h",1,colors.brown},
  23. Crab = {"c",0,colors.orange},
  24. }
  25.  
  26. blacklist = {
  27. "minecraft:item_frame",
  28. "quark:glass_item_frame",
  29. "quark:colored_item_frame",
  30. "LeashKnot",
  31. }
  32.  
  33. maxX,maxY = term.getSize()
  34. getMobs = function()
  35.     level = {}
  36.     sensor = nil
  37.     if peripheral.find("neuralInterface") and peripheral.find("neuralInterface").hasModule("plethora:sensor") then
  38.         sensor = peripheral.wrap("back")
  39.         neural = true
  40.     else sensor = peripheral.find("plethora:sensor") end
  41.     if sensor == nil then
  42.         term.setCursorPos(1,maxY)
  43.         term.clearLine()
  44.         print("Requires Plethora Entity Sensor!")
  45.     else
  46.         entities = sensor.sense()
  47.         if selected == nil then selected = 0 end
  48.         if size == nil then size = 17 end
  49.         if selected > 8 then selected = 8
  50.         elseif selected < -8 then selected = -8 end
  51.         if size > 17 then size = 17
  52.         elseif size < 1 then size = 1 end
  53.         indent = math.floor((17-size)/2)
  54.         if size < maxY then
  55.             offset = 3 + math.floor((11-size)/2)
  56.         else offset = 3 end
  57.  
  58.         for e = 1,#entities do
  59.             isAllowed = true
  60.             for b = 1,#blacklist do
  61.                 if entities[e].name == blacklist[b] then
  62.                     table.remove(entities[e])
  63.                     isAllowed = false
  64.                 end
  65.             end
  66.             if isAllowed then
  67.                 entities[e].y = math.floor(entities[e].y)
  68.                 if entities[e].x - math.floor(entities[e].x) > 0.85 then
  69.                     entities[e].x = math.ceil(entities[e].x)+9
  70.                 else entities[e].x = math.floor(entities[e].x)+9 end
  71.                 if entities[e].z - math.floor(entities[e].z) > 0.85 then
  72.                     entities[e].z = math.ceil(entities[e].z)+9
  73.                 else entities[e].z = math.floor(entities[e].z)+9 end
  74.                 tileFound = false
  75.                 for k,v in pairs(tileset) do
  76.                     if k == entities[e].name or k == entities[e].displayName then
  77.                         for l = 0,(v[2]) do
  78.                             if entities[e].y - l == selected then
  79.                                 entities[e].tile = v[1]
  80.                                 entities[e].colour = v[3]
  81.                                 entities[e].y = selected
  82.                                 table.insert(level, entities[e])
  83.                                 tileFound = true
  84.                             end
  85.                         end
  86.                     end
  87.                 end
  88.                 if not tileFound and (entities[e].y == selected) then
  89.                     hungry = sensor.getMetaByName(entities[e].name).food
  90.                     if hungry == nil then
  91.                         entities[e].tile = "?"
  92.                         entities[e].colour = colors.white
  93.                         table.insert(level, entities[e])
  94.                     elseif (tonumber(entities[e].y) == selected) or (tonumber(entities[e].y) - 1 == selected) then
  95.                         entities[e].tile = "\2"
  96.                         entities[e].colour = colors.white
  97.                         table.insert(level, entities[e])
  98.                     end
  99.                 end
  100.             end
  101.         end
  102.     end
  103. end
  104.  
  105. writeText = function()
  106.     if size > 17 then size = 17
  107.     elseif size < 1 then size = 1 end
  108.     if selected < 0 then lPref = "Y:"
  109.     else lPref = "Y: " end
  110.     if size < 10 then sPref = "S: "
  111.     else sPref = "S:" end
  112.  
  113.     levelString = lPref..tostring(selected)
  114.     scaleString = sPref..tostring(size)
  115.  
  116.     term.setCursorPos(maxX-#levelString+1,1)
  117.     write(levelString)
  118.     term.setCursorPos(maxX-#scaleString+1,2)
  119.     write(scaleString)
  120.  
  121.     term.setCursorPos(1,maxY)
  122.     term.clearLine()
  123.     if selectedMob ~= nil then
  124.         if #selectedMob < maxX then write(selectedMob)
  125.         else write(string.sub(selectedMob,1,maxX-3).."...") end
  126.     end
  127. end
  128.  
  129. drawMap = function()
  130.     for row = 1+offset,17-offset do
  131.         for col = 1+indent,17-indent do
  132.             filled = false
  133.             term.setCursorPos(((col*2)-1),row-3)
  134.             for mob = 1,#level do
  135.                 if (level[mob].z == row) and (level[mob].x == col) then
  136.                     if term.isColour() then term.setTextColour(tonumber(level[mob].colour)) end
  137.                     write(level[mob].tile)
  138.                     if term.isColour() then term.setTextColour(colors.white) end
  139.                     filled = true
  140.                 end
  141.             end
  142.             if not filled then write(" ") end
  143.         end
  144.     end
  145. end
  146.  
  147. lastLevel = {false}
  148. checkMobs = function()
  149.     while true do
  150.         getMobs()
  151.         if change or (textutils.serialise(level) ~= textutils.serialise(lastLevel)) then
  152.             shell.run("clear")
  153.             drawMap()
  154.             writeText()
  155.             lastLevel = level
  156.             change = false
  157.         end
  158.         sleep(0)
  159.     end
  160. end
  161.  
  162. selectedMobs = {}
  163. checkKeys = function()
  164.     while true do
  165.         os.startTimer(1)
  166.         evt, e1, e2, e3 = os.pullEvent()
  167.         if evt == "key" then
  168.             if e1 == keys.up then
  169.                 selected = selected + 1
  170.                 change = true
  171.             elseif e1 == keys.down then
  172.                 selected = selected - 1
  173.                 change = true
  174.             elseif e1 == keys.right then
  175.                 size = size + 2
  176.                 change = true
  177.             elseif e1 == keys.left then
  178.                 size = size - 2
  179.                 change = true
  180.             elseif e1 == keys.space then
  181.                 selectedMob = nil
  182.                 change = true
  183.             end
  184.         elseif evt == "mouse_scroll" then
  185.             if e1 == 1 then
  186.                 selected = selected - 1
  187.                 change = true
  188.             elseif e1 == -1 then
  189.                 selected = selected + 1
  190.                 change = true
  191.             end
  192.         elseif evt == "mouse_click" and (e1==1) then
  193.             for i = 1,#level do
  194.                 if (tonumber(textutils.serialise(level[i].x))*2)-1 == tonumber(e2) then
  195.                     if tonumber(textutils.serialise(level[i].z))-3 == tonumber(e3) then
  196.                         if level[i].name ~= level[i].displayName:gsub(" ","") then
  197.                             selectedMob = level[i].displayName.." ("..level[i].name..")"
  198.                         else selectedMob = level[i].displayName end
  199.                         change = true
  200.                     end
  201.                 end
  202.                 if change == true then break end
  203.             end
  204.         end
  205.     end
  206. end
  207.  
  208. parallel.waitForAny(checkKeys, checkMobs)
  209.  
  210.  
Advertisement
Add Comment
Please, Sign In to add comment