Search in sources :

Example 1 with BuilderBucket

use of com.minecolonies.coremod.colony.buildings.utils.BuilderBucket in project minecolonies by Minecolonies.

the class AbstractEntityAIStructure method pickUpMaterial.

/**
 * State to pick up material before going back to work.
 *
 * @return the next state to go to.
 */
public IAIState pickUpMaterial() {
    if (structurePlacer == null || !structurePlacer.getB().hasBluePrint()) {
        return IDLE;
    }
    if (structurePlacer.getB().getStage() == null || structurePlacer.getB().getStage() == BuildingStructureHandler.Stage.CLEAR) {
        pickUpCount = 0;
        return START_WORKING;
    }
    final List<Tuple<Predicate<ItemStack>, Integer>> neededItemsList = new ArrayList<>();
    final BuilderBucket neededRessourcesMap = getOwnBuilding().getRequiredResources();
    final BuildingResourcesModule module = getOwnBuilding().getFirstModuleOccurance(BuildingResourcesModule.class);
    if (neededRessourcesMap != null) {
        for (final Map.Entry<String, Integer> entry : neededRessourcesMap.getResourceMap().entrySet()) {
            final BuildingBuilderResource res = module.getResourceFromIdentifier(entry.getKey());
            if (res != null) {
                int amount = entry.getValue();
                neededItemsList.add(new Tuple<>(itemstack -> ItemStackUtils.compareItemStacksIgnoreStackSize(res.getItemStack(), itemstack, true, true), amount));
            }
        }
    }
    if (neededItemsList.size() <= pickUpCount || InventoryUtils.openSlotCount(worker.getInventoryCitizen()) <= MIN_OPEN_SLOTS) {
        getOwnBuilding().checkOrRequestBucket(getOwnBuilding().getRequiredResources(), worker.getCitizenData(), true);
        getOwnBuilding().checkOrRequestBucket(getOwnBuilding().getNextBucket(), worker.getCitizenData(), false);
        pickUpCount = 0;
        return START_WORKING;
    }
    needsCurrently = neededItemsList.get(pickUpCount);
    pickUpCount++;
    if (InventoryUtils.hasItemInProvider(getOwnBuilding().getTileEntity(), needsCurrently.getA())) {
        return GATHERING_REQUIRED_MATERIALS;
    }
    return pickUpMaterial();
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) BLOCK_PLACE_SPEED(com.minecolonies.api.research.util.ResearchConstants.BLOCK_PLACE_SPEED) AirBlock(net.minecraft.block.AirBlock) IBuilderUndestroyable(com.minecolonies.api.entity.ai.citizen.builder.IBuilderUndestroyable) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) TriPredicate(net.minecraftforge.common.util.TriPredicate) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) Block(net.minecraft.block.Block) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) BlockTags(net.minecraft.tags.BlockTags) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) BlockState(net.minecraft.block.BlockState) CitizenConstants(com.minecolonies.api.util.constant.CitizenConstants) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) AIEventTarget(com.minecolonies.api.entity.ai.statemachine.AIEventTarget) Predicate(java.util.function.Predicate) BlueprintPositionInfo(com.ldtteam.structurize.util.BlueprintPositionInfo) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Nullable(org.jetbrains.annotations.Nullable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) BlockItem(net.minecraft.item.BlockItem) MineColonies(com.minecolonies.coremod.MineColonies) AbstractJobStructure(com.minecolonies.coremod.colony.jobs.AbstractJobStructure) IStructureHandler(com.ldtteam.structurize.placement.structure.IStructureHandler) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) BuilderBucket(com.minecolonies.coremod.colony.buildings.utils.BuilderBucket) java.util(java.util) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ModBlocks(com.minecolonies.api.blocks.ModBlocks) Mirror(net.minecraft.util.Mirror) ItemStack(net.minecraft.item.ItemStack) BuildingResourcesModule(com.minecolonies.coremod.colony.buildings.modules.BuildingResourcesModule) ImmutableList(com.google.common.collect.ImmutableList) AbstractBuildingStructureBuilder(com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder) Hand(net.minecraft.util.Hand) com.minecolonies.api.util(com.minecolonies.api.util) StructurePhasePlacementResult(com.ldtteam.structurize.placement.StructurePhasePlacementResult) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) BuildingStructureHandler(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler) ModTags(com.minecolonies.api.items.ModTags) AIBlockingEventType(com.minecolonies.api.entity.ai.statemachine.states.AIBlockingEventType) BlockPos(net.minecraft.util.math.BlockPos) NULL_POS(com.ldtteam.structurize.placement.AbstractBlueprintIterator.NULL_POS) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut) Blocks(net.minecraft.block.Blocks) Stage(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler.Stage) TypeConstants(com.minecolonies.api.util.constant.TypeConstants) BlockPlacementResult(com.ldtteam.structurize.placement.BlockPlacementResult) BlockUtils(com.ldtteam.structurize.util.BlockUtils) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) BlockFluidSubstitution(com.ldtteam.structurize.blocks.schematic.BlockFluidSubstitution) TileEntity(net.minecraft.tileentity.TileEntity) ItemCheckResult(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructure.ItemCheckResult) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) BuildingResourcesModule(com.minecolonies.coremod.colony.buildings.modules.BuildingResourcesModule) ItemStack(net.minecraft.item.ItemStack) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) BuilderBucket(com.minecolonies.coremod.colony.buildings.utils.BuilderBucket)

Example 2 with BuilderBucket

use of com.minecolonies.coremod.colony.buildings.utils.BuilderBucket in project minecolonies by ldtteam.

the class BuildingResourcesModule method addNeededResource.

/**
 * Add a new resource to the needed list.
 *
 * @param res    the resource.
 * @param amount the amount.
 */
public void addNeededResource(@Nullable final ItemStack res, final int amount) {
    if (ItemStackUtils.isEmpty(res) || amount == 0) {
        return;
    }
    final int hashCode = res.hasTag() ? res.getTag().hashCode() : 0;
    final String key = res.getDescriptionId() + "-" + hashCode;
    BuildingBuilderResource resource = this.neededResources.get(key);
    if (resource == null) {
        resource = new BuildingBuilderResource(res, amount);
    } else {
        resource.setAmount(resource.getAmount() + amount);
    }
    this.neededResources.put(key, resource);
    BuilderBucket last = buckets.isEmpty() ? null : buckets.removeLast();
    final int stacks = (int) Math.ceil((double) amount / res.getMaxStackSize());
    final int max = building.getAllAssignedCitizen().iterator().next().getInventory().getSlots() - 9;
    if (last == null || last.getTotalStacks() >= max || last.getTotalStacks() + stacks >= max) {
        if (last != null) {
            buckets.add(last);
        }
        last = new BuilderBucket();
        last.setTotalStacks(stacks);
        last.addOrAdjustResource(key, amount);
        buckets.add(last);
    } else {
        int currentQty = last.getResourceMap().getOrDefault(key, 0);
        final int currentStacks = (int) Math.ceil((double) currentQty / res.getMaxStackSize());
        final int newStacks = (int) Math.ceil((double) (currentQty + amount) / res.getMaxStackSize());
        final Map<String, Integer> map = last.getResourceMap();
        last.setTotalStacks(last.getTotalStacks() + newStacks - currentStacks);
        last.addOrAdjustResource(key, currentQty + amount);
        buckets.add(last);
    }
    this.markDirty();
}
Also used : BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) BuilderBucket(com.minecolonies.coremod.colony.buildings.utils.BuilderBucket)

Example 3 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)

Example 4 with BuilderBucket

use of com.minecolonies.coremod.colony.buildings.utils.BuilderBucket in project minecolonies by Minecolonies.

the class BuildingResourcesModule method addNeededResource.

/**
 * Add a new resource to the needed list.
 *
 * @param res    the resource.
 * @param amount the amount.
 */
public void addNeededResource(@Nullable final ItemStack res, final int amount) {
    if (ItemStackUtils.isEmpty(res) || amount == 0) {
        return;
    }
    final int hashCode = res.hasTag() ? res.getTag().hashCode() : 0;
    final String key = res.getDescriptionId() + "-" + hashCode;
    BuildingBuilderResource resource = this.neededResources.get(key);
    if (resource == null) {
        resource = new BuildingBuilderResource(res, amount);
    } else {
        resource.setAmount(resource.getAmount() + amount);
    }
    this.neededResources.put(key, resource);
    BuilderBucket last = buckets.isEmpty() ? null : buckets.removeLast();
    final int stacks = (int) Math.ceil((double) amount / res.getMaxStackSize());
    final int max = building.getAllAssignedCitizen().iterator().next().getInventory().getSlots() - 9;
    if (last == null || last.getTotalStacks() >= max || last.getTotalStacks() + stacks >= max) {
        if (last != null) {
            buckets.add(last);
        }
        last = new BuilderBucket();
        last.setTotalStacks(stacks);
        last.addOrAdjustResource(key, amount);
        buckets.add(last);
    } else {
        int currentQty = last.getResourceMap().getOrDefault(key, 0);
        final int currentStacks = (int) Math.ceil((double) currentQty / res.getMaxStackSize());
        final int newStacks = (int) Math.ceil((double) (currentQty + amount) / res.getMaxStackSize());
        final Map<String, Integer> map = last.getResourceMap();
        last.setTotalStacks(last.getTotalStacks() + newStacks - currentStacks);
        last.addOrAdjustResource(key, currentQty + amount);
        buckets.add(last);
    }
    this.markDirty();
}
Also used : BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) BuilderBucket(com.minecolonies.coremod.colony.buildings.utils.BuilderBucket)

Example 5 with BuilderBucket

use of com.minecolonies.coremod.colony.buildings.utils.BuilderBucket in project minecolonies by ldtteam.

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