use of com.minecolonies.coremod.colony.buildings.utils.BuilderBucket in project minecolonies by Minecolonies.
the class BuildingResourcesModule method reduceNeededResource.
/**
* Reduce a resource of the needed list.
*
* @param res the resource.
* @param amount the amount.
*/
public void reduceNeededResource(final ItemStack res, final int amount) {
final int hashCode = res.hasTag() ? res.getTag().hashCode() : 0;
final String name = res.getDescriptionId() + "-" + hashCode;
final BuilderBucket last = buckets.isEmpty() ? null : getRequiredResources();
if (last != null) {
final Map<String, Integer> map = last.getResourceMap();
if (map.containsKey(name)) {
int qty = map.get(name) - amount;
if (qty > 0) {
last.addOrAdjustResource(name, map.get(name) - amount);
} else {
last.removeResources(name);
}
}
if (map.isEmpty()) {
buckets.remove();
}
}
int preAmount = 0;
if (this.neededResources.containsKey(name)) {
preAmount = this.neededResources.get(name).getAmount();
}
if (preAmount - amount <= 0) {
this.neededResources.remove(name);
} else {
this.neededResources.get(name).setAmount(preAmount - amount);
}
this.markDirty();
}
Aggregations