Search in sources :

Example 1 with FluidElement

use of minechem.fluid.FluidElement in project Minechem by iopleke.

the class FluidItemRenderingHandler method renderItem.

@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
    Fluid fluid = ((BlockFluidBase) ((ItemBlock) item.getItem()).field_150939_a).getFluid();
    if (fluid instanceof FluidElement) {
        RenderingUtil.setColorForElement(((FluidElement) fluid).element);
    } else if (fluid instanceof FluidMolecule) {
        MoleculeEnum molecule = ((FluidMolecule) fluid).molecule;
        GL11.glColor3f(molecule.red, molecule.green, molecule.blue);
    }
    IIcon icon = ((ItemBlock) item.getItem()).field_150939_a.getBlockTextureFromSide(0);
    switch(type) {
        case INVENTORY:
            RenderingUtil.drawTexturedRectUV(0, 0, 0, 16, 16, icon);
            break;
        case EQUIPPED_FIRST_PERSON:
        case EQUIPPED:
            ItemRenderer.renderItemIn2D(Tessellator.instance, icon.getMaxU(), icon.getMinV(), icon.getMinU(), icon.getMaxV(), icon.getIconWidth(), icon.getIconHeight(), 0.0625F);
            break;
        case ENTITY:
            EntityItem entityItem = (EntityItem) data[1];
            if (entityItem.worldObj == null) {
                float angle = (Minecraft.getSystemTime() % 8000L) / 8000.0F * 360.0F;
                GL11.glPushMatrix();
                GL11.glRotatef(angle, 0.0F, 1.0F, 0.0F);
                GL11.glTranslatef(-0.2F, -0.5F, 0.0F);
                renderItemAsEntity(item, icon);
                GL11.glPopMatrix();
            } else {
                renderItemAsEntity(item, icon);
            }
            break;
        default:
            break;
    }
}
Also used : FluidElement(minechem.fluid.FluidElement) BlockFluidBase(net.minecraftforge.fluids.BlockFluidBase) IIcon(net.minecraft.util.IIcon) Fluid(net.minecraftforge.fluids.Fluid) MoleculeEnum(minechem.item.molecule.MoleculeEnum) FluidMolecule(minechem.fluid.FluidMolecule) EntityItem(net.minecraft.entity.item.EntityItem)

Example 2 with FluidElement

use of minechem.fluid.FluidElement in project Minechem by iopleke.

the class ElementItem method onItemUseFirst.

@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    TileEntity te = world.getTileEntity(x, y, z);
    boolean result = !world.isRemote;
    if (te != null && te instanceof IFluidHandler && !player.isSneaking() && !(te instanceof IInventory)) {
        if (stack.getItemDamage() != 0) {
            int filled = 0;
            for (int i = 0; i < 6; i++) {
                FluidElement fluid = FluidHelper.elements.get(getElement(stack));
                if (fluid == null) {
                    return super.onItemUseFirst(stack, player, world, x, y, z, side, hitX, hitY, hitZ);
                }
                filled = ((IFluidHandler) te).fill(ForgeDirection.getOrientation(i), new FluidStack(fluid, 125), false);
                if (filled > 0) {
                    if (result) {
                        ((IFluidHandler) te).fill(ForgeDirection.getOrientation(i), new FluidStack(FluidHelper.elements.get(getElement(stack)), 125), true);
                    }
                    if (!player.capabilities.isCreativeMode) {
                        MinechemUtil.incPlayerInventory(stack, -1, player, new ItemStack(MinechemItemsRegistration.element, 1, 0));
                    }
                    return result || stack.stackSize <= 0;
                }
            }
        } else {
            FluidStack drained = null;
            Fluid fluid = MinechemUtil.getFluid((IFluidHandler) te);
            ElementEnum element = MinechemUtil.getElement(fluid);
            if (element != null) {
                for (int i = 0; i < 6; i++) {
                    drained = ((IFluidHandler) te).drain(ForgeDirection.getOrientation(i), new FluidStack(fluid, 125), false);
                    if (drained != null && drained.amount > 0) {
                        if (result) {
                            ((IFluidHandler) te).drain(ForgeDirection.getOrientation(i), new FluidStack(fluid, 125), true);
                        }
                        if (!player.capabilities.isCreativeMode) {
                            MinechemUtil.incPlayerInventory(stack, -1, player, new ItemStack(MinechemItemsRegistration.element, 1, element.atomicNumber()));
                        }
                        return result;
                    }
                }
            } else {
                MoleculeEnum molecule = MinechemUtil.getMolecule(fluid);
                if (fluid == FluidRegistry.WATER) {
                    molecule = MoleculeEnum.water;
                }
                if (molecule != null) {
                    for (int i = 0; i < 6; i++) {
                        drained = ((IFluidHandler) te).drain(ForgeDirection.getOrientation(i), new FluidStack(fluid, 125), false);
                        if (drained != null && drained.amount > 0) {
                            if (result) {
                                ((IFluidHandler) te).drain(ForgeDirection.getOrientation(i), new FluidStack(fluid, 125), true);
                            }
                            if (!player.capabilities.isCreativeMode) {
                                MinechemUtil.incPlayerInventory(stack, -1, player, new ItemStack(MinechemItemsRegistration.molecule, 1, molecule.id()));
                            }
                            return result;
                        }
                    }
                }
            }
        }
        return result;
    }
    return super.onItemUseFirst(stack, player, world, x, y, z, side, hitX, hitY, hitZ);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) RadiationFluidTileEntity(minechem.radiation.RadiationFluidTileEntity) IInventory(net.minecraft.inventory.IInventory) FluidElement(minechem.fluid.FluidElement) FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) MoleculeEnum(minechem.item.molecule.MoleculeEnum) ItemStack(net.minecraft.item.ItemStack) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Aggregations

FluidElement (minechem.fluid.FluidElement)2 MoleculeEnum (minechem.item.molecule.MoleculeEnum)2 Fluid (net.minecraftforge.fluids.Fluid)2 FluidMolecule (minechem.fluid.FluidMolecule)1 RadiationFluidTileEntity (minechem.radiation.RadiationFluidTileEntity)1 EntityItem (net.minecraft.entity.item.EntityItem)1 IInventory (net.minecraft.inventory.IInventory)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 IIcon (net.minecraft.util.IIcon)1 BlockFluidBase (net.minecraftforge.fluids.BlockFluidBase)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)1