This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ItsRodrick's profile picture

Crate API - Summon chests with items!

Started by ItsRodrick, 07 April 2015 - 06:56 PM
ItsRodrick #1
Posted 07 April 2015 - 08:56 PM
Crate API

Easily summon chests with items!


I and some friends were working in a CC map, and we needed a way to give items to players. Some time ago, I used command blocks and played in the snapshots a lot, so I thought of spawning a Chest as a Falling Sand from the sky. But NBT tags are a bit hard, so I made this utility to help us with that.

Note: it summons a FALLING SAND entity, so you can summon it at y150 and it'll fall from the sky, like a Supply Crate :P/>

Download: pastebin get QNhhry4M crate

Usage:

os.loadAPI("crate")

-- First, you need to make a table with all the items.
items = {
  {id = 322, count = 1, slot = 4, data = 1}, -- note: data is optional
  {id = 264, count = 64, slot = 13},
  {id = 276, count = 1, slot = 22}
}

x, y, z = commands.getBlockPosition()
-- Then, summonCrate(xCoords, yCoords, zCoords, table with items)
crate.summonCrate(x, 200, z, items)


Oh, and thanks awsumben13 for the help with some var to NBT things ;)/>
Edited on 07 April 2015 - 11:36 PM
Mackan90096 #2
Posted 11 April 2015 - 11:49 AM
It just summons a chest item from my experiences.
The chest doesn't even have NBT tags.

Please fix this.

- Mackan
ItsRodrick #3
Posted 11 April 2015 - 03:16 PM
It does. The chests NBT tags are inside the 'TileEntityData' tag.
Wojbie #4
Posted 11 April 2015 - 07:44 PM
Does your api support use of names like "Minecraft:dirt" instead of Id numbers? If not can I suggest that?
ItsRodrick #5
Posted 11 April 2015 - 11:26 PM
I would do that, but it's impossible before 1.8. Only after 1.8 the NBT tag "id" is a "String tag", before (1.7.10) it's a "Short tag", so we can only have numbers.
Info at NBT tags at Minecraft Wiki

Edit: the only way to do it would have a "Name ID to number converter", but it would be hard to do… (if id = "minecraft:stone" then id = 1 end… if id = "minecraft:dirt" then id = 2 end…)

Edit 2: Pushed a 1 line update just to say that Name IDs aren't supported in 1.7.10. :P/>
Edited on 11 April 2015 - 09:33 PM
Wojbie #6
Posted 12 April 2015 - 04:46 AM
A okeyo. Name id's are semi supported in 1.7.10 was not sure if command you used allowed them. I guess not ;p
Making name convener is pointless - too many mods to bother doing that plus id numbers can be different between configs in same mod.
Edited on 12 April 2015 - 02:46 AM
moomoomoo3O9 #7
Posted 07 June 2015 - 02:16 AM
Would this help for the block names? I know it might not seem useful, but I think you could make use of this.
Program I used to make that table
List I originally got the names from

Modify, copy, redistribute, and use the program as you wish. I needed it for one of my programs anyways.
Edited on 07 June 2015 - 12:19 AM
ItsRodrick #8
Posted 07 June 2015 - 02:08 PM
Thanks, and great program. But, I think Ill wait for 1.8. Its too simple to get numerical ids (F3 + H).

But if people ask for it, Ill add :)/>
biggest yikes #9
Posted 09 June 2015 - 11:45 PM
numerical IDs were deprecated in Minecraft 1.7 and totally removed in Minecraft 1.8. You should probably migrate sooner than later.
ItsRodrick #10
Posted 10 June 2015 - 01:57 AM
When CC gets updated to 1.8, I'll just need to change a letter. (Seriously xD)
Bomb Bloke #11
Posted 10 June 2015 - 02:50 AM
In theory, you should be able to detect whether your script is running under MC 1.7.10 or 1.8 by checking which functions are available within the commands API.

Eg:

if commands.blockdata then  -- If ComputerCraft detected the 1.8 "blockdata" command as being available, then...
ItsRodrick #12
Posted 15 January 2016 - 11:51 PM
So, with CC for 1.8 released, I came back from a while…
Support for BOTH 1.7.10 and 1.8 should be working. I couldn't test it, but if you find any errors, please tell me.
Edited on 15 January 2016 - 10:52 PM
PossieTV #13
Posted 23 June 2016 - 09:57 PM
This is really well done, do you mind if I use this on a server I'm trying to put together?
jv110 #14
Posted 24 June 2016 - 12:07 AM
What were you talking about? Name IDs are supported on 1.7.10. Numeric IDs were deprecated since 1.7. And I don't think anybody uses 1.6 anymore.
Bomb Bloke #15
Posted 24 June 2016 - 01:45 AM
Name IDs are supported for some things in 1.7.10, but the support isn't across-the-board within NBT tags. I also had to use numeric IDs for cPrint.
randomdude999 #16
Posted 04 July 2016 - 06:34 PM
Might I suggest the ability to add custom NBT data to items? Would be useful for custom weapons, for example.