use of net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by Minecolonies.
the class AbstractEntityAIRequestSmelter method retrieveUsedFuel.
/**
* Retrieve used fuel from the furnaces. If no position has been set return. Else navigate to the position of the furnace. On arrival execute the extract method of the
* specialized worker.
*
* @return the next state to go to.
*/
private IAIState retrieveUsedFuel() {
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_RETRIEVING));
if (walkTo == null) {
return START_WORKING;
}
if (walkToBlock(walkTo)) {
return getState();
}
final TileEntity entity = world.getBlockEntity(walkTo);
if (!(entity instanceof FurnaceTileEntity) || (ItemStackUtils.isEmpty(((FurnaceTileEntity) entity).getItem(FUEL_SLOT)))) {
walkTo = null;
return START_WORKING;
}
walkTo = null;
extractFromFurnaceSlot((FurnaceTileEntity) entity, FUEL_SLOT);
return START_WORKING;
}
use of net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by ldtteam.
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 ldtteam.
the class AbstractEntityAIRequestSmelter method getRecipe.
@Override
protected IAIState getRecipe() {
final IRequest<? extends PublicCrafting> currentTask = job.getCurrentTask();
if (currentTask == null) {
worker.setItemInHand(Hand.MAIN_HAND, ItemStackUtils.EMPTY);
return START_WORKING;
}
job.setMaxCraftingCount(currentTask.getRequest().getCount());
final BlockPos furnacePosWithUsedFuel = getPositionOfOvenToRetrieveFuelFrom();
if (furnacePosWithUsedFuel != null) {
currentRequest = currentTask;
walkTo = furnacePosWithUsedFuel;
return RETRIEVING_USED_FUEL_FROM_FURNACE;
}
final BlockPos furnacePos = getPositionOfOvenToRetrieveFrom();
if (furnacePos != null) {
currentRequest = currentTask;
walkTo = furnacePos;
return RETRIEVING_END_PRODUCT_FROM_FURNACE;
}
if (currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
for (final BlockPos pos : getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces()) {
final TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof FurnaceTileEntity) {
final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
if (furnace.isLit() || !isEmpty(furnace.getItem(RESULT_SLOT)) || !isEmpty(furnace.getItem(SMELTABLE_SLOT))) {
if (furnace.isLit()) {
setDelay(TICKS_20);
}
return CRAFT;
}
}
}
}
final IAIState newState = super.getRecipe();
final ItemListModule module = getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST));
// This should only happen in the stonesmelter, but it could potentially happen with multiple fuels.
if (newState == QUERY_ITEMS && currentRecipeStorage != null && module.isItemInList(new ItemStorage(currentRecipeStorage.getPrimaryOutput()))) {
job.setCraftCounter(0);
}
return newState;
}
use of net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by ldtteam.
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 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