use of com.minecolonies.coremod.inventory.InventoryCitizen in project minecolonies by Minecolonies.
the class BuildingBuilder method updateAvailableResources.
/**
* Update the available resources.
* <p>
* which are needed for the build and in the builder's chest or inventory
*/
private void updateAvailableResources() {
final EntityCitizen builder = getWorkerEntity();
InventoryCitizen builderInventory = null;
if (builder != null) {
builderInventory = builder.getInventoryCitizen();
}
for (@NotNull final Map.Entry<String, BuildingBuilderResource> entry : neededResources.entrySet()) {
final BuildingBuilderResource resource = entry.getValue();
resource.setAvailable(0);
if (builderInventory != null) {
resource.addAvailable(InventoryUtils.getItemCountInItemHandler(new InvWrapper(builderInventory), resource.getItem(), resource.getDamageValue()));
}
final TileEntity chestInventory = this.getTileEntity();
if (chestInventory != null) {
resource.addAvailable(InventoryUtils.getItemCountInProvider(chestInventory, resource.getItem(), resource.getDamageValue()));
}
//Count in the additional chests as well
if (builder != null) {
for (final BlockPos pos : getAdditionalCountainers()) {
final TileEntity entity = builder.world.getTileEntity(pos);
if (entity instanceof TileEntityChest) {
resource.addAvailable(InventoryUtils.getItemCountInProvider(entity, resource.getItem(), resource.getDamageValue()));
}
}
}
}
}
use of com.minecolonies.coremod.inventory.InventoryCitizen in project minecolonies by Minecolonies.
the class AbstractEntityAIBasic method getMostEfficientTool.
/**
* Calculates the most efficient tool to use
* on that block.
*
* @param target the Block type to mine
* @return the slot with the best tool
*/
private int getMostEfficientTool(@NotNull final Block target) {
final String tool = target.getHarvestTool(target.getDefaultState());
final int required = target.getHarvestLevel(target.getDefaultState());
int bestSlot = -1;
int bestLevel = Integer.MAX_VALUE;
@NotNull final InventoryCitizen inventory = worker.getInventoryCitizen();
final int hutLevel = worker.getWorkBuilding().getBuildingLevel();
for (int i = 0; i < new InvWrapper(worker.getInventoryCitizen()).getSlots(); i++) {
final ItemStack item = inventory.getStackInSlot(i);
final int level = Utils.getMiningLevel(item, tool);
if (level >= required && level < bestLevel) {
if (tool == null || InventoryUtils.verifyToolLevel(item, level, hutLevel)) {
bestSlot = i;
bestLevel = level;
}
}
}
return bestSlot;
}
use of com.minecolonies.coremod.inventory.InventoryCitizen in project minecolonies by Minecolonies.
the class AbstractEntityAIBasic method checkForTool.
/**
* Ensures that we have a tool available.
*
* @param tool tool required for block
* @return true if we have a tool
*/
private boolean checkForTool(@NotNull final String tool) {
final boolean needsTool = !InventoryFunctions.matchFirstInProvider(worker, stack -> Utils.isTool(stack, tool));
final int hutLevel = worker.getWorkBuilding().getBuildingLevel();
final InventoryCitizen inventory = worker.getInventoryCitizen();
final boolean isUsable = InventoryUtils.isToolInItemHandler(new InvWrapper(inventory), tool, hutLevel);
if (!needsTool && isUsable) {
return false;
}
delay += DELAY_RECHECK;
if (walkToBuilding()) {
return true;
}
if (isToolInHut(tool)) {
return false;
}
if (!getOwnBuilding().hasOnGoingDelivery()) {
chatSpamFilter.talkWithoutSpam(COM_MINECOLONIES_COREMOD_ENTITY_WORKER_TOOLREQUEST, tool, InventoryUtils.swapToolGrade(hutLevel));
}
return true;
}
use of com.minecolonies.coremod.inventory.InventoryCitizen in project minecolonies by Minecolonies.
the class AbstractEntityAIBasic method checkForPickaxe.
/**
* Ensures that we have a pickaxe available.
* Will set {@code needsPickaxe} accordingly.
*
* @param minlevel the minimum pickaxe level needed.
* @return true if we have a pickaxe
*/
private boolean checkForPickaxe(final int minlevel) {
//Check for a pickaxe
getOwnBuilding().setNeedsPickaxe(!InventoryFunctions.matchFirstInProvider(worker, stack -> Utils.checkIfPickaxeQualifies(minlevel, Utils.getMiningLevel(stack, Utils.PICKAXE))));
delay += DELAY_RECHECK;
final InventoryCitizen inventory = worker.getInventoryCitizen();
final int hutLevel = worker.getWorkBuilding().getBuildingLevel();
final boolean isUsable = InventoryUtils.isToolInItemHandler(new InvWrapper(inventory), Utils.PICKAXE, hutLevel);
if (!isUsable) {
getOwnBuilding().setNeedsPickaxe(true);
}
if (getOwnBuilding().needsPickaxe()) {
getOwnBuilding().setNeedsPickaxeLevel(minlevel);
if (walkToBuilding()) {
return false;
}
if (isPickaxeInHut(minlevel)) {
return true;
}
if (!getOwnBuilding().hasOnGoingDelivery()) {
if (minlevel > hutLevel) {
chatSpamFilter.talkWithoutSpam(COM_MINECOLONIES_COREMOD_ENTITY_WORKER_PICKAXEREQUESTBETTERHUT, InventoryUtils.swapToolGrade(hutLevel));
} else {
chatSpamFilter.talkWithoutSpam(COM_MINECOLONIES_COREMOD_ENTITY_WORKER_PICKAXEREQUEST, InventoryUtils.swapToolGrade(minlevel), InventoryUtils.swapToolGrade(hutLevel));
}
}
}
return getOwnBuilding().needsPickaxe();
}
Aggregations