Search in sources :

Example 6 with BuilderBucket

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();
}
Also used : BuilderBucket(com.minecolonies.coremod.colony.buildings.utils.BuilderBucket)

Aggregations

BuilderBucket (com.minecolonies.coremod.colony.buildings.utils.BuilderBucket)6 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)4 ImmutableList (com.google.common.collect.ImmutableList)2 Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)2 BlockFluidSubstitution (com.ldtteam.structurize.blocks.schematic.BlockFluidSubstitution)2 NULL_POS (com.ldtteam.structurize.placement.AbstractBlueprintIterator.NULL_POS)2 BlockPlacementResult (com.ldtteam.structurize.placement.BlockPlacementResult)2 StructurePhasePlacementResult (com.ldtteam.structurize.placement.StructurePhasePlacementResult)2 StructurePlacer (com.ldtteam.structurize.placement.StructurePlacer)2 IStructureHandler (com.ldtteam.structurize.placement.structure.IStructureHandler)2 BlockUtils (com.ldtteam.structurize.util.BlockUtils)2 BlueprintPositionInfo (com.ldtteam.structurize.util.BlueprintPositionInfo)2 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)2 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)2 ModBlocks (com.minecolonies.api.blocks.ModBlocks)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)2 IDeliverable (com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)2 Stack (com.minecolonies.api.colony.requestsystem.requestable.Stack)2 ItemStorage (com.minecolonies.api.crafting.ItemStorage)2