Search in sources :

Example 1 with MoleculeItem

use of minechem.item.molecule.MoleculeItem in project Minechem by iopleke.

the class MinechemItemsRegistration method init.

public static void init() {
    element = new ElementItem();
    GameRegistry.registerItem(element, Reference.ID + "Element");
    molecule = new MoleculeItem();
    GameRegistry.registerItem(molecule, Reference.ID + "Molecule");
    lens = new OpticalMicroscopeLens();
    concaveLens = new ItemStack(lens, 1, 0);
    convexLens = new ItemStack(lens, 1, 1);
    microscopeLens = new ItemStack(lens, 1, 2);
    projectorLens = new ItemStack(lens, 1, 3);
    GameRegistry.registerItem(lens, Reference.ID + "OpticalMicroscopeLens");
    atomicManipulator = new ItemAtomicManipulator();
    GameRegistry.registerItem(atomicManipulator, Reference.ID + "AtomicManipulator");
    blueprint = new ItemBlueprint();
    GameRegistry.registerItem(blueprint, Reference.ID + "Blueprint");
    journal = new ChemistJournalItem();
    GameRegistry.registerItem(journal, Reference.ID + "Journal");
    polytool = new PolytoolItem();
    GameRegistry.registerItem(polytool, Reference.ID + "Polytool");
    emptyTube = new ItemStack(MinechemItemsRegistration.element, 1, 0);
}
Also used : ElementItem(minechem.item.element.ElementItem) ItemBlueprint(minechem.item.blueprint.ItemBlueprint) OpticalMicroscopeLens(minechem.item.OpticalMicroscopeLens) ItemAtomicManipulator(minechem.item.ItemAtomicManipulator) MoleculeItem(minechem.item.molecule.MoleculeItem) ChemistJournalItem(minechem.item.chemistjournal.ChemistJournalItem) PolytoolItem(minechem.item.polytool.PolytoolItem) ItemStack(net.minecraft.item.ItemStack)

Example 2 with MoleculeItem

use of minechem.item.molecule.MoleculeItem in project Minechem by iopleke.

the class PotionSpikingRecipe method getCraftingResult.

@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
    for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack foodItem = inv.getStackInSlot(i);
        if (foodItem != null && foodItem.getItem() instanceof ItemFood) {
            for (int j = 0; j < inv.getSizeInventory(); j++) {
                ItemStack moleculeStack = inv.getStackInSlot(j);
                if (moleculeStack != null && moleculeStack.getItem() instanceof MoleculeItem && PharmacologyEffectRegistry.hasEffect(MoleculeEnum.getById(moleculeStack.getItemDamage()))) {
                    ItemStack result = foodItem.copy();
                    result.stackSize = 1;
                    if (// empty NBT
                    result.stackTagCompound == null) {
                        NBTTagCompound tagCompound = new NBTTagCompound();
                        tagCompound.setBoolean("minechem.isPoisoned", true);
                        tagCompound.setIntArray("minechem.effectTypes", new int[] { MoleculeItem.getMolecule(moleculeStack).id() });
                        result.setTagCompound(tagCompound);
                    } else if (// has been poisoned before
                    result.stackTagCompound.hasKey("minechem.isPoisoned")) {
                        int[] arrayOld = result.stackTagCompound.getIntArray("minechem.effectTypes");
                        int[] arrayNew = new int[arrayOld.length + 1];
                        System.arraycopy(arrayOld, 0, arrayNew, 0, arrayOld.length);
                        arrayNew[arrayOld.length] = MoleculeItem.getMolecule(moleculeStack).id();
                        result.stackTagCompound.setIntArray("minechem.effectTypes", arrayNew);
                    } else // has NBT but no poison
                    {
                        result.stackTagCompound.setBoolean("minechem.isPoisoned", true);
                        result.stackTagCompound.setIntArray("minechem.effectTypes", new int[] { MoleculeItem.getMolecule(moleculeStack).id() });
                    }
                    this.result = result.copy();
                    return result;
                }
            }
        }
    }
    return null;
}
Also used : ItemFood(net.minecraft.item.ItemFood) MoleculeItem(minechem.item.molecule.MoleculeItem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 3 with MoleculeItem

use of minechem.item.molecule.MoleculeItem in project Minechem by iopleke.

the class FluidChemicalDispenser method dispense.

@Override
public ItemStack dispense(IBlockSource blockSource, ItemStack itemStack) {
    EnumFacing enumfacing = BlockDispenser.func_149937_b(blockSource.getBlockMetadata());
    World world = blockSource.getWorld();
    int x = blockSource.getXInt() + enumfacing.getFrontOffsetX();
    int y = blockSource.getYInt() + enumfacing.getFrontOffsetY();
    int z = blockSource.getZInt() + enumfacing.getFrontOffsetZ();
    TileEntity inventoryTile = blockSource.getBlockTileEntity();
    if (itemStack.getItem() instanceof ElementItem && itemStack.getItemDamage() != 0) {
        Block frontBlock = world.getBlock(x, y, z);
        MinechemChemicalType chemical = MinechemUtil.getChemical(frontBlock);
        if (chemical != null && MinechemUtil.canDrain(world, frontBlock, x, y, z)) {
            ItemStack stack = MinechemUtil.createItemStack(chemical, 8);
            if (stack != null) {
                if (itemStack.stackSize >= 8) {
                    itemStack.stackSize -= 8;
                } else {
                    if (inventoryTile instanceof IInventory) {
                        int needs = 8 - itemStack.stackSize;
                        IInventory inventory = (IInventory) inventoryTile;
                        Set<ItemStack> otherTubes = MinechemUtil.findItemStacks(inventory, MinechemItemsRegistration.element, 0);
                        int free = 0;
                        otherTubes.remove(itemStack);
                        for (ItemStack emptyStack : otherTubes) {
                            free += emptyStack.stackSize;
                        }
                        if (free < needs) {
                            return itemStack;
                        }
                        itemStack.stackSize = 0;
                        for (ItemStack emptyStack : otherTubes) {
                            if (emptyStack.stackSize >= needs) {
                                emptyStack.stackSize -= needs;
                                needs = 0;
                            } else {
                                needs -= emptyStack.stackSize;
                                emptyStack.stackSize = 0;
                            }
                            if (emptyStack.stackSize <= 0) {
                                MinechemUtil.removeStackInInventory(inventory, emptyStack);
                            }
                            if (needs == 0) {
                                break;
                            }
                        }
                    }
                }
                TileEntity tile = world.getTileEntity(x, y, z);
                if (tile instanceof RadiationFluidTileEntity && ((RadiationFluidTileEntity) tile).info != null) {
                    RadiationInfo.setRadiationInfo(((RadiationFluidTileEntity) tile).info, stack);
                }
                world.setBlockToAir(x, y, z);
                if (inventoryTile instanceof IInventory) {
                    stack = MinechemUtil.addItemToInventory((IInventory) inventoryTile, stack);
                }
                MinechemUtil.throwItemStack(world, stack, x, y, z);
            }
        }
    } else {
        IInventory inventory;
        Block block;
        if (inventoryTile instanceof IInventory) {
            inventory = (IInventory) inventoryTile;
        } else {
            return itemStack;
        }
        if (itemStack.getItem() instanceof ElementItem) {
            ElementEnum element = ElementItem.getElement(itemStack);
            block = FluidHelper.elementsBlocks.get(FluidHelper.elements.get(element));
        } else if (itemStack.getItem() instanceof MoleculeItem) {
            MoleculeEnum molecule = MoleculeEnum.getById(itemStack.getItemDamage());
            block = FluidHelper.moleculeBlocks.get(FluidHelper.molecules.get(molecule));
        } else {
            return itemStack;
        }
        if (!world.isAirBlock(x, y, z) && !world.getBlock(x, y, z).getMaterial().isSolid()) {
            world.func_147480_a(x, y, z, true);
            world.setBlockToAir(x, y, z);
        }
        if (world.isAirBlock(x, y, z)) {
            RadiationInfo radioactivity = ElementItem.getRadiationInfo(itemStack, world);
            long worldtime = world.getTotalWorldTime();
            long leftTime = radioactivity.radioactivity.getLife() - (worldtime - radioactivity.decayStarted);
            if (itemStack.stackSize >= 8) {
                itemStack.stackSize -= 8;
            } else {
                int needs = 8 - itemStack.stackSize;
                itemStack.stackSize = 0;
                Set<ItemStack> otherItemsStacks = MinechemUtil.findItemStacks(inventory, itemStack.getItem(), itemStack.getItemDamage());
                otherItemsStacks.remove(itemStack);
                int free = 0;
                for (ItemStack stack : otherItemsStacks) {
                    free += stack.stackSize;
                }
                if (free < needs) {
                    return itemStack;
                }
                for (ItemStack stack : otherItemsStacks) {
                    RadiationInfo anotherRadiation = ElementItem.getRadiationInfo(stack, world);
                    long anotherLeft = anotherRadiation.radioactivity.getLife() - (worldtime - anotherRadiation.decayStarted);
                    if (anotherLeft < leftTime) {
                        radioactivity = anotherRadiation;
                        leftTime = anotherLeft;
                    }
                    if (stack.stackSize >= needs) {
                        stack.stackSize -= needs;
                        needs = 0;
                    } else {
                        needs -= stack.stackSize;
                        stack.stackSize = 0;
                    }
                    if (stack.stackSize <= 0) {
                        MinechemUtil.removeStackInInventory(inventory, stack);
                    }
                    if (needs == 0) {
                        break;
                    }
                }
            }
            ItemStack empties = MinechemUtil.addItemToInventory(inventory, new ItemStack(MinechemItemsRegistration.element, 8, 0));
            MinechemUtil.throwItemStack(world, empties, x, y, z);
            world.setBlock(x, y, z, block, 0, 3);
            TileEntity tile = world.getTileEntity(x, y, z);
            if (radioactivity.isRadioactive() && tile instanceof RadiationFluidTileEntity) {
                ((RadiationFluidTileEntity) tile).info = radioactivity;
            }
        }
        return itemStack;
    // Block block = null;
    // RadiationEnum radioactivity = null;
    // if (itemStack.getItem() instanceof ElementItem)
    // {
    // ElementEnum element = ElementItem.getElement(itemStack);
    // block = FluidHelper.elementsBlocks.get(FluidHelper.elements.get(element));
    // radioactivity = element.radioactivity();
    // } else if (itemStack.getItem() instanceof MoleculeItem)
    // {
    // MoleculeEnum molecule = MoleculeEnum.getById(itemStack.getItemDamage());
    // block = FluidHelper.moleculeBlocks.get(FluidHelper.molecules.get(molecule));
    // radioactivity = molecule.radioactivity();
    // }
    // 
    // if (!world.isAirBlock(x, y, z) && !world.getBlock(x, y, z).getMaterial().isSolid())
    // {
    // world.func_147480_a(x, y, z, true);
    // world.setBlockToAir(x, y, z);
    // }
    // 
    // if (world.isAirBlock(x, y, z) && block != null)
    // {
    // world.setBlock(x, y, z, block, 0, 3);
    // --itemStack.stackSize;
    // TileEntity tile = world.getTileEntity(x, y, z);
    // if (radioactivity != RadiationEnum.stable && tile instanceof RadiationFluidTileEntity)
    // {
    // ((RadiationFluidTileEntity) tile).info = ElementItem.getRadiationInfo(itemStack, world);
    // }
    // ItemStack elementStack = new ItemStack(MinechemItemsRegistration.element, 1, ElementEnum.heaviestMass);
    // TileEntity inventoryTile = blockSource.getBlockTileEntity();
    // if (inventoryTile instanceof IInventory)
    // {
    // elementStack = MinechemUtil.addItemToInventory((IInventory) inventoryTile, elementStack);
    // }
    // MinechemUtil.throwItemStack(world, elementStack, x, y, z);
    // }
    }
    return itemStack;
}
Also used : ElementItem(minechem.item.element.ElementItem) IInventory(net.minecraft.inventory.IInventory) RadiationFluidTileEntity(minechem.radiation.RadiationFluidTileEntity) EnumFacing(net.minecraft.util.EnumFacing) MoleculeItem(minechem.item.molecule.MoleculeItem) World(net.minecraft.world.World) MinechemChemicalType(minechem.item.MinechemChemicalType) TileEntity(net.minecraft.tileentity.TileEntity) RadiationFluidTileEntity(minechem.radiation.RadiationFluidTileEntity) ElementEnum(minechem.item.element.ElementEnum) RadiationInfo(minechem.radiation.RadiationInfo) Block(net.minecraft.block.Block) MoleculeEnum(minechem.item.molecule.MoleculeEnum) ItemStack(net.minecraft.item.ItemStack)

Example 4 with MoleculeItem

use of minechem.item.molecule.MoleculeItem in project Minechem by iopleke.

the class PotionCoatingRecipe method getCraftingResult.

@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
    for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack s = inv.getStackInSlot(i);
        if (s != null && s.getItem() instanceof ItemSword) {
            for (int j = 0; j < inv.getSizeInventory(); j++) {
                ItemStack s2 = inv.getStackInSlot(j);
                if (s2 != null && s2.getItem() instanceof MoleculeItem && PharmacologyEffectRegistry.hasEffect(MoleculeEnum.getById(s2.getItemDamage()))) {
                    NBTTagList l = s2.getEnchantmentTagList();
                    int level = 0;
                    if (l != null) {
                        for (int k = 0; k < l.tagCount(); k++) {
                            NBTTagCompound tag = l.getCompoundTagAt(k);
                            if (tag.getShort("id") == PotionEnchantmentCoated.chemLookup.get(MoleculeEnum.getById(s2.getItemDamage())).effectId) {
                                level = tag.getShort("lvl");
                                ItemStack result = s.copy();
                                result.getEnchantmentTagList().getCompoundTagAt(k).setInteger("lvl", level + 1);
                            }
                        }
                    }
                    ItemStack result = s.copy();
                    result.addEnchantment(PotionEnchantmentCoated.chemLookup.get(MoleculeEnum.getById(s2.getItemDamage())), 1);
                    return result;
                }
            }
        }
    }
    return null;
}
Also used : ItemSword(net.minecraft.item.ItemSword) NBTTagList(net.minecraft.nbt.NBTTagList) MoleculeItem(minechem.item.molecule.MoleculeItem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 5 with MoleculeItem

use of minechem.item.molecule.MoleculeItem in project Minechem by iopleke.

the class RadiationMoleculeHandler method handleRadiationMoleculeBucket.

public RadiationInfo handleRadiationMoleculeBucket(World world, ItemStack itemStack, IInventory inventory, double x, double y, double z) {
    PotionChemical[] decayedChemicals = getDecayedMolecule((MoleculeEnum) ((MinechemBucketItem) itemStack.getItem()).chemical);
    for (int i = 0; i < decayedChemicals.length; i++) {
        decayedChemicals[i].amount *= 8 * itemStack.stackSize;
    }
    ItemStack[] items = toItemStacks(decayedChemicals);
    for (int i = 1; i < items.length; i++) {
        ItemStack stack = MinechemUtil.addItemToInventory(inventory, items[i]);
        if (stack != null) {
            MinechemUtil.throwItemStack(world, itemStack, x, y, z);
        }
    }
    Item item = items[0].getItem();
    if (item instanceof MoleculeItem) {
        itemStack.func_150996_a(MinechemBucketHandler.getInstance().buckets.get(FluidHelper.moleculeBlocks.get(FluidHelper.molecules.get(MoleculeItem.getMolecule(items[0])))));
    } else if (item instanceof ElementItem) {
        itemStack.func_150996_a(MinechemBucketHandler.getInstance().buckets.get(FluidHelper.elementsBlocks.get(FluidHelper.elements.get(ElementItem.getElement(items[0])))));
    }
    itemStack.stackSize = (items[0].stackSize / 8);
    itemStack.setTagCompound(items[0].stackTagCompound);
    return ElementItem.initiateRadioactivity(itemStack, world);
}
Also used : ElementItem(minechem.item.element.ElementItem) MinechemBucketItem(minechem.item.bucket.MinechemBucketItem) Item(net.minecraft.item.Item) ElementItem(minechem.item.element.ElementItem) MoleculeItem(minechem.item.molecule.MoleculeItem) MoleculeItem(minechem.item.molecule.MoleculeItem) MinechemBucketItem(minechem.item.bucket.MinechemBucketItem) PotionChemical(minechem.potion.PotionChemical) ItemStack(net.minecraft.item.ItemStack)

Aggregations

MoleculeItem (minechem.item.molecule.MoleculeItem)5 ItemStack (net.minecraft.item.ItemStack)5 ElementItem (minechem.item.element.ElementItem)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 ItemAtomicManipulator (minechem.item.ItemAtomicManipulator)1 MinechemChemicalType (minechem.item.MinechemChemicalType)1 OpticalMicroscopeLens (minechem.item.OpticalMicroscopeLens)1 ItemBlueprint (minechem.item.blueprint.ItemBlueprint)1 MinechemBucketItem (minechem.item.bucket.MinechemBucketItem)1 ChemistJournalItem (minechem.item.chemistjournal.ChemistJournalItem)1 ElementEnum (minechem.item.element.ElementEnum)1 MoleculeEnum (minechem.item.molecule.MoleculeEnum)1 PolytoolItem (minechem.item.polytool.PolytoolItem)1 PotionChemical (minechem.potion.PotionChemical)1 RadiationFluidTileEntity (minechem.radiation.RadiationFluidTileEntity)1 RadiationInfo (minechem.radiation.RadiationInfo)1 Block (net.minecraft.block.Block)1 IInventory (net.minecraft.inventory.IInventory)1 Item (net.minecraft.item.Item)1 ItemFood (net.minecraft.item.ItemFood)1