Search in sources :

Example 6 with ItemStorage

use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.

the class BuildingLumberjack method writeToNBT.

@Override
public void writeToNBT(@NotNull final NBTTagCompound compound) {
    super.writeToNBT(compound);
    @NotNull final NBTTagList saplingTagList = new NBTTagList();
    for (@NotNull final Map.Entry<ItemStorage, Boolean> entry : treesToFell.entrySet()) {
        @NotNull final NBTTagCompound saplingCompound = new NBTTagCompound();
        entry.getKey().getItemStack().writeToNBT(saplingCompound);
        saplingCompound.setBoolean(TAG_CUT, entry.getValue());
        saplingTagList.appendTag(saplingCompound);
    }
    compound.setTag(TAG_SAPLINGS, saplingTagList);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NotNull(org.jetbrains.annotations.NotNull) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 7 with ItemStorage

use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.

the class BuildingLumberjack method readFromNBT.

@Override
public void readFromNBT(@NotNull final NBTTagCompound compound) {
    super.readFromNBT(compound);
    if (treesToFell.isEmpty()) {
        final NBTTagList saplingTagList = compound.getTagList(TAG_SAPLINGS, Constants.NBT.TAG_COMPOUND);
        for (int i = 0; i < saplingTagList.tagCount(); ++i) {
            final NBTTagCompound saplingCompound = saplingTagList.getCompoundTagAt(i);
            final ItemStack stack = new ItemStack(saplingCompound);
            final boolean cut = saplingCompound.getBoolean(TAG_CUT);
            treesToFell.put(new ItemStorage(stack), cut);
        }
    }
    checkTreesToFell();
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 8 with ItemStorage

use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.

the class WindowBuildBuilding 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;
    }
    ItemStorage resource = resources.get(res.getUnlocalizedName());
    if (resource == null) {
        resource = new ItemStorage(res);
        resource.setAmount(amount);
    } else {
        resource.setAmount(resource.getAmount() + amount);
    }
    resources.put(res.getUnlocalizedName(), resource);
}
Also used : ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 9 with ItemStorage

use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.

the class WindowHutLumberjack method onButtonClicked.

@Override
public void onButtonClicked(@NotNull final Button button) {
    if (button.getID().equals(BUTTON_CURRENT_SAPLING)) {
        final int row = saplingsList.getListElementIndexByPane(button);
        final ItemStorage saplingStack = treesToFell.keySet().toArray(new ItemStorage[treesToFell.size()])[row];
        final boolean shouldCut = !treesToFell.get(saplingStack);
        treesToFell.put(saplingStack, shouldCut);
        MineColonies.getNetwork().sendToServer(new LumberjackSaplingSelectorMessage(building, saplingStack.getItemStack(), shouldCut));
        this.ownBuilding.treesToFell.clear();
        this.ownBuilding.treesToFell.putAll(treesToFell);
    } else if (button.getID().equals(BUTTON_TOGGLE_ALL)) {
        final boolean on = button.getLabel().equals(LanguageHandler.format(TOGGLE_ALL_OPTIONS_ON));
        if (on) {
            button.setLabel(LanguageHandler.format(TOGGLE_ALL_OPTIONS_OFF));
        } else {
            button.setLabel(LanguageHandler.format(TOGGLE_ALL_OPTIONS_ON));
        }
        for (final Map.Entry<ItemStorage, Boolean> entry : new HashSet<Map.Entry<ItemStorage, Boolean>>(treesToFell.entrySet())) {
            treesToFell.put(entry.getKey(), on);
        }
        this.ownBuilding.treesToFell.clear();
        this.ownBuilding.treesToFell.putAll(treesToFell);
    } else {
        super.onButtonClicked(button);
    }
}
Also used : LumberjackSaplingSelectorMessage(com.minecolonies.coremod.network.messages.LumberjackSaplingSelectorMessage) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 10 with ItemStorage

use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.

the class CompatabilityManager method connectLeaveToSapling.

@Override
public void connectLeaveToSapling(final IBlockState leave, final ItemStack stack) {
    final ItemStack tempStack = new ItemStack(leave.getBlock(), 1, leave.getBlock().getMetaFromState(leave));
    final IBlockState tempLeave = BlockLeaves.getBlockFromItem(tempStack.getItem()).getStateFromMeta(tempStack.getMetadata());
    if (!leavesToSaplingMap.containsKey(tempLeave) && !leavesToSaplingMap.containsValue(new ItemStorage(stack))) {
        leavesToSaplingMap.put(tempLeave, new ItemStorage(stack));
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Aggregations

ItemStorage (com.minecolonies.api.crafting.ItemStorage)11 ItemStack (net.minecraft.item.ItemStack)7 ArrayList (java.util.ArrayList)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 NBTTagList (net.minecraft.nbt.NBTTagList)3 List (java.util.List)2 Predicate (java.util.function.Predicate)2 Block (net.minecraft.block.Block)2 IBlockState (net.minecraft.block.state.IBlockState)2 CreativeTabs (net.minecraft.creativetab.CreativeTabs)2 NotNull (org.jetbrains.annotations.NotNull)2 BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 TypeToken (com.google.common.reflect.TypeToken)1 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)1 IDeliverable (com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)1 Stack (com.minecolonies.api.colony.requestsystem.requestable.Stack)1 Tool (com.minecolonies.api.colony.requestsystem.requestable.Tool)1