Search in sources :

Example 6 with BuildingBuilderResource

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

the class WindowHutBuilder method pullResourcesFromHut.

/**
     * Retrieve resources from the building to display in GUI.
     */
private void pullResourcesFromHut() {
    final AbstractBuilding.View newView = builder.getColony().getBuilding(builder.getID());
    if (newView instanceof BuildingBuilderView) {
        final BuildingBuilderView updatedView = (BuildingBuilderView) newView;
        final InventoryPlayer inventory = this.mc.player.inventory;
        resources.clear();
        resources.addAll(updatedView.getResources().values());
        for (final BuildingBuilderResource resource : resources) {
            resource.setPlayerAmount(InventoryUtils.getItemCountInItemHandler(new InvWrapper(inventory), resource.getItem(), resource.getDamageValue()));
        }
        resources.sort(new BuildingBuilderResource.ResourceComparator());
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) BuildingBuilderView(com.minecolonies.coremod.colony.buildings.views.BuildingBuilderView) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 7 with BuildingBuilderResource

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

the class WindowHutBuilder method transferItems.

/**
     * On Button click transfert Items.
     *
     * @param button the clicked button.
     */
private void transferItems(@NotNull final Button button) {
    final Pane pane = button.getParent();
    final Label idLabel = pane.findPaneOfTypeByID(RESOURCE_ID, Label.class);
    final int index = Integer.parseInt(idLabel.getLabelText());
    final BuildingBuilderResource res = resources.get(index);
    if (res == null) {
        Log.getLogger().warn("WindowHutBuilder.transferItems: Error - Could not find the resource.");
    } else {
        // The itemStack size should not be greater than itemStack.getMaxStackSize, We send 1 instead
        // and use quantity for the size
        @NotNull final ItemStack itemStack = new ItemStack(res.getItem(), 1, res.getDamageValue());
        final Label quantityLabel = pane.findPaneOfTypeByID(RESOURCE_QUANTITY_MISSING, Label.class);
        final int quantity = Integer.parseInt(quantityLabel.getLabelText());
        MineColonies.getNetwork().sendToServer(new TransferItemsRequestMessage(this.building, itemStack, quantity));
    }
}
Also used : Label(com.minecolonies.blockout.controls.Label) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) ItemStack(net.minecraft.item.ItemStack) Pane(com.minecolonies.blockout.Pane) NotNull(org.jetbrains.annotations.NotNull) TransferItemsRequestMessage(com.minecolonies.coremod.network.messages.TransferItemsRequestMessage)

Example 8 with BuildingBuilderResource

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

the class BuildingBuilderView method deserialize.

@Override
public void deserialize(@NotNull final ByteBuf buf) {
    super.deserialize(buf);
    final int size = buf.readInt();
    resources.clear();
    for (int i = 0; i < size; i++) {
        //Serialising the ItemStack give a bad ItemStack sometimes using itemId + damage instead
        //final ItemStack itemStack = ByteBufUtils.readItemStack(buf);
        final int itemId = buf.readInt();
        final int damage = buf.readInt();
        final ItemStack itemStack = new ItemStack(Item.getByNameOrId(Integer.toString(itemId)), 1, damage);
        final int amountAvailable = buf.readInt();
        final int amountNeeded = buf.readInt();
        final BuildingBuilderResource resource = new BuildingBuilderResource(itemStack.getItem(), itemStack.getItemDamage(), amountNeeded, amountAvailable);
        resources.put(itemStack.getDisplayName(), resource);
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)

Example 9 with BuildingBuilderResource

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

the class BuildingBuilder method writeToNBT.

@Override
public void writeToNBT(@NotNull final NBTTagCompound compound) {
    super.writeToNBT(compound);
    @NotNull final NBTTagList neededResTagList = new NBTTagList();
    for (@NotNull final BuildingBuilderResource resource : neededResources.values()) {
        @NotNull final NBTTagCompound neededRes = new NBTTagCompound();
        final ItemStack itemStack = new ItemStack(resource.getItem(), resource.getAmount(), resource.getDamageValue());
        itemStack.writeToNBT(neededRes);
        neededResTagList.appendTag(neededRes);
    }
    compound.setTag(TAG_RESOURCE_LIST, neededResTagList);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) ItemStack(net.minecraft.item.ItemStack) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with BuildingBuilderResource

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

the class BuildingBuilder method serializeToView.

/**
     * Method to serialize data to send it to the view.
     *
     * @param buf the used ByteBuffer.
     */
@Override
public void serializeToView(@NotNull final ByteBuf buf) {
    super.serializeToView(buf);
    updateAvailableResources();
    buf.writeInt(neededResources.size());
    for (@NotNull final Map.Entry<String, BuildingBuilderResource> entry : neededResources.entrySet()) {
        final BuildingBuilderResource resource = neededResources.get(entry.getKey());
        //ByteBufUtils.writeItemStack() is Buggy, serialize itemId and damage separately;
        final int itemId = Item.getIdFromItem(resource.getItem());
        final int damage = resource.getDamageValue();
        buf.writeInt(itemId);
        buf.writeInt(damage);
        buf.writeInt(resource.getAvailable());
        buf.writeInt(resource.getAmount());
    }
}
Also used : BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) NotNull(org.jetbrains.annotations.NotNull) HashMap(java.util.HashMap) Map(java.util.Map)

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