Advertisement
RodrickLord

Crate API

Apr 7th, 2015
1,013
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.95 KB | None | 0 0
  1. --[[    CrateAPI
  2.   Easily summon chests
  3.       with items!
  4.      By RodrickLord ]]
  5.  
  6. if not commands then
  7.   error("Crate API needs a Command Computer!", 0)
  8. end
  9.  
  10. -- Thx awsumben13 for help in this function
  11. local function formatTable(t)
  12.   local s = ""
  13.   for i, v in ipairs(t) do
  14.     if type(v) == "table" then
  15.       local tagType = ""
  16.       if type(v.id) == "string" and not commands.blockdata then
  17.         error("Crate API: Name IDs aren't supported in 1.7.10",0)
  18.       elseif type(v.id == "number" and commands.blockdata then
  19.         error("Crate API: Number IDs aren't supported in 1.8",0)
  20.       end
  21.       v.data = v.data or 0
  22.       s = s .. "," .. ("{id:%d,Count:%db,Slot:%db,Damage:%ds}"):format(v.id,v.count,v.slot,v.data)
  23.     end
  24.   end
  25.   return s:sub( 2 )
  26. end
  27.  
  28. function summonCrate(x,y,z,itemTable)
  29.   local items = formatTable(itemTable)
  30.   commands.summon("FallingSand",x,y,z,"{TileID:54,Time:1,TileEntityData:{Items:["..items.."]}}")
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement