Solved NBTTagCompound.getList("TileEntities") and NBTTagCompound.getList("Items", 8)

Discussion in 'Plugin Development' started by SoS_Dylan, Dec 24, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    SoS_Dylan

    The new way that NBT's getList function has changed from .getList(String arg0) to .getList(String arg0, int arg1). I need some help with updating it because it is currently not working for me, ive tried a few things but they didn't work.
    Heres my code:
    SchematicUtils.java
    Code:java
    1. public static Schematic loadScheamtic(File file) {
    2. try {
    3. InputStream fis = new FileInputStream(file);
    4. NBTTagCompound nbtdata = NBTCompressedStreamTools.a(fis);
    5.  
    6. short width = nbtdata.getShort("Width");
    7. short height = nbtdata.getShort("Height");
    8. short length = nbtdata.getShort("Length");
    9.  
    10. byte[] blocks = nbtdata.getByteArray("Blocks");
    11. byte[] data = nbtdata.getByteArray("Data");
    12.  
    13. NBTTagList tileentities = nbtdata.getList("TileEntities", 8);
    14.  
    15. fis.close();
    16.  
    17. return new Schematic(file.getName(), width, height, length, "", blocks, data, tileentities);
    18. } catch (Exception e) {
    19. e.printStackTrace();
    20. }
    21. return null;
    22. }

    MapFFA8.java
    Code:java
    1. NBTTagList tileentities = platformsList.get(0).getSchematic().getTileEntities(); // This is getting the variable 'tileentities' from above.
    2.  
    3. for (Location loc : cp) {
    4. for (int i = 0; i < tileentities.size(); i++) {
    5. if (SchematicUtils.getValue(SchematicUtils.toArray(tileentities.get(i).toString())[0]).equalsIgnoreCase("Sign")) {
    6. try {
    7. int x = Integer.parseInt(SchematicUtils.getValue(SchematicUtils.toArray(tileentities.get(i).toString())[7]));
    8. int y = Integer.parseInt(SchematicUtils.getValue(SchematicUtils.toArray(tileentities.get(i).toString())[6]));
    9. int z = Integer.parseInt(SchematicUtils.getValue(SchematicUtils.toArray(tileentities.get(i).toString())[5]));
    10.  
    11. String line0 = SchematicUtils.getValue(SchematicUtils.toArray(tileentities.get(i).toString())[1]);
    12. String line1 = SchematicUtils.getValue(SchematicUtils.toArray(tileentities.get(i).toString())[2]);
    13. String line2 = SchematicUtils.getValue(SchematicUtils.toArray(tileentities.get(i).toString())[3]);
    14. String line3 = SchematicUtils.getValue(SchematicUtils.toArray(tileentities.get(i).toString())[4]);
    15.  
    16. if (loc.clone().add(x, y, z).getBlock().getState() instanceof Sign) {
    17. Sign sign = (Sign) loc.clone().add(x, y, z).getBlock().getState();
    18.  
    19. sign.setLine(0, line0);
    20. sign.setLine(1, line1);
    21. sign.setLine(2, line2);
    22. sign.setLine(3, line3);
    23.  
    24. sign.update();
    25. }
    26. } catch (Exception ex) {
    27. ex.printStackTrace();
    28. }
    29. } else if (SchematicUtils.getValue(SchematicUtils.toArray(tileentities.get(i).toString())[1]).equalsIgnoreCase("Chest")) {
    30. try {
    31. for (int j = 0; j < ((NBTTagCompound) tileentities.get(0)).getList("Items", 8).size(); j++) {
    32. int x = Integer.parseInt(SchematicUtils.getValue(SchematicUtils.toArray(tileentities.get(i).toString())[4]));
    33. int y = Integer.parseInt(SchematicUtils.getValue(SchematicUtils.toArray(tileentities.get(i).toString())[3]));
    34. int z = Integer.parseInt(SchematicUtils.getValue(SchematicUtils.toArray(tileentities.get(i).toString())[2]));
    35.  
    36. int type = Integer.parseInt(SchematicUtils.getValue(SchematicUtils.toArray(((NBTTagCompound) tileentities.get(i)).getList("Items", 8).get(j).toString())[0]));
    37. short damage = Short.parseShort(SchematicUtils.getValue(SchematicUtils.toArray(((NBTTagCompound) tileentities.get(i)).getList("Items", 8).get(j).toString())[1]));
    38. int amount = Integer.parseInt(SchematicUtils.getValue(SchematicUtils.toArray(((NBTTagCompound) tileentities.get(i)).getList("Items", 8).get(j).toString())[2]));
    39. int slot = Integer.parseInt(SchematicUtils.getValue(SchematicUtils.toArray(((NBTTagCompound) tileentities.get(i)).getList("Items", 8).get(j).toString())[3]));
    40.  
    41. if (loc.clone().add(x, y, z).getBlock().getState() instanceof Chest) {
    42. Chest chest = (Chest) loc.clone().add(x, y, z).getBlock().getState();
    43. chest.getBlockInventory().setItem(slot, new ItemStack(type, amount, damage));
    44. }
    45. }
    46. } catch (Exception ex) {
    47. ex.printStackTrace();
    48. }
    49. }
    50. }
    51. }


    I looked at the code and I made this,
    Code:
    0:"END", 1:"BYTE", 2:"SHORT", 3:"INT", 4:"LONG", 5:"FLOAT", 6:"DOUBLE", 7:"BYTE[]", 8:"STRING", 9:"LIST", 10:"COMPOUND", 11:"INT[]"
    The int before the String is what you will want to put in arg1, eg.
    Code:java
    1. String thisIsAString = NBTTAGCompound.getList("WhateverYouWant", 8);
    and
    Code:java
    1. int[] thisIsAString = NBTTAGCompound.getList("WhateverYouWant", 11);


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page