use of com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule in project minecolonies by ldtteam.
the class AbstractEntityAIRequestSmelter method checkFurnaceFuel.
/**
* Check Fuel levels in the furnace
*/
private IAIState checkFurnaceFuel() {
final World world = getOwnBuilding().getColony().getWorld();
final List<ItemStack> possibleFuels = getActivePossibleFuels();
final FurnaceUserModule module = getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class);
if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), isCorrectFuel(possibleFuels)) && !InventoryUtils.hasItemInProvider(getOwnBuilding(), isCorrectFuel(possibleFuels)) && !getOwnBuilding().hasWorkerOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(StackList.class)) && currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
worker.getCitizenData().createRequestAsync(new StackList(possibleFuels, COM_MINECOLONIES_REQUESTS_BURNABLE, STACKSIZE * module.getFurnaces().size(), 1));
return getState();
}
for (final BlockPos pos : module.getFurnaces()) {
if (WorldUtil.isBlockLoaded(world, pos)) {
final TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof FurnaceTileEntity) {
final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
if (!furnace.isLit() && (hasSmeltableInFurnaceAndNoFuel(furnace) || hasNeitherFuelNorSmeltAble(furnace)) && currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), isCorrectFuel(possibleFuels))) {
if (InventoryUtils.hasItemInProvider(getOwnBuilding(), isCorrectFuel(possibleFuels))) {
needsCurrently = new Tuple<>(isCorrectFuel(possibleFuels), STACKSIZE);
// This could be set to a furnace at this point, and gathering requires it to be null, to find the right rack
walkTo = null;
return GATHERING_REQUIRED_MATERIALS;
}
// We need to wait for Fuel to arrive
return getState();
}
fuelPos = pos;
if (preFuelState == null) {
preFuelState = getState();
}
return ADD_FUEL_TO_FURNACE;
}
}
}
}
return getState();
}
use of com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule in project minecolonies by Minecolonies.
the class AbstractEntityAIRequestSmelter method checkFurnaceFuel.
/**
* Check Fuel levels in the furnace
*/
private IAIState checkFurnaceFuel() {
final World world = getOwnBuilding().getColony().getWorld();
final List<ItemStack> possibleFuels = getActivePossibleFuels();
final FurnaceUserModule module = getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class);
if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), isCorrectFuel(possibleFuels)) && !InventoryUtils.hasItemInProvider(getOwnBuilding(), isCorrectFuel(possibleFuels)) && !getOwnBuilding().hasWorkerOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(StackList.class)) && currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
worker.getCitizenData().createRequestAsync(new StackList(possibleFuels, COM_MINECOLONIES_REQUESTS_BURNABLE, STACKSIZE * module.getFurnaces().size(), 1));
return getState();
}
for (final BlockPos pos : module.getFurnaces()) {
if (WorldUtil.isBlockLoaded(world, pos)) {
final TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof FurnaceTileEntity) {
final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
if (!furnace.isLit() && (hasSmeltableInFurnaceAndNoFuel(furnace) || hasNeitherFuelNorSmeltAble(furnace)) && currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), isCorrectFuel(possibleFuels))) {
if (InventoryUtils.hasItemInProvider(getOwnBuilding(), isCorrectFuel(possibleFuels))) {
needsCurrently = new Tuple<>(isCorrectFuel(possibleFuels), STACKSIZE);
// This could be set to a furnace at this point, and gathering requires it to be null, to find the right rack
walkTo = null;
return GATHERING_REQUIRED_MATERIALS;
}
// We need to wait for Fuel to arrive
return getState();
}
fuelPos = pos;
if (preFuelState == null) {
preFuelState = getState();
}
return ADD_FUEL_TO_FURNACE;
}
}
}
}
return getState();
}
use of com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule 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();
}
use of com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule in project minecolonies by ldtteam.
the class AbstractEntityAIRequestSmelter method craft.
@Override
protected IAIState craft() {
final FurnaceUserModule module = getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class);
final List<ItemStack> possibleFuels = getAllowedFuel();
if (possibleFuels.isEmpty()) {
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(FURNACE_USER_NO_FUEL), ChatPriority.BLOCKING));
}
return getState();
}
if (currentRecipeStorage != null) {
possibleFuels.removeIf(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, currentRecipeStorage.getPrimaryOutput()));
// There is always only one input.
possibleFuels.removeIf(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, currentRecipeStorage.getCleanedInput().get(0).getItemStack()));
}
if (walkToBuilding()) {
setDelay(STANDARD_DELAY);
return getState();
}
if (currentRecipeStorage != null && currentRequest == null) {
currentRequest = job.getCurrentTask();
}
if (currentRecipeStorage != null && currentRecipeStorage.getIntermediate() != Blocks.FURNACE) {
return super.craft();
}
if (module.getFurnaces().isEmpty()) {
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(BAKER_HAS_NO_FURNACES_MESSAGE), ChatPriority.BLOCKING));
}
setDelay(STANDARD_DELAY);
return START_WORKING;
}
final BlockPos furnacePosWithUsedFuel = getPositionOfOvenToRetrieveFuelFrom();
if (furnacePosWithUsedFuel != null) {
walkTo = furnacePosWithUsedFuel;
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.retrieving"));
return RETRIEVING_USED_FUEL_FROM_FURNACE;
}
final BlockPos posOfOven = getPositionOfOvenToRetrieveFrom();
if (posOfOven != null) {
walkTo = posOfOven;
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.retrieving"));
return RETRIEVING_END_PRODUCT_FROM_FURNACE;
}
// Safety net, should get caught removing things from the furnace.
if (currentRequest != null && job.getMaxCraftingCount() > 0 && job.getCraftCounter() >= job.getMaxCraftingCount()) {
job.finishRequest(true);
currentRecipeStorage = null;
currentRequest = null;
resetValues();
return INVENTORY_FULL;
}
if (currentRequest != null && (currentRequest.getState() == RequestState.CANCELLED || currentRequest.getState() == RequestState.FAILED)) {
incrementActionsDone(getActionRewardForCraftingSuccess());
currentRecipeStorage = null;
currentRequest = null;
resetValues();
return START_WORKING;
}
return checkIfAbleToSmelt();
}
use of com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule in project minecolonies by ldtteam.
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