use of net.minecraft.tileentity.BrewingStandTileEntity in project minecolonies by Minecolonies.
the class EntityAIWorkAlchemist method retrieveUsedFuel.
/**
* Retrieve used fuel from the brewingStand. If no position has been set return. Else navigate to the position of the brewingStand. 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 BrewingStandTileEntity) || (ItemStackUtils.isEmpty(((BrewingStandTileEntity) entity).getItem(BREWING_FUEL_SLOT)))) {
walkTo = null;
return START_WORKING;
}
walkTo = null;
extractFromBrewingStandSlot((BrewingStandTileEntity) entity, BREWING_FUEL_SLOT);
return START_WORKING;
}
use of net.minecraft.tileentity.BrewingStandTileEntity in project minecolonies by Minecolonies.
the class EntityAIWorkAlchemist method addFuelToBrewingStand.
/**
* Add brewing stand fuel when necessary
* @return
*/
private IAIState addFuelToBrewingStand() {
if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), Items.BLAZE_POWDER)) {
if (InventoryUtils.hasItemInProvider(building, Items.BLAZE_POWDER)) {
needsCurrently = new Tuple<>(item -> item.getItem() == Items.BLAZE_POWDER, STACKSIZE);
return GATHERING_REQUIRED_MATERIALS;
}
// We shouldn't get here, unless something changed between the checkBrewingStandFuel and the addFueltoBrewingStand 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 BrewingStandTileEntity) {
final BrewingStandTileEntity brewingStand = (BrewingStandTileEntity) entity;
// Stoke the brewing stands
if (InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), Items.BLAZE_POWDER) && (hasBrewableAndNoFuel(brewingStand) || hasNeitherFuelNorBrewable(brewingStand))) {
InventoryUtils.transferXOfFirstSlotInItemHandlerWithIntoInItemHandler(worker.getInventoryCitizen(), item -> item.getItem() == Items.BLAZE_POWDER, BREWING_MIN_FUEL_COUNT, new InvWrapper(brewingStand), BREWING_FUEL_SLOT);
if (preFuelState != null && preFuelState != ADD_FUEL_TO_BREWINGSTAND) {
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.BrewingStandTileEntity in project minecolonies by Minecolonies.
the class EntityAIWorkAlchemist method getPositionOfBrewingStandToRetrieveFrom.
/**
* Get the brewingStand which has finished smeltables. For this check each brewingStand which has been registered to the building. Check if the brewingStand is turned off and has something in
* the result slot or check if the brewingStand has more than x results.
*
* @return the position of the brewingStand.
*/
private BlockPos getPositionOfBrewingStandToRetrieveFrom() {
if (currentRecipeStorage == null || currentRecipeStorage.getIntermediate() != Blocks.BREWING_STAND) {
return null;
}
for (final BlockPos pos : building.getAllBrewingStandPositions()) {
final TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof BrewingStandTileEntity) {
final BrewingStandTileEntity brewingStand = (BrewingStandTileEntity) entity;
int countInResultSlot = 0;
for (int slot = 0; slot < 3; slot++) {
if (!isEmpty(brewingStand.getItem(slot)) && ItemStackUtils.compareItemStacksIgnoreStackSize(currentRecipeStorage.getPrimaryOutput(), brewingStand.getItem(slot))) {
countInResultSlot = brewingStand.getItem(slot).getCount();
}
}
if (brewingStand.brewTime <= 0 && countInResultSlot > 0 && isEmpty(brewingStand.getItem(INGREDIENT_SLOT))) {
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_RETRIEVING));
return pos;
}
}
}
return null;
}
use of net.minecraft.tileentity.BrewingStandTileEntity in project minecolonies by Minecolonies.
the class EntityAIWorkAlchemist method fillUpBrewingStand.
/**
* Brew the ingredient after the required items are in the inv.
*
* @return the next state to go to.
*/
private IAIState fillUpBrewingStand() {
if (building.getAllBrewingStandPositions().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.BREWING_STAND) {
walkTo = null;
setDelay(STANDARD_DELAY);
return START_WORKING;
}
final int burningCount = countOfBubblingBrewingStands();
final TileEntity entity = world.getBlockEntity(walkTo);
if (entity instanceof BrewingStandTileEntity && currentRecipeStorage != null) {
final BrewingStandTileEntity brewingStand = (BrewingStandTileEntity) entity;
final int maxBrewingStands = getMaxUsableBrewingStands();
final int resultInBrewingStand = getExtendedCount(currentRecipeStorage.getPrimaryOutput());
final int resultInCitizenInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, currentRecipeStorage.getPrimaryOutput()));
if (isEmpty(((BrewingStandTileEntity) entity).getItem(0)) || isEmpty(((BrewingStandTileEntity) entity).getItem(1)) || isEmpty(((BrewingStandTileEntity) entity).getItem(2))) {
final ItemStack potionStack = currentRecipeStorage.getCleanedInput().get(1).getItemStack();
final Predicate<ItemStack> potion = stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(potionStack, stack);
final int potionInBrewingStand = getExtendedCount(potionStack);
final int targetCount = currentRequest.getRequest().getCount() * currentRecipeStorage.getPrimaryOutput().getCount() - potionInBrewingStand - resultInBrewingStand - resultInCitizenInv;
if (targetCount <= 0) {
return START_WORKING;
}
final int amountOfPotionInBuilding = InventoryUtils.getCountFromBuilding(building, potion);
final int amountOfPotionInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), potion);
if (worker.getItemInHand(Hand.MAIN_HAND).isEmpty()) {
worker.setItemInHand(Hand.MAIN_HAND, potionStack.copy());
}
if (amountOfPotionInInv > 0) {
if (hasFuelAndNoBrewable(brewingStand) || hasNeitherFuelNorBrewable(brewingStand)) {
for (int slot = 0; slot < 3; slot++) {
if (!isEmpty(((BrewingStandTileEntity) entity).getItem(slot))) {
continue;
}
int toTransfer = 0;
if (burningCount < maxBrewingStands) {
toTransfer = 1;
}
if (toTransfer > 0) {
if (walkToBlock(walkTo)) {
return getState();
}
worker.getCitizenItemHandler().hitBlockWithToolInHand(walkTo);
InventoryUtils.transferXInItemHandlerIntoSlotInItemHandler(worker.getInventoryCitizen(), potion, toTransfer, new InvWrapper(brewingStand), slot);
}
}
}
} else if (amountOfPotionInBuilding >= targetCount - amountOfPotionInInv && currentRecipeStorage.getIntermediate() == Blocks.BREWING_STAND) {
needsCurrently = new Tuple<>(potion, 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 (isEmpty(((BrewingStandTileEntity) entity).getItem(INGREDIENT_SLOT))) {
final ItemStack ingredientStack = currentRecipeStorage.getCleanedInput().get(0).getItemStack();
final Predicate<ItemStack> ingredient = stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(ingredientStack, stack);
final int ingredientInBrewingStand = getExtendedCount(ingredientStack);
final int targetCount = currentRequest.getRequest().getCount() * currentRecipeStorage.getPrimaryOutput().getCount() - ingredientInBrewingStand * 3 - resultInBrewingStand - resultInCitizenInv;
if (targetCount <= 0) {
return START_WORKING;
}
final int amountOfIngredientInBuilding = InventoryUtils.getCountFromBuilding(building, ingredient);
final int amountOfIngredientInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), ingredient);
if (worker.getItemInHand(Hand.MAIN_HAND).isEmpty()) {
worker.setItemInHand(Hand.MAIN_HAND, ingredientStack.copy());
}
if (amountOfIngredientInInv > 0) {
if (hasFuelAndNoBrewable(brewingStand) || hasNeitherFuelNorBrewable(brewingStand)) {
int toTransfer = 0;
if (burningCount < maxBrewingStands) {
toTransfer = 1;
}
if (toTransfer > 0) {
if (walkToBlock(walkTo)) {
return getState();
}
worker.getCitizenItemHandler().hitBlockWithToolInHand(walkTo);
InventoryUtils.transferXInItemHandlerIntoSlotInItemHandler(worker.getInventoryCitizen(), ingredient, toTransfer, new InvWrapper(brewingStand), INGREDIENT_SLOT);
}
}
} else if (amountOfIngredientInBuilding >= targetCount - amountOfIngredientInInv && currentRecipeStorage.getIntermediate() == Blocks.BREWING_STAND) {
needsCurrently = new Tuple<>(ingredient, 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 BrewingStandBlock)) {
building.removeBrewingStand(walkTo);
}
walkTo = null;
setDelay(STANDARD_DELAY);
return START_WORKING;
}
use of net.minecraft.tileentity.BrewingStandTileEntity in project minecolonies by Minecolonies.
the class EntityAIWorkAlchemist method accelerateBrewingStand.
/**
* Actually accelerate the brewingStand
*/
private boolean accelerateBrewingStand() {
final int accelerationTicks = (worker.getCitizenData().getCitizenSkillHandler().getLevel(getModuleForJob().getSecondarySkill()) / 10) * 2;
final World world = building.getColony().getWorld();
for (final BlockPos pos : building.getAllBrewingStandPositions()) {
if (WorldUtil.isBlockLoaded(world, pos)) {
final TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof BrewingStandTileEntity) {
final BrewingStandTileEntity brewingStand = (BrewingStandTileEntity) entity;
for (int i = 0; i < accelerationTicks; i++) {
if (brewingStand.brewTime > 0) {
brewingStand.tick();
}
}
}
}
}
return false;
}
Aggregations