Advertisement
Guest User

Untitled

a guest
Sep 12th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. @Override
  2. public void writeToNBT(@NotNull final NBTTagCompound compound)
  3. {
  4. super.writeToNBT(compound);
  5. @NotNull final NBTTagList tasksTagList = new NBTTagList();
  6. for (@NotNull final Map.Entry<ProductState, List<BakingProduct>> entry : tasks.entrySet())
  7. {
  8. if(!entry.getValue().isEmpty())
  9. {
  10. @NotNull final NBTTagCompound taskCompound = new NBTTagCompound();
  11. taskCompound.setInteger(TAG_STATE, entry.getKey().ordinal());
  12.  
  13. @NotNull final NBTTagList productsTaskList = new NBTTagList();
  14. for (@NotNull final BakingProduct bakingProduct : entry.getValue())
  15. {
  16. @NotNull final NBTTagCompound productCompound = new NBTTagCompound();
  17. bakingProduct.writeToNBT(productCompound);
  18. }
  19. taskCompound.setTag(TAG_PRODUCTS, productsTaskList);
  20. tasksTagList.appendTag(taskCompound);
  21. }
  22. }
  23. compound.setTag(TAG_TASKS, tasksTagList);
  24.  
  25. @NotNull final NBTTagList furnacesTagList = new NBTTagList();
  26. for (@NotNull final Map.Entry<BlockPos, BakingProduct> entry : furnaces.entrySet())
  27. {
  28. @NotNull final NBTTagCompound furnaceCompound = new NBTTagCompound();
  29. BlockPosUtil.writeToNBT(furnaceCompound, TAG_FURNACE_POS, entry.getKey());
  30.  
  31. if(entry.getValue() != null)
  32. {
  33. entry.getValue().writeToNBT(furnaceCompound);
  34. }
  35.  
  36. furnacesTagList.appendTag(furnaceCompound);
  37. }
  38. compound.setTag(TAG_FURNACES, furnacesTagList);
  39. }
  40.  
  41. @Override
  42. public void readFromNBT(@NotNull final NBTTagCompound compound)
  43. {
  44. tasks.clear();
  45. super.readFromNBT(compound);
  46. final NBTTagList taskTagList = compound.getTagList(TAG_TASKS, Constants.NBT.TAG_COMPOUND);
  47. for (int i = 0; i < taskTagList.tagCount(); ++i)
  48. {
  49. final NBTTagCompound taskCompound = taskTagList.getCompoundTagAt(i);
  50. final ProductState state = ProductState.values()[taskCompound.getInteger(TAG_STATE)];
  51. final List<BakingProduct> bakingProducts = new ArrayList<>();
  52.  
  53. final NBTTagList productTagList = taskCompound.getTagList(TAG_PRODUCTS, Constants.NBT.TAG_COMPOUND);
  54. for (int j = 0; j < productTagList.tagCount(); ++j)
  55. {
  56. final NBTTagCompound productCompound = taskTagList.getCompoundTagAt(i);
  57. final BakingProduct bakingProduct = BakingProduct.createFromNBT(productCompound);
  58. bakingProducts.add(bakingProduct);
  59. }
  60.  
  61. tasks.put(state, bakingProducts);
  62. }
  63.  
  64. final NBTTagList furnaceTagList = compound.getTagList(TAG_FURNACES, Constants.NBT.TAG_COMPOUND);
  65. for (int i = 0; i < furnaceTagList.tagCount(); ++i)
  66. {
  67. final NBTTagCompound furnaceCompound = furnaceTagList.getCompoundTagAt(i);
  68. final BlockPos pos = BlockPosUtil.readFromNBT(furnaceCompound, TAG_FURNACE_POS);
  69. final BakingProduct bakingProduct = BakingProduct.createFromNBT(furnaceCompound);
  70. furnaces.put(pos, bakingProduct);
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement