use of net.minecraft.block.FurnaceBlock in project minecolonies by Minecolonies.
the class AbstractEntityAIRequestSmelter method fillUpFurnace.
/**
* Smelt the smeltable after the required items are in the inv.
*
* @return the next state to go to.
*/
private IAIState fillUpFurnace() {
final FurnaceUserModule module = getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class);
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;
}
if (walkTo == null || world.getBlockState(walkTo).getBlock() != Blocks.FURNACE) {
walkTo = null;
setDelay(STANDARD_DELAY);
return START_WORKING;
}
final int burningCount = countOfBurningFurnaces();
final TileEntity entity = world.getBlockEntity(walkTo);
if (entity instanceof FurnaceTileEntity && currentRecipeStorage != null) {
final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
final int maxFurnaces = getMaxUsableFurnaces();
final Predicate<ItemStack> smeltable = stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(currentRecipeStorage.getCleanedInput().get(0).getItemStack(), stack);
final int smeltableInFurnaces = getExtendedCount(currentRecipeStorage.getCleanedInput().get(0).getItemStack());
final int resultInFurnaces = getExtendedCount(currentRecipeStorage.getPrimaryOutput());
final int resultInCitizenInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, currentRecipeStorage.getPrimaryOutput()));
final int targetCount = currentRequest.getRequest().getCount() - smeltableInFurnaces - resultInFurnaces - resultInCitizenInv;
if (targetCount <= 0) {
return START_WORKING;
}
final int amountOfSmeltableInBuilding = InventoryUtils.getCountFromBuilding(getOwnBuilding(), smeltable);
final int amountOfSmeltableInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), smeltable);
if (worker.getItemInHand(Hand.MAIN_HAND).isEmpty()) {
worker.setItemInHand(Hand.MAIN_HAND, currentRecipeStorage.getCleanedInput().get(0).getItemStack().copy());
}
if (amountOfSmeltableInInv > 0) {
if (hasFuelInFurnaceAndNoSmeltable(furnace) || hasNeitherFuelNorSmeltAble(furnace)) {
int toTransfer = 0;
if (burningCount < maxFurnaces) {
final int availableFurnaces = maxFurnaces - burningCount;
if (targetCount > STACKSIZE * availableFurnaces) {
toTransfer = STACKSIZE;
} else {
// We need to split stacks and spread them across furnaces for best performance
// We will front-load the remainder
toTransfer = Math.min((targetCount / availableFurnaces) + (targetCount % availableFurnaces), STACKSIZE);
}
}
if (toTransfer > 0) {
if (walkToBlock(walkTo)) {
return getState();
}
worker.getCitizenItemHandler().hitBlockWithToolInHand(walkTo);
InventoryUtils.transferXInItemHandlerIntoSlotInItemHandler(worker.getInventoryCitizen(), smeltable, toTransfer, new InvWrapper(furnace), SMELTABLE_SLOT);
}
}
} else if (amountOfSmeltableInBuilding >= targetCount - amountOfSmeltableInInv && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
needsCurrently = new Tuple<>(smeltable, targetCount);
return GATHERING_REQUIRED_MATERIALS;
} else {
// This is a safety net for the AI getting way out of sync with it's tracking. It shouldn't happen.
job.finishRequest(false);
resetValues();
walkTo = null;
return IDLE;
}
} else if (!(world.getBlockState(walkTo).getBlock() instanceof FurnaceBlock)) {
module.removeFromFurnaces(walkTo);
}
walkTo = null;
setDelay(STANDARD_DELAY);
return START_WORKING;
}
use of net.minecraft.block.FurnaceBlock in project minecolonies by ldtteam.
the class AbstractEntityAIRequestSmelter method fillUpFurnace.
/**
* Smelt the smeltable after the required items are in the inv.
*
* @return the next state to go to.
*/
private IAIState fillUpFurnace() {
final FurnaceUserModule module = getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class);
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;
}
if (walkTo == null || world.getBlockState(walkTo).getBlock() != Blocks.FURNACE) {
walkTo = null;
setDelay(STANDARD_DELAY);
return START_WORKING;
}
final int burningCount = countOfBurningFurnaces();
final TileEntity entity = world.getBlockEntity(walkTo);
if (entity instanceof FurnaceTileEntity && currentRecipeStorage != null) {
final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
final int maxFurnaces = getMaxUsableFurnaces();
final Predicate<ItemStack> smeltable = stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(currentRecipeStorage.getCleanedInput().get(0).getItemStack(), stack);
final int smeltableInFurnaces = getExtendedCount(currentRecipeStorage.getCleanedInput().get(0).getItemStack());
final int resultInFurnaces = getExtendedCount(currentRecipeStorage.getPrimaryOutput());
final int resultInCitizenInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, currentRecipeStorage.getPrimaryOutput()));
final int targetCount = currentRequest.getRequest().getCount() - smeltableInFurnaces - resultInFurnaces - resultInCitizenInv;
if (targetCount <= 0) {
return START_WORKING;
}
final int amountOfSmeltableInBuilding = InventoryUtils.getCountFromBuilding(getOwnBuilding(), smeltable);
final int amountOfSmeltableInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), smeltable);
if (worker.getItemInHand(Hand.MAIN_HAND).isEmpty()) {
worker.setItemInHand(Hand.MAIN_HAND, currentRecipeStorage.getCleanedInput().get(0).getItemStack().copy());
}
if (amountOfSmeltableInInv > 0) {
if (hasFuelInFurnaceAndNoSmeltable(furnace) || hasNeitherFuelNorSmeltAble(furnace)) {
int toTransfer = 0;
if (burningCount < maxFurnaces) {
final int availableFurnaces = maxFurnaces - burningCount;
if (targetCount > STACKSIZE * availableFurnaces) {
toTransfer = STACKSIZE;
} else {
// We need to split stacks and spread them across furnaces for best performance
// We will front-load the remainder
toTransfer = Math.min((targetCount / availableFurnaces) + (targetCount % availableFurnaces), STACKSIZE);
}
}
if (toTransfer > 0) {
if (walkToBlock(walkTo)) {
return getState();
}
worker.getCitizenItemHandler().hitBlockWithToolInHand(walkTo);
InventoryUtils.transferXInItemHandlerIntoSlotInItemHandler(worker.getInventoryCitizen(), smeltable, toTransfer, new InvWrapper(furnace), SMELTABLE_SLOT);
}
}
} else if (amountOfSmeltableInBuilding >= targetCount - amountOfSmeltableInInv && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
needsCurrently = new Tuple<>(smeltable, targetCount);
return GATHERING_REQUIRED_MATERIALS;
} else {
// This is a safety net for the AI getting way out of sync with it's tracking. It shouldn't happen.
job.finishRequest(false);
resetValues();
walkTo = null;
return IDLE;
}
} else if (!(world.getBlockState(walkTo).getBlock() instanceof FurnaceBlock)) {
module.removeFromFurnaces(walkTo);
}
walkTo = null;
setDelay(STANDARD_DELAY);
return START_WORKING;
}
use of net.minecraft.block.FurnaceBlock 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 net.minecraft.block.FurnaceBlock 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