use of net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by Minecolonies.
the class AbstractEntityAIRequestSmelter method getPositionOfOvenToRetrieveFrom.
/**
* Get the furnace which has finished smeltables. For this check each furnace which has been registered to the building. Check if the furnace is turned off and has something in
* the result slot or check if the furnace has more than x results.
*
* @return the position of the furnace.
*/
private BlockPos getPositionOfOvenToRetrieveFrom() {
for (final BlockPos pos : getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces()) {
final TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof FurnaceTileEntity) {
final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
int countInResultSlot = 0;
boolean fullResult = false;
if (!isEmpty(furnace.getItem(RESULT_SLOT))) {
countInResultSlot = furnace.getItem(RESULT_SLOT).getCount();
fullResult = countInResultSlot >= furnace.getItem(RESULT_SLOT).getMaxStackSize();
}
if (fullResult || (!furnace.isLit() && countInResultSlot > 0 && isEmpty(furnace.getItem(SMELTABLE_SLOT)))) {
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_RETRIEVING));
return pos;
}
}
}
return null;
}
use of net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by Minecolonies.
the class AbstractEntityAIRequestSmelter method addFuelToFurnace.
/**
* Add furnace fuel when necessary
* @return
*/
private IAIState addFuelToFurnace() {
final List<ItemStack> possibleFuels = getActivePossibleFuels();
if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), isCorrectFuel(possibleFuels))) {
if (InventoryUtils.hasItemInProvider(getOwnBuilding(), isCorrectFuel(possibleFuels))) {
needsCurrently = new Tuple<>(isCorrectFuel(possibleFuels), STACKSIZE);
return GATHERING_REQUIRED_MATERIALS;
}
// We shouldn't get here, unless something changed between the checkFurnaceFuel and the addFueltoFurnace calls
preFuelState = null;
fuelPos = null;
return START_WORKING;
}
if (fuelPos == null || walkToBlock(fuelPos)) {
return getState();
}
if (WorldUtil.isBlockLoaded(world, fuelPos)) {
final TileEntity entity = world.getBlockEntity(fuelPos);
if (entity instanceof FurnaceTileEntity) {
final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
// Stoke the furnaces
if (InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), isCorrectFuel(possibleFuels)) && (hasSmeltableInFurnaceAndNoFuel(furnace) || hasNeitherFuelNorSmeltAble(furnace))) {
InventoryUtils.transferXOfFirstSlotInItemHandlerWithIntoInItemHandler(worker.getInventoryCitizen(), isCorrectFuel(possibleFuels), STACKSIZE, new InvWrapper(furnace), FUEL_SLOT);
if (preFuelState != null && preFuelState != ADD_FUEL_TO_FURNACE) {
IAIState returnState = preFuelState;
preFuelState = null;
fuelPos = null;
return returnState;
}
}
}
}
// Fueling is confused, start over.
preFuelState = null;
fuelPos = null;
return START_WORKING;
}
use of net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by Minecolonies.
the class AbstractEntityAIRequestSmelter method countOfBurningFurnaces.
/**
* Check to see how many furnaces are still processing
* @return the count.
*/
private int countOfBurningFurnaces() {
int count = 0;
final World world = getOwnBuilding().getColony().getWorld();
for (final BlockPos pos : getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces()) {
if (WorldUtil.isBlockLoaded(world, pos)) {
final TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof FurnaceTileEntity) {
final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
if (furnace.isLit()) {
count += 1;
}
}
}
}
return count;
}
use of net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by Minecolonies.
the class AbstractEntityAIRequestSmelter method getExtendedCount.
@Override
protected int getExtendedCount(final ItemStack stack) {
if (currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
int count = 0;
for (final BlockPos pos : getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces()) {
if (WorldUtil.isBlockLoaded(world, pos)) {
final TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof FurnaceTileEntity) {
final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
final ItemStack smeltableSlot = furnace.getItem(SMELTABLE_SLOT);
final ItemStack resultSlot = furnace.getItem(RESULT_SLOT);
if (ItemStackUtils.compareItemStacksIgnoreStackSize(stack, smeltableSlot)) {
count += smeltableSlot.getCount();
} else if (ItemStackUtils.compareItemStacksIgnoreStackSize(stack, resultSlot)) {
count += resultSlot.getCount();
}
}
}
}
return count;
}
return 0;
}
use of net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by Minecolonies.
the class AbstractEntityAIRequestSmelter method checkIfAbleToSmelt.
/**
* Checks if the furnaces are ready to start smelting.
*
* @return START_USING_FURNACE if enough, else check for additional worker specific jobs.
*/
private IAIState checkIfAbleToSmelt() {
// We're fully committed currently, try again later.
final int burning = countOfBurningFurnaces();
if (burning > 0 && (burning >= getMaxUsableFurnaces() || (job.getCraftCounter() + job.getProgress()) >= job.getMaxCraftingCount())) {
setDelay(TICKS_SECOND);
return getState();
}
final FurnaceUserModule module = getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class);
for (final BlockPos pos : module.getFurnaces()) {
final TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof FurnaceTileEntity) {
if (isEmpty(((FurnaceTileEntity) entity).getItem(SMELTABLE_SLOT))) {
walkTo = pos;
return START_USING_FURNACE;
}
} else {
if (!(world.getBlockState(pos).getBlock() instanceof FurnaceBlock)) {
module.removeFromFurnaces(pos);
}
}
}
if (burning > 0) {
setDelay(TICKS_SECOND);
}
return getState();
}
Aggregations