Search in sources :

Example 6 with ElementEnum

use of minechem.item.element.ElementEnum 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 7 with ElementEnum

use of minechem.item.element.ElementEnum in project Minechem by iopleke.

the class PolytoolInventoryRender method renderItem.

@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
    GL11.glPushMatrix();
    ArrayList upgrades = PolytoolItem.getUpgrades(item);
    int count = 1;
    float red = 0F;
    float green = 0F;
    float blue = 0F;
    for (int i = 0; i < upgrades.size(); i++) {
        for (int j = 0; j < ((PolytoolUpgradeType) upgrades.get(i)).power; j++) {
            count++;
        }
    }
    for (int i = 0; i < upgrades.size(); i++) {
        for (int j = 0; j < ((PolytoolUpgradeType) upgrades.get(i)).power; j++) {
            ElementEnum element = ((PolytoolUpgradeType) upgrades.get(i)).getElement();
            red += (1 / count) * getRed(element);
            green += (1 / count) * getGreen(element);
            blue += (1 / count) * getBlue(element);
        }
    }
    GL11.glColor3f(red, green, blue);
    // Get icon index for the texture
    IIcon icon = item.getIconIndex();
    // Use vanilla code to render the icon in a 16x16 square of inventory slot
    renderItem.renderIcon(0, 0, icon, 16, 16);
    GL11.glPopMatrix();
}
Also used : ElementEnum(minechem.item.element.ElementEnum) IIcon(net.minecraft.util.IIcon) ArrayList(java.util.ArrayList)

Example 8 with ElementEnum

use of minechem.item.element.ElementEnum in project Minechem by iopleke.

the class ChemicalBucketNEIRecipeHandler method loadCraftingRecipes.

@Override
public void loadCraftingRecipes(ItemStack result) {
    if (result.getItem() instanceof MinechemBucketItem) {
        MinechemBucketItem bucket = (MinechemBucketItem) result.getItem();
        List<ItemStack> recipe = new ArrayList<ItemStack>();
        Item type = bucket.chemical instanceof ElementEnum ? MinechemItemsRegistration.element : MinechemItemsRegistration.molecule;
        int meta = bucket.chemical instanceof ElementEnum ? ((ElementEnum) bucket.chemical).atomicNumber() : ((MoleculeEnum) bucket.chemical).id();
        for (int i = 0; i < 4; i++) recipe.add(new ItemStack(type, 1, meta));
        recipe.add(new ItemStack(Items.bucket));
        for (int i = 0; i < 4; i++) recipe.add(new ItemStack(type, 1, meta));
        arecipes.add(new CachedShapelessRecipe(recipe, result));
    } else if (Compare.isStackAnElement(result)) {
        ItemStack recipe = new ItemStack(MinechemBucketHandler.getInstance().getBucket(ElementItem.getElement(result)));
        arecipes.add(new CachedShapelessRecipe(new ItemStack[] { recipe }, new ItemStack(result.getItem(), 8, result.getItemDamage())));
    } else if (Compare.isStackAMolecule(result)) {
        ItemStack recipe = new ItemStack(MinechemBucketHandler.getInstance().getBucket(MoleculeItem.getMolecule(result)));
        arecipes.add(new CachedShapelessRecipe(new ItemStack[] { recipe }, new ItemStack(result.getItem(), 8, result.getItemDamage())));
    }
}
Also used : ElementEnum(minechem.item.element.ElementEnum) MinechemBucketItem(minechem.item.bucket.MinechemBucketItem) Item(net.minecraft.item.Item) ElementItem(minechem.item.element.ElementItem) MoleculeItem(minechem.item.molecule.MoleculeItem) MinechemBucketItem(minechem.item.bucket.MinechemBucketItem) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 9 with ElementEnum

use of minechem.item.element.ElementEnum in project Minechem by iopleke.

the class MinechemBucketHandler method registerBucketDecomposerRecipe.

private void registerBucketDecomposerRecipe(ItemStack itemStack, MinechemChemicalType type) {
    ArrayList<PotionChemical> tubes = new ArrayList<PotionChemical>();
    tubes.add(new Element(ElementEnum.Fe, 48));
    if (type instanceof ElementEnum) {
        tubes.add(new Element((ElementEnum) type, 8));
    } else if (type instanceof MoleculeEnum) {
        tubes.add(new Molecule((MoleculeEnum) type, 8));
    }
    DecomposerRecipe.add(new DecomposerRecipe(itemStack, tubes));
}
Also used : ElementEnum(minechem.item.element.ElementEnum) Molecule(minechem.item.molecule.Molecule) Element(minechem.item.element.Element) ArrayList(java.util.ArrayList) PotionChemical(minechem.potion.PotionChemical) MoleculeEnum(minechem.item.molecule.MoleculeEnum) DecomposerRecipe(minechem.tileentity.decomposer.DecomposerRecipe)

Example 10 with ElementEnum

use of minechem.item.element.ElementEnum in project Minechem by iopleke.

the class ChemicalFluidReactionHandler method chemicalReaction.

private static void chemicalReaction(World world, Entity entity, int x, int y, int z, ChemicalFluidReactionRule rule, boolean popFlowingFluid) {
    ChemicalFluidReactionOutput output = reactionRules.get(rule);
    if (output == null) {
        return;
    }
    if (!Float.isNaN(output.explosionLevel)) {
        world.createExplosion(null, x, y, z, output.explosionLevel, true);
    }
    int halfSpace = FLUIDS_GENERATE_SPACE / 2;
    List[] availableSpaces = new List[FLUIDS_GENERATE_SPACE];
    for (int i = 0; i < availableSpaces.length; i++) {
        availableSpaces[i] = findAvailableSpacesAtCrossSection(world, x, y - halfSpace + i, z, 1);
    }
    Iterator<MinechemChemicalType> it = output.outputs.iterator();
    while (it.hasNext()) {
        MinechemChemicalType chemical = it.next();
        boolean hasFlowingStatus = chemical.roomState().getQuanta() > 2;
        CoordTuple coords = null;
        if (!(!hasFlowingStatus && popFlowingFluid)) {
            boolean isGas = chemical.roomState().isGas();
            if (isGas) {
                for (int i = availableSpaces.length - 1; i > -1; i--) {
                    if (!availableSpaces[i].isEmpty()) {
                        coords = (CoordTuple) availableSpaces[i].remove(availableSpaces[i].size() - 1);
                        break;
                    }
                }
            } else {
                for (int i = 0; i < availableSpaces.length; i++) {
                    if (!availableSpaces[i].isEmpty()) {
                        coords = (CoordTuple) availableSpaces[i].remove(availableSpaces[i].size() - 1);
                        break;
                    }
                }
            }
        }
        if (coords == null) {
            if (!popFlowingFluid) {
                ItemStack itemStack = MinechemUtil.createItemStack(chemical, 8);
                MinechemUtil.throwItemStack(world, itemStack, x, y, z);
            }
        } else if (!(popFlowingFluid && !hasFlowingStatus)) {
            int px = coords.getX();
            int py = coords.getY();
            int pz = coords.getZ();
            world.func_147480_a(px, py, pz, true);
            world.setBlockToAir(px, py, pz);
            Block fluidBlock = null;
            if (chemical instanceof ElementEnum) {
                fluidBlock = FluidHelper.elementsBlocks.get(FluidHelper.elements.get(chemical));
            } else if (chemical instanceof MoleculeEnum) {
                fluidBlock = FluidHelper.moleculeBlocks.get(FluidHelper.molecules.get(chemical));
            }
            if (fluidBlock != null) {
                world.setBlock(px, py, pz, fluidBlock, popFlowingFluid ? 1 : 0, 3);
            }
        }
    }
}
Also used : ElementEnum(minechem.item.element.ElementEnum) Block(net.minecraft.block.Block) MinechemFluidBlock(minechem.fluid.MinechemFluidBlock) ArrayList(java.util.ArrayList) List(java.util.List) CoordTuple(minechem.utils.CoordTuple) MoleculeEnum(minechem.item.molecule.MoleculeEnum) ItemStack(net.minecraft.item.ItemStack) MinechemChemicalType(minechem.item.MinechemChemicalType)

Aggregations

ElementEnum (minechem.item.element.ElementEnum)10 MoleculeEnum (minechem.item.molecule.MoleculeEnum)6 ItemStack (net.minecraft.item.ItemStack)5 ArrayList (java.util.ArrayList)4 MinechemChemicalType (minechem.item.MinechemChemicalType)3 MinechemBucketItem (minechem.item.bucket.MinechemBucketItem)3 ElementItem (minechem.item.element.ElementItem)3 MoleculeItem (minechem.item.molecule.MoleculeItem)3 Item (net.minecraft.item.Item)3 Element (minechem.item.element.Element)2 PotionChemical (minechem.potion.PotionChemical)2 DecomposerRecipe (minechem.tileentity.decomposer.DecomposerRecipe)2 Block (net.minecraft.block.Block)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 List (java.util.List)1 MinechemFluidBlock (minechem.fluid.MinechemFluidBlock)1 ItemBlueprint (minechem.item.blueprint.ItemBlueprint)1 MinechemBlueprint (minechem.item.blueprint.MinechemBlueprint)1 Molecule (minechem.item.molecule.Molecule)1 RadiationFluidTileEntity (minechem.radiation.RadiationFluidTileEntity)1