t8rt0t

inventoryObfuscator.lua

Jul 7th, 2024 (edited)
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.46 KB | None | 0 0
  1. local inv = peripheral.find("inventoryManager")
  2. local anvil = peripheral.find("anvil_interface")
  3. local chest = peripheral.find("minecraft:chest")
  4. local chestName = peripheral.getName(chest)
  5. local sc = string.char(167)
  6.  
  7. local rarity_map = {sc .. "f",sc.."e",sc.."b",sc.."d"}
  8.  
  9. local function pullItem(fromSlot,toSlot)
  10.     inv.removeItemFromPlayer("up",{fromSlot=fromSlot,toSlot=toSlot,count=64})
  11. end
  12.  
  13. local function pushItem(fromSlot,toSlot)
  14.     inv.addItemToPlayer("up",{fromSlot=fromSlot,toSlot=toSlot,count=64})
  15. end
  16.  
  17. local rarities = {
  18.     ["minecraft:creeper_banner_pattern"] = 2,
  19.     ["minecraft:skull_banner_pattern"] = 2,
  20.     ["minecraft:experience_bottle"] = 2,
  21.     ["minecraft:dragon_breath"] = 2,
  22.     ["minecraft:elytra"] = 2,
  23.     ["#forge:heads"] = 2,
  24.     ["minecraft:heart_of_the_sea"] = 2,
  25.     ["minecraft:nether_star"] = 2,
  26.     ["minecraft:totem_of_undying"] = 2,
  27.     ["minecraft:enchanted_book"] = 2,
  28.     ["minecraft:beacon"] = 3,
  29.     ["minecraft:conduit"] = 3,
  30.     ["minecraft:end_crystal"] = 3,
  31.     ["minecraft:golden_apple"] = 3,
  32.     ["#minecraft:music_discs"] = 3,
  33.     ["minecraft:mojang_banner_pattern"] = 4,
  34.     ["minecraft:dragon_egg"] = 4,
  35.     ["minecraft:enchanted_golden_apple"] = 4,
  36.     ["create:extendo_grip"] = 2,
  37.     ["create_wand_of_symmetry"] = 2,
  38.     ["create_sa:experience_pickaxe"] = 2,
  39.     ["create_sa:experience_axe"] = 2,
  40.     ["create_sa:experience_shovel"] = 2,
  41.     ["create_sa:experience_sword"] = 2,
  42.     ["create_sa:heap_of_experience"] = 2,
  43.     ["create_sa:portable_drill"] = 2,
  44.     ["create_sa:grapplin_whisk"] = 2,
  45.     ["create_sa:block_picker"] = 2,
  46.     ["craete_enchantment_industry:hyper_experience_bottle"] = 3,
  47.     ["create_things_and_misc:mending_rune"] = 2,
  48.     ["supplementaries:globe"] = 3,
  49.     ["supplementaries:globe_sepia"] = 3,
  50.     ["supplementaries:bomb"] = 3,
  51.     ["supplementaries:bomb_blue"] = 4,
  52.     ["supplementaries:quiver"] = 3,
  53.     ["ad_astra:moon_globe"] = 3,
  54.     ["tfmg:gasoline_engine"] = 2,
  55.     ["tfmg:gasoline_engine_back"] = 2,
  56.     ["tfmg:lpg_engine"] = 2,
  57.     ["tfmg:lpg_engine_back"] = 2,
  58.     ["tfmg:turbine_engine"] = 2,
  59.     ["tfmg:turbine_engine_back"] = 2,
  60.     ["tfmg:radial_engine"] = 2,
  61.     ["tfmg:large_radial_engine"] = 2,
  62.     ["tfmg:compact_engine"] = 2,
  63.     ["securitycraft:codebreaker"] = 3,
  64.     ["create_jetpack:jetpack"] = 3,
  65.     ["create_jetpack:netherite_jetpack"] = 4
  66. }
  67. --setmetatable(rarities,{__index = function() return 1 end})
  68. local function serialiseName(name)
  69.     local json = textutils.unserialiseJSON(name)
  70.     if not json then return nil end
  71.     local itemstr = sc .. "o" .. (json.text or "")
  72.     for _,component in ipairs(json) do
  73.         if type(component) == "string" then
  74.             itemstr = itemstr .. component
  75.         else
  76.             itemstr = itemstr .. component.text
  77.         end
  78.     end
  79.     return itemstr:gsub("^"..sc.."[febd]",""):gsub(sc.."k","")
  80. end
  81.  
  82. local function getItemColor(itemDetail)
  83.     local rarity = 1
  84.     for k,v in ipairs(itemDetail.tags or{}) do
  85.         if rarities["#"..v] then rarity = math.max(rarities["#"..v],rarity) end
  86.     end
  87.     if itemDetail.nbt and itemDetail.nbt.Enchantments then
  88.         rarity = math.max(rarity,3)
  89.     end
  90.     if rarities[itemDetail.name] then rarity = math.max(rarities,rarities[itemDetail.name]) end
  91.     return rarity_map[rarity]
  92. end
  93.  
  94. local function getItemRename(item)
  95.     local color = getItemColor(item)
  96.     local itemName = item.displayName:sub(2,-2)
  97.     if item.nbt and item.nbt.display and item.nbt.display.Name then
  98.         itemName = serialiseName(item.nbt.display.Name,color)
  99.     end
  100.     return color .. sc .. "k".. itemName
  101. end
  102.  
  103. local function loop()
  104.     local action_slot = 0
  105.     for i=1,chest.size() do
  106.         if not chest.getItemDetail(i) then
  107.             action_slot = i
  108.             break
  109.         end
  110.     end
  111.     if action_slot == 0 then error("make room for action") end
  112.     print("Action Slot",action_slot)
  113.     for k,v in pairs(inv.list()) do
  114.         if v.slot >= 9 and not v.displayName:match("^%["..sc.."[febd]"..sc.."k") then
  115.             local name = getItemRename(v)
  116.             print(v.slot..":",v.displayName,"->",name,";Press any key to continue.")
  117.             os.pullEvent("key")
  118.             pullItem(v.slot,action_slot - 1)
  119.             sleep(0)
  120.             pcall(function() print(anvil.rename(chestName,action_slot,name)) end)
  121.             sleep(0)
  122.             pushItem(action_slot - 1,v.slot)
  123.             print("success")
  124.         end
  125.     end
  126. end
  127. loop()
Advertisement
Add Comment
Please, Sign In to add comment