use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.
the class TileEntityRack method updateItemStorage.
/**
* Scans through the whole storage and updates it.
*/
public void updateItemStorage() {
content.clear();
for (int slot = 0; slot < inventory.getSlots(); slot++) {
final ItemStack stack = inventory.getStackInSlot(slot);
if (ItemStackUtils.isEmpty(stack)) {
continue;
}
final ItemStorage storage = new ItemStorage(stack.copy());
int amount = ItemStackUtils.getSize(stack);
if (content.containsKey(storage)) {
amount += content.remove(storage);
}
content.put(storage, amount);
}
updateBlockState();
markDirty();
}
use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.
the class WindowBuildBuilding method updateResourceList.
public void updateResourceList() {
final ScrollingList recourseList = findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class);
recourseList.enable();
recourseList.show();
final List<ItemStorage> tempRes = new ArrayList<>(resources.values());
// Creates a dataProvider for the unemployed recourseList.
recourseList.setDataProvider(new ScrollingList.DataProvider() {
/**
* The number of rows of the list.
* @return the number.
*/
@Override
public int getElementCount() {
return tempRes.size();
}
/**
* Inserts the elements into each row.
* @param index the index of the row/list element.
* @param rowPane the parent Pane for the row, containing the elements to update.
*/
@Override
public void updateElement(final int index, @NotNull final Pane rowPane) {
final ItemStorage resource = tempRes.get(index);
final Label resourceLabel = rowPane.findPaneOfTypeByID(RESOURCE_NAME, Label.class);
final Label quantityLabel = rowPane.findPaneOfTypeByID(RESOURCE_QUANTITY_MISSING, Label.class);
resourceLabel.setLabelText(resource.getItemStack().getDisplayName());
quantityLabel.setLabelText(Integer.toString(resource.getAmount()));
resourceLabel.setColor(WHITE, WHITE);
quantityLabel.setColor(WHITE, WHITE);
rowPane.findPaneOfTypeByID(RESOURCE_ICON, ItemIcon.class).setItem(new ItemStack(resource.getItem(), 1, resource.getDamageValue()));
}
});
}
use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.
the class AbstractEntityAIBasic method dumpOneMoreSlot.
/**
* Dumps one inventory slot into the building chest.
*
* @return true if is has to dump more.
*/
private boolean dumpOneMoreSlot() {
// Items already kept in the inventory
final List<ItemStorage> alreadyKept = new ArrayList<>();
@Nullable final AbstractBuildingWorker buildingWorker = getOwnBuilding();
return buildingWorker != null && (walkToBuilding() || InventoryFunctions.matchFirstInHandlerWithAction(new InvWrapper(worker.getInventoryCitizen()), itemStack -> !ItemStackUtils.isEmpty(itemStack) && !buildingWorker.buildingRequiresCertainAmountOfItem(itemStack, alreadyKept), (handler, slot) -> InventoryUtils.transferItemStackIntoNextFreeSlotInItemHandlers(new InvWrapper(worker.getInventoryCitizen()), slot, new InvWrapper(buildingWorker.getTileEntity()))));
}
use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.
the class CompatabilityManager method discoverSaplings.
private void discoverSaplings() {
for (final ItemStack saps : OreDictionary.getOres(SAPLINGS)) {
if (saps.getHasSubtypes()) {
for (final CreativeTabs tabs : CreativeTabs.CREATIVE_TAB_ARRAY) {
final NonNullList<ItemStack> list = NonNullList.create();
saps.getItem().getSubItems(tabs, list);
for (final ItemStack stack : list) {
// Just put it in if not in there already, don't mind the leave yet.
if (!ItemStackUtils.isEmpty(stack) && !leavesToSaplingMap.containsValue(new ItemStorage(stack)) && !saplings.contains(new ItemStorage(stack))) {
saplings.add(new ItemStorage(stack));
}
}
}
}
}
Log.getLogger().info("Finished discovering saplings");
}
use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.
the class AbstractBuilding method buildingRequiresCertainAmountOfItem.
/**
* Check if the worker requires a certain amount of that item and the alreadykept list contains it.
* Always leave one stack behind if the worker requires a certain amount of it. Just to be sure.
*
* @param stack the stack to check it with.
* @param localAlreadyKept already kept items.
* @return true if it should be leave it behind.
*/
public boolean buildingRequiresCertainAmountOfItem(final ItemStack stack, final List<ItemStorage> localAlreadyKept) {
for (final Map.Entry<Predicate<ItemStack>, Integer> entry : getRequiredItemsAndAmount().entrySet()) {
if (entry.getKey().test(stack)) {
final ItemStorage kept = ItemStorage.getItemStackOfListMatchingPredicate(localAlreadyKept, entry.getKey());
if (kept != null) {
if (kept.getAmount() >= entry.getValue()) {
return false;
}
localAlreadyKept.remove(kept);
kept.setAmount(kept.getAmount() + ItemStackUtils.getSize(stack));
localAlreadyKept.add(kept);
return true;
}
localAlreadyKept.add(new ItemStorage(stack));
return true;
}
}
return false;
}
Aggregations