Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void writeToNBT(@NotNull final NBTTagCompound compound)
- {
- super.writeToNBT(compound);
- @NotNull final NBTTagList tasksTagList = new NBTTagList();
- for (@NotNull final Map.Entry<ProductState, List<BakingProduct>> entry : tasks.entrySet())
- {
- if(!entry.getValue().isEmpty())
- {
- @NotNull final NBTTagCompound taskCompound = new NBTTagCompound();
- taskCompound.setInteger(TAG_STATE, entry.getKey().ordinal());
- @NotNull final NBTTagList productsTaskList = new NBTTagList();
- for (@NotNull final BakingProduct bakingProduct : entry.getValue())
- {
- @NotNull final NBTTagCompound productCompound = new NBTTagCompound();
- bakingProduct.writeToNBT(productCompound);
- }
- taskCompound.setTag(TAG_PRODUCTS, productsTaskList);
- tasksTagList.appendTag(taskCompound);
- }
- }
- compound.setTag(TAG_TASKS, tasksTagList);
- @NotNull final NBTTagList furnacesTagList = new NBTTagList();
- for (@NotNull final Map.Entry<BlockPos, BakingProduct> entry : furnaces.entrySet())
- {
- @NotNull final NBTTagCompound furnaceCompound = new NBTTagCompound();
- BlockPosUtil.writeToNBT(furnaceCompound, TAG_FURNACE_POS, entry.getKey());
- if(entry.getValue() != null)
- {
- entry.getValue().writeToNBT(furnaceCompound);
- }
- furnacesTagList.appendTag(furnaceCompound);
- }
- compound.setTag(TAG_FURNACES, furnacesTagList);
- }
- @Override
- public void readFromNBT(@NotNull final NBTTagCompound compound)
- {
- tasks.clear();
- super.readFromNBT(compound);
- final NBTTagList taskTagList = compound.getTagList(TAG_TASKS, Constants.NBT.TAG_COMPOUND);
- for (int i = 0; i < taskTagList.tagCount(); ++i)
- {
- final NBTTagCompound taskCompound = taskTagList.getCompoundTagAt(i);
- final ProductState state = ProductState.values()[taskCompound.getInteger(TAG_STATE)];
- final List<BakingProduct> bakingProducts = new ArrayList<>();
- final NBTTagList productTagList = taskCompound.getTagList(TAG_PRODUCTS, Constants.NBT.TAG_COMPOUND);
- for (int j = 0; j < productTagList.tagCount(); ++j)
- {
- final NBTTagCompound productCompound = taskTagList.getCompoundTagAt(i);
- final BakingProduct bakingProduct = BakingProduct.createFromNBT(productCompound);
- bakingProducts.add(bakingProduct);
- }
- tasks.put(state, bakingProducts);
- }
- final NBTTagList furnaceTagList = compound.getTagList(TAG_FURNACES, Constants.NBT.TAG_COMPOUND);
- for (int i = 0; i < furnaceTagList.tagCount(); ++i)
- {
- final NBTTagCompound furnaceCompound = furnaceTagList.getCompoundTagAt(i);
- final BlockPos pos = BlockPosUtil.readFromNBT(furnaceCompound, TAG_FURNACE_POS);
- final BakingProduct bakingProduct = BakingProduct.createFromNBT(furnaceCompound);
- furnaces.put(pos, bakingProduct);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement