Search in sources :

Example 1 with BakingProduct

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

the class BuildingBaker method checkFurnaces.

/**
 * Checks the furnaces of the baker if they're ready.
 */
private void checkFurnaces() {
    final World worldObj = getColony().getWorld();
    if (worldObj == null) {
        return;
    }
    final List<Map.Entry<BlockPos, BakingProduct>> copyOfList = new ArrayList<>(this.getFurnacesWithProduct().entrySet());
    for (final Map.Entry<BlockPos, BakingProduct> entry : copyOfList) {
        if (!worldObj.isBlockLoaded(entry.getKey())) {
            return;
        }
        final IBlockState furnace = worldObj.getBlockState(entry.getKey());
        if (!(furnace.getBlock() instanceof BlockFurnace)) {
            if (worldObj.getTileEntity(entry.getKey()) instanceof TileEntityFurnace) {
                return;
            }
            Log.getLogger().warn(getColony().getName() + " Removed furnace at: " + entry.getKey() + " because it went missing!");
            this.removeFromFurnaces(entry.getKey());
            continue;
        }
        final BakingProduct bakingProduct = entry.getValue();
        if (bakingProduct != null && bakingProduct.getState() == ProductState.BAKING) {
            bakingProduct.increaseBakingProgress();
            worldObj.setBlockState(entry.getKey(), Blocks.LIT_FURNACE.getDefaultState().withProperty(BlockFurnace.FACING, furnace.getValue(BlockFurnace.FACING)));
        } else {
            worldObj.setBlockState(entry.getKey(), Blocks.FURNACE.getDefaultState().withProperty(BlockFurnace.FACING, furnace.getValue(BlockFurnace.FACING)));
        }
    }
}
Also used : BlockFurnace(net.minecraft.block.BlockFurnace) IBlockState(net.minecraft.block.state.IBlockState) TileEntityFurnace(net.minecraft.tileentity.TileEntityFurnace) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) BakingProduct(com.minecolonies.coremod.entity.ai.citizen.baker.BakingProduct)

Example 2 with BakingProduct

use of com.minecolonies.coremod.entity.ai.citizen.baker.BakingProduct 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 3 with BakingProduct

use of com.minecolonies.coremod.entity.ai.citizen.baker.BakingProduct 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)3 BlockPos (net.minecraft.util.math.BlockPos)3 ProductState (com.minecolonies.coremod.entity.ai.citizen.baker.ProductState)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 BlockFurnace (net.minecraft.block.BlockFurnace)1 IBlockState (net.minecraft.block.state.IBlockState)1 TileEntityFurnace (net.minecraft.tileentity.TileEntityFurnace)1 World (net.minecraft.world.World)1 NotNull (org.jetbrains.annotations.NotNull)1