use of net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by ldtteam.
the class AbstractEntityAIRequestSmelter method isFuelNeeded.
/**
* Quick check to see if there is a furnace that needs fuel
*/
private boolean isFuelNeeded() {
final FurnaceUserModule module = getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class);
for (final BlockPos pos : module.getFurnaces()) {
if (WorldUtil.isBlockLoaded(world, pos)) {
final TileEntity entity = world.getBlockEntity(pos);
if (!(entity instanceof FurnaceTileEntity)) {
module.removeFromFurnaces(pos);
continue;
}
final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
if (!furnace.isLit() && (hasSmeltableInFurnaceAndNoFuel(furnace) || hasNeitherFuelNorSmeltAble(furnace)) && currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
// We only want to return true if we're not already gathering materials.
return getState() != GATHERING_REQUIRED_MATERIALS;
}
}
}
return false;
}
use of net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by ldtteam.
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 ldtteam.
the class AbstractEntityAIUsesFurnace method fillUpFurnace.
/**
* Smelt the smeltable after the required items are in the inv.
*
* @return the next state to go to.
*/
private IAIState fillUpFurnace() {
if (getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces().isEmpty()) {
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(BAKER_HAS_NO_FURNACES_MESSAGE), ChatPriority.BLOCKING));
}
return START_WORKING;
}
if (walkTo == null || world.getBlockState(walkTo).getBlock() != Blocks.FURNACE) {
walkTo = null;
return START_WORKING;
}
if (walkToBlock(walkTo)) {
return getState();
}
final TileEntity entity = world.getBlockEntity(walkTo);
if (entity instanceof FurnaceTileEntity) {
final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
if (InventoryUtils.hasItemInItemHandler((worker.getInventoryCitizen()), this::isSmeltable) && (hasFuelInFurnaceAndNoSmeltable(furnace) || hasNeitherFuelNorSmeltAble(furnace))) {
InventoryUtils.transferXOfFirstSlotInItemHandlerWithIntoInItemHandler((worker.getInventoryCitizen()), this::isSmeltable, STACKSIZE, new InvWrapper(furnace), SMELTABLE_SLOT);
}
final ItemListModule module = getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST));
if (InventoryUtils.hasItemInItemHandler((worker.getInventoryCitizen()), stack -> module.isItemInList(new ItemStorage(stack))) && (hasSmeltableInFurnaceAndNoFuel(furnace) || hasNeitherFuelNorSmeltAble(furnace))) {
InventoryUtils.transferXOfFirstSlotInItemHandlerWithIntoInItemHandler((worker.getInventoryCitizen()), stack -> module.isItemInList(new ItemStorage(stack)), STACKSIZE, new InvWrapper(furnace), FUEL_SLOT);
}
}
walkTo = null;
return START_WORKING;
}
use of net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by ldtteam.
the class AbstractEntityAIUsesFurnace method retrieveSmeltableFromFurnace.
/**
* Retrieve ready bars 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 retrieveSmeltableFromFurnace() {
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(RESULT_SLOT)))) {
walkTo = null;
return START_WORKING;
}
walkTo = null;
extractFromFurnace((FurnaceTileEntity) entity);
incrementActionsDoneAndDecSaturation();
return START_WORKING;
}
Aggregations