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)));
}
}
}
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);
}
}
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);
}
Aggregations