Search in sources :

Example 1 with BuildingBuilderResource

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

the class EntityAIStructureBuilder method getTotalAmount.

/**
     * Check how much of a certain stuck is actually required.
     *
     * @param stack the stack to check.
     * @return the new stack with the correct amount.
     */
@Override
@Nullable
public ItemStack getTotalAmount(@Nullable final ItemStack stack) {
    final AbstractBuildingWorker buildingWorker = getOwnBuilding();
    if (stack == null || stack.getItem() == null) {
        return null;
    }
    final BuildingBuilderResource resource = ((BuildingBuilder) buildingWorker).getNeededResources().get(stack.getUnlocalizedName());
    return resource == null ? stack : new ItemStack(resource.getItem(), resource.getAmount(), resource.getDamageValue());
}
Also used : AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) ItemStack(net.minecraft.item.ItemStack) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with BuildingBuilderResource

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

the class BuildingBuilder 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 (res.isEmpty() || amount == 0) {
        return;
    }
    BuildingBuilderResource resource = this.neededResources.get(res.getUnlocalizedName());
    if (resource == null) {
        resource = new BuildingBuilderResource(res.getItem(), res.getItemDamage(), amount);
    } else {
        resource.setAmount(resource.getAmount() + amount);
    }
    this.neededResources.put(res.getUnlocalizedName(), resource);
    this.markDirty();
}
Also used : BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)

Example 3 with BuildingBuilderResource

use of com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource 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()));
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityChest(net.minecraft.tileentity.TileEntityChest) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) InventoryCitizen(com.minecolonies.coremod.inventory.InventoryCitizen) BlockPos(net.minecraft.util.math.BlockPos) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) NotNull(org.jetbrains.annotations.NotNull) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with BuildingBuilderResource

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

the class BuildingBuilder method readFromNBT.

@Override
public void readFromNBT(@NotNull final NBTTagCompound compound) {
    super.readFromNBT(compound);
    final NBTTagList neededResTagList = compound.getTagList(TAG_RESOURCE_LIST, Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < neededResTagList.tagCount(); ++i) {
        final NBTTagCompound neededRes = neededResTagList.getCompoundTagAt(i);
        final ItemStack stack = new ItemStack(neededRes);
        final BuildingBuilderResource resource = new BuildingBuilderResource(stack.getItem(), stack.getItemDamage(), stack.getCount());
        neededResources.put(stack.getUnlocalizedName(), resource);
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)

Example 5 with BuildingBuilderResource

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

the class WindowHutBuilder method updateResourcePane.

/**
     * Update one row pad with its resource informations.
     *
     * @param index   index in the list of resources.
     * @param rowPane The Pane to use to display the information.
     */
private void updateResourcePane(final int index, @NotNull final Pane rowPane) {
    final BuildingBuilderResource resource = resources.get(index);
    final Label resourceLabel = rowPane.findPaneOfTypeByID(RESOURCE_NAME, Label.class);
    final Label resourceMissingLabel = rowPane.findPaneOfTypeByID(RESOURCE_MISSING, Label.class);
    final Label neededLabel = rowPane.findPaneOfTypeByID(RESOURCE_AVAILABLE_NEEDED, Label.class);
    final Button addButton = rowPane.findPaneOfTypeByID(RESOURCE_ADD, Button.class);
    switch(resource.getAvailabilityStatus()) {
        case DONT_HAVE:
            addButton.disable();
            resourceLabel.setColor(RED, RED);
            resourceMissingLabel.setColor(RED, RED);
            neededLabel.setColor(RED, RED);
            break;
        case NEED_MORE:
            addButton.enable();
            resourceLabel.setColor(RED, RED);
            resourceMissingLabel.setColor(RED, RED);
            neededLabel.setColor(RED, RED);
            break;
        case HAVE_ENOUGH:
            addButton.enable();
            resourceLabel.setColor(DARKGREEN, DARKGREEN);
            resourceMissingLabel.setColor(DARKGREEN, DARKGREEN);
            neededLabel.setColor(DARKGREEN, DARKGREEN);
            break;
        case NOT_NEEDED:
        default:
            addButton.disable();
            resourceLabel.setColor(BLACK, BLACK);
            resourceMissingLabel.setColor(BLACK, BLACK);
            neededLabel.setColor(BLACK, BLACK);
            break;
    }
    //position the addResource Button to the right
    final int buttonX = rowPane.getWidth() - addButton.getWidth() - (rowPane.getHeight() - addButton.getHeight()) / 2;
    final int buttonY = rowPane.getHeight() - addButton.getHeight() - 2;
    addButton.setPosition(buttonX, buttonY);
    resourceLabel.setLabelText(resource.getName());
    final int missing = resource.getMissingFromPlayer();
    if (missing < 0) {
        resourceMissingLabel.setLabelText(Integer.toString(missing));
    } else {
        resourceMissingLabel.setLabelText("");
    }
    neededLabel.setLabelText(Integer.toString(resource.getAvailable()) + " / " + Integer.toString(resource.getAmount()));
    rowPane.findPaneOfTypeByID(RESOURCE_ID, Label.class).setLabelText(Integer.toString(index));
    rowPane.findPaneOfTypeByID(RESOURCE_QUANTITY_MISSING, Label.class).setLabelText(Integer.toString(resource.getAmount() - resource.getAvailable()));
    rowPane.findPaneOfTypeByID(RESOURCE_ICON, ItemIcon.class).setItem(new ItemStack(resource.getItem(), 1, resource.getDamageValue()));
}
Also used : Button(com.minecolonies.blockout.controls.Button) Label(com.minecolonies.blockout.controls.Label) ItemIcon(com.minecolonies.blockout.controls.ItemIcon) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) ItemStack(net.minecraft.item.ItemStack)

Aggregations

BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)10 ItemStack (net.minecraft.item.ItemStack)6 NotNull (org.jetbrains.annotations.NotNull)4 Label (com.minecolonies.blockout.controls.Label)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)2 Pane (com.minecolonies.blockout.Pane)1 Button (com.minecolonies.blockout.controls.Button)1 ItemIcon (com.minecolonies.blockout.controls.ItemIcon)1 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)1 AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)1 BuildingBuilderView (com.minecolonies.coremod.colony.buildings.views.BuildingBuilderView)1 EntityCitizen (com.minecolonies.coremod.entity.EntityCitizen)1 InventoryCitizen (com.minecolonies.coremod.inventory.InventoryCitizen)1 TransferItemsRequestMessage (com.minecolonies.coremod.network.messages.TransferItemsRequestMessage)1 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)1 TileEntity (net.minecraft.tileentity.TileEntity)1