<commit_before>package mcjty.rftools.items.storage;

import cofh.api.energy.IEnergyContainerItem;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mcjty.rftools.RFTools;
import mcjty.rftools.blocks.dimlets.DimletConfiguration;
import mcjty.rftools.blocks.storage.ModularStorageConfiguration;
import mcjty.rftools.blocks.storage.ModularStorageSetup;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;

import java.util.List;

public class StorageModuleTabletItem extends Item implements IEnergyContainerItem {

    private int capacity;
    private int maxReceive;
    private int maxExtract;

    private IIcon iconFull;
    private IIcon iconEmpty;

    public static final int DAMAGE_EMPTY = 0;
    public static final int DAMAGE_FULL = 1;

    public StorageModuleTabletItem() {
        setMaxStackSize(1);

        capacity = ModularStorageConfiguration.TABLET_MAXENERGY;
        maxReceive = ModularStorageConfiguration.TABLET_RECEIVEPERTICK;
        maxExtract = ModularStorageConfiguration.TABLET_CONSUMEPERUSE;
    }

    @Override
    public int getMaxItemUseDuration(ItemStack stack) {
        return 1;
    }

    @Override
    public void registerIcons(IIconRegister iconRegister) {
        iconFull = iconRegister.registerIcon(RFTools.MODID + ":storage/storageModuleTablet");
        iconEmpty = iconRegister.registerIcon(RFTools.MODID + ":storage/storageModuleTabletEmpty");
    }

    @Override
    @SideOnly(Side.CLIENT)
    public IIcon getIconFromDamage(int damage) {
        if (damage == DAMAGE_EMPTY) {
            return iconEmpty;
        } else {
            return iconFull;
        }
    }

    @Override
    public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
        if (!world.isRemote) {
            NBTTagCompound tagCompound = stack.getTagCompound();
            if (tagCompound == null || !tagCompound.hasKey("childDamage")) {
                RFTools.message(player, EnumChatFormatting.YELLOW + "This tablet contains no storage module!");
                return stack;
            }

            int moduleDamage = tagCompound.getInteger("childDamage");
            int rfNeeded = ModularStorageConfiguration.TABLET_CONSUMEPERUSE;
            if (moduleDamage != StorageModuleItem.STORAGE_REMOTE) {
                rfNeeded += ModularStorageConfiguration.TABLET_EXTRACONSUME * (moduleDamage + 1);
            }

            int energy = tagCompound.getInteger("Energy");
            if (energy < rfNeeded) {
                RFTools.message(player, EnumChatFormatting.YELLOW + "Not enough energy to open the contents!");
                return stack;
            }

            energy -= rfNeeded;
            tagCompound.setInteger("Energy", energy);

            if (moduleDamage == StorageModuleItem.STORAGE_REMOTE) {
                if (!tagCompound.hasKey("id")) {
                    RFTools.message(player, EnumChatFormatting.YELLOW + "This remote storage module is not linked!");
                    return stack;
                }
                player.openGui(RFTools.instance, RFTools.GUI_REMOTE_STORAGE_ITEM, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
            } else {
                player.openGui(RFTools.instance, RFTools.GUI_MODULAR_STORAGE_ITEM, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
            }
            return stack;
        }
        return stack;
    }

    @Override
    public boolean hasContainerItem(ItemStack stack) {
        if (stack.getItemDamage() == DAMAGE_FULL) {
            return true;
        }
        return super.hasContainerItem(stack);
    }

    @Override
    public Item getContainerItem() {
        return ModularStorageSetup.storageModuleTabletItem;
    }

    @Override
    public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean whatIsThis) {
        super.addInformation(itemStack, player, list, whatIsThis);
        NBTTagCompound tagCompound = itemStack.getTagCompound();
        if (tagCompound != null) {
            list.add(EnumChatFormatting.BLUE + "Energy: " + tagCompound.getInteger("Energy") + " RF");
            if (itemStack.getItemDamage() == DAMAGE_FULL) {
                int max = StorageModuleItem.MAXSIZE[tagCompound.getInteger("moduleDamage")];
                StorageModuleItem.addModuleInformation(list, max, tagCompound);
            } else {
                list.add(EnumChatFormatting.YELLOW + "No storage module installed!");
            }
        }
        list.add("This RF/charged module can hold a storage module");
        list.add("and allows the wielder to manipulate the contents of");<commit_msg>Uncrafting the tablet doesn't get rid of the stored energy<commit_after>package mcjty.rftools.items.storage;

import cofh.api.energy.IEnergyContainerItem;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mcjty.rftools.RFTools;
import mcjty.rftools.blocks.dimlets.DimletConfiguration;
import mcjty.rftools.blocks.storage.ModularStorageConfiguration;
import mcjty.rftools.blocks.storage.ModularStorageSetup;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;

import java.util.List;

public class StorageModuleTabletItem extends Item implements IEnergyContainerItem {

    private int capacity;
    private int maxReceive;
    private int maxExtract;

    private IIcon iconFull;
    private IIcon iconEmpty;

    public static final int DAMAGE_EMPTY = 0;
    public static final int DAMAGE_FULL = 1;

    public StorageModuleTabletItem() {
        setMaxStackSize(1);

        capacity = ModularStorageConfiguration.TABLET_MAXENERGY;
        maxReceive = ModularStorageConfiguration.TABLET_RECEIVEPERTICK;
        maxExtract = ModularStorageConfiguration.TABLET_CONSUMEPERUSE;
    }

    @Override
    public int getMaxItemUseDuration(ItemStack stack) {
        return 1;
    }

    @Override
    public void registerIcons(IIconRegister iconRegister) {
        iconFull = iconRegister.registerIcon(RFTools.MODID + ":storage/storageModuleTablet");
        iconEmpty = iconRegister.registerIcon(RFTools.MODID + ":storage/storageModuleTabletEmpty");
    }

    @Override
    @SideOnly(Side.CLIENT)
    public IIcon getIconFromDamage(int damage) {
        if (damage == DAMAGE_EMPTY) {
            return iconEmpty;
        } else {
            return iconFull;
        }
    }

    @Override
    public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
        if (!world.isRemote) {
            NBTTagCompound tagCompound = stack.getTagCompound();
            if (tagCompound == null || !tagCompound.hasKey("childDamage")) {
                RFTools.message(player, EnumChatFormatting.YELLOW + "This tablet contains no storage module!");
                return stack;
            }

            int moduleDamage = tagCompound.getInteger("childDamage");
            int rfNeeded = ModularStorageConfiguration.TABLET_CONSUMEPERUSE;
            if (moduleDamage != StorageModuleItem.STORAGE_REMOTE) {
                rfNeeded += ModularStorageConfiguration.TABLET_EXTRACONSUME * (moduleDamage + 1);
            }

            int energy = tagCompound.getInteger("Energy");
            if (energy < rfNeeded) {
                RFTools.message(player, EnumChatFormatting.YELLOW + "Not enough energy to open the contents!");
                return stack;
            }

            energy -= rfNeeded;
            tagCompound.setInteger("Energy", energy);

            if (moduleDamage == StorageModuleItem.STORAGE_REMOTE) {
                if (!tagCompound.hasKey("id")) {
                    RFTools.message(player, EnumChatFormatting.YELLOW + "This remote storage module is not linked!");
                    return stack;
                }
                player.openGui(RFTools.instance, RFTools.GUI_REMOTE_STORAGE_ITEM, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
            } else {
                player.openGui(RFTools.instance, RFTools.GUI_MODULAR_STORAGE_ITEM, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
            }
            return stack;
        }
        return stack;
    }

    @Override
    public boolean hasContainerItem(ItemStack stack) {
        if (stack.getItemDamage() == DAMAGE_FULL) {
            return true;
        }
        return super.hasContainerItem(stack);
    }

    @Override
    public Item getContainerItem() {
        return ModularStorageSetup.storageModuleTabletItem;
    }

    @Override
    public ItemStack getContainerItem(ItemStack stack) {
        if (hasContainerItem(stack)) {
            NBTTagCompound tagCompound = new NBTTagCompound();
            tagCompound.setInteger("Energy", stack.getTagCompound().getInteger("Energy"));
            ItemStack container = new ItemStack(getContainerItem());
            container.setTagCompound(tagCompound);
            return container;
        }
        return null;
    }

    @Override
    public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean whatIsThis) {
        super.addInformation(itemStack, player, list, whatIsThis);
        NBTTagCompound tagCompound = itemStack.getTagCompound();
        if (tagCompound != null) {
            list.add(EnumChatFormatting.BLUE + "Energy: " + tagCompound.getInteger("Energy") + " RF");
            if (itemStack.getItemDamage() == DAMAGE_FULL) {
                int max = StorageModuleItem.MAXSIZE[tagCompound.getInteger("moduleDamage")];
                StorageModuleItem.addModuleInformation(list, max, tagCompound);
            } else {
                list.add(EnumChatFormatting.YELLOW + "No storage module installed!");
            }
        }
        list.add("This RF/charged module can hold a storage module");
        list.add("and allows the wielder to manipulate the contents of");
{'fraction_non_alphanumeric': 0.08988226285057911, 'fraction_numerical': 0.0009572125969177754, 'mean_word_length': 2.7868793040956867, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4231522', 'n_tokens_mistral': 3018, 'n_tokens_neox': 2917, 'n_words': 600}