Search in sources :

Example 1 with ProductState

use of com.minecolonies.coremod.entity.ai.citizen.baker.ProductState in project minecolonies by Minecolonies.

the class BuildingBaker method readFromNBT.

@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);
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ProductState(com.minecolonies.coremod.entity.ai.citizen.baker.ProductState) BlockPos(net.minecraft.util.math.BlockPos) BakingProduct(com.minecolonies.coremod.entity.ai.citizen.baker.BakingProduct)

Example 2 with ProductState

use of com.minecolonies.coremod.entity.ai.citizen.baker.ProductState in project minecolonies by Minecolonies.

the class BuildingBaker method writeToNBT.

@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);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ProductState(com.minecolonies.coremod.entity.ai.citizen.baker.ProductState) NBTTagList(net.minecraft.nbt.NBTTagList) BlockPos(net.minecraft.util.math.BlockPos) NotNull(org.jetbrains.annotations.NotNull) BakingProduct(com.minecolonies.coremod.entity.ai.citizen.baker.BakingProduct)

Aggregations

BakingProduct (com.minecolonies.coremod.entity.ai.citizen.baker.BakingProduct)2 ProductState (com.minecolonies.coremod.entity.ai.citizen.baker.ProductState)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 BlockPos (net.minecraft.util.math.BlockPos)2 NotNull (org.jetbrains.annotations.NotNull)1