use of net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by ldtteam.
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 accelerateFurnaces.
/**
* Actually accelerate the furnaces
*/
private boolean accelerateFurnaces() {
final int accelerationTicks = (worker.getCitizenData().getCitizenSkillHandler().getLevel(getModuleForJob().getSecondarySkill()) / 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 false;
}
use of net.minecraft.tileentity.FurnaceTileEntity 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 net.minecraft.tileentity.FurnaceTileEntity in project minecolonies by ldtteam.
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 ldtteam.
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