use of net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by Minecolonies.
the class AbstractEntityAIUsesFurnace method accelerateFurnaces.
/**
* Actually accelerate the furnaces
*/
private IAIState accelerateFurnaces() {
final int accelerationTicks = (worker.getCitizenData().getCitizenSkillHandler().getLevel(getModuleForJob().getPrimarySkill()) / 10) * 2;
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;
for (int i = 0; i < accelerationTicks; i++) {
if (furnace.isLit()) {
furnace.tick();
}
}
}
}
}
return null;
}
use of net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by Minecolonies.
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;
}
use of net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by Minecolonies.
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 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 net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by Minecolonies.
the class AbstractEntityAIRequestSmelter 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 || currentRequest == null) {
return START_WORKING;
}
final TileEntity entity = world.getBlockEntity(walkTo);
if (!(entity instanceof FurnaceTileEntity) || (isEmpty(((FurnaceTileEntity) entity).getItem(RESULT_SLOT)))) {
walkTo = null;
return START_WORKING;
}
if (walkToBlock(walkTo)) {
return getState();
}
walkTo = null;
final int preExtractCount = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(currentRequest.getRequest().getStack(), stack));
extractFromFurnaceSlot((FurnaceTileEntity) entity, RESULT_SLOT);
// Do we have the requested item in the inventory now?
final int resultCount = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(currentRequest.getRequest().getStack(), stack)) - preExtractCount;
if (resultCount > 0) {
final ItemStack stack = currentRequest.getRequest().getStack().copy();
stack.setCount(resultCount);
currentRequest.addDelivery(stack);
job.setCraftCounter(job.getCraftCounter() + resultCount);
job.setProgress(job.getProgress() - resultCount);
if (job.getMaxCraftingCount() == 0) {
job.setMaxCraftingCount(currentRequest.getRequest().getCount());
}
if (job.getCraftCounter() >= job.getMaxCraftingCount() && job.getProgress() <= 0) {
job.finishRequest(true);
resetValues();
currentRecipeStorage = null;
incrementActionsDoneAndDecSaturation();
return INVENTORY_FULL;
}
}
setDelay(STANDARD_DELAY);
return START_WORKING;
}
Aggregations