public static void useDropper(PlayerEntity player, Object tank, int button) {
            ItemStack stack = player.inventory.getItemStack();
            if (stack.isEmpty() || !(stack.getItem() instanceof ItemGaugeDropper)) {
                return;
            }
            if (!stack.isEmpty()) {
                FluidStack storedFluid = StorageUtils.getStoredFluidFromNBT(stack);
                if (tank instanceof IChemicalTank) {
                    IChemicalTank<?, ?> chemicalTank = (IChemicalTank<?, ?>) tank;
                    if (chemicalTank.getEmptyStack() == GasStack.EMPTY) {
                        //It is actually a gas tank
                        IChemicalTank<Gas, GasStack> gasTank = (IChemicalTank<Gas, GasStack>) chemicalTank;
                        Optional<IGasHandler> capability = MekanismUtils.toOptional(stack.getCapability(Capabilities.GAS_HANDLER_CAPABILITY));
                        if (capability.isPresent()) {
                            IGasHandler gasHandlerItem = capability.get();
                            if (gasHandlerItem.getGasTankCount() > 0) {
                                //Validate something didn't go terribly wrong and we actually do have the tank we expect to have
                                GasStack storedGas = gasHandlerItem.getGasInTank(0);
                                if (!storedGas.isTypeEqual(gasTank.getStack())) {
                                    return;
                                }
                                if (button == 0) { //Insert gas into dropper
                                    if (!storedFluid.isEmpty() || gasTank.isEmpty()) {
                                        return;
                                    }
                                    GasStack gasInTank = gasTank.getStack();
                                    GasStack simulatedRemainder = gasHandlerItem.insertGas(gasInTank, Action.SIMULATE);
                                    int remainder = simulatedRemainder.getAmount();
                                    int amount = gasInTank.getAmount();
                                    if (remainder < amount) {
                                        //We are able to fit at least some of the gas from our tank into the item
                                        GasStack extractedGas = gasTank.extract(amount - remainder, Action.EXECUTE, AutomationType.INTERNAL);
                                        if (!extractedGas.isEmpty()) {
                                            //If we were able to actually extract it from our tank, then insert it into the item
                                            if (!gasHandlerItem.insertGas(extractedGas, Action.EXECUTE).isEmpty()) {
                                                //TODO: Print warning/error
                                            }
                                            ((ServerPlayerEntity) player).sendContainerToPlayer(player.openContainer);
                                        }
                                    }
                                } else if (button == 1) { //Extract gas from dropper
                                    if (!storedFluid.isEmpty() || gasTank.getNeeded() == 0) {
                                        //If the dropper has fluid or the tank interacting with is already full of gas
                                        return;
                                    }
                                    GasStack simulatedRemainder = gasTank.insert(storedGas, Action.SIMULATE, AutomationType.INTERNAL);
                                    int gasInItemAmount = storedGas.getAmount();
                                    int remainder = simulatedRemainder.getAmount();
                                    if (remainder < gasInItemAmount) {
                                        GasStack extractedGas = gasHandlerItem.extractGas(0, gasInItemAmount - remainder, Action.EXECUTE);
                                        if (!extractedGas.isEmpty()) {
                                            //If we were able to actually extract it from the item, then insert it into our gas tank
                                            if (!gasTank.insert(extractedGas, Action.EXECUTE, AutomationType.INTERNAL).isEmpty()) {
                                                //TODO: Print warning/error
                                            }
                                            ((ServerPlayerEntity) player).sendContainerToPlayer(player.openContainer);
                                        }
                                    }
                                } else if (button == 2) { //Dump the tank
                                    gasTank.setEmpty();
                                }
                            }
                        } else if (chemicalTank.getEmptyStack() == InfusionStack.EMPTY) {
                            //It is actually an infusion tank
                            IChemicalTank<InfuseType, InfusionStack> infusionTank = (IChemicalTank<InfuseType, InfusionStack>) chemicalTank;
                            //TODO: Implement at some point
                        }
                    }
                    //TODO: Handle other chemical tanks like maybe infusion tanks
                } else if (tank instanceof IExtendedFluidTank) {
                    IExtendedFluidTank fluidTank = (IExtendedFluidTank) tank;
                    if (!storedFluid.isEmpty() && !fluidTank.isEmpty() && !storedFluid.isFluidEqual(fluidTank.getFluid())) {
                        return;
                    }
                    GasStack storedGas = GasStack.EMPTY;
                    Optional<IGasHandler> gasCapability = MekanismUtils.toOptional(stack.getCapability(Capabilities.GAS_HANDLER_CAPABILITY));
                    if (gasCapability.isPresent()) {
                        IGasHandler gasHandlerItem = gasCapability.get();
                        if (gasHandlerItem.getGasTankCount() > 0) {
                            storedGas = gasHandlerItem.getGasInTank(0);
                        }
                    }
                    if (button == 2) { //Dump the tank
                        fluidTank.setEmpty();
                    }
                    Optional<IFluidHandlerItem> capability = MekanismUtils.toOptional(FluidUtil.getFluidHandler(stack));
                    if (!capability.isPresent()) {
                        //If something went wrong and we don't have a fluid handler on our tank, then fail
                        return;
                    }
                    IFluidHandlerItem fluidHandlerItem = capability.get();
                    if (!(fluidHandlerItem instanceof IMekanismFluidHandler)) {
                        //TODO: Decide if we want to support someone replacing our fluid handler with another?
                        //If it isn't one of our fluid handlers fail
                        return;
                    }
                    IExtendedFluidTank itemFluidTank = ((IMekanismFluidHandler) fluidHandlerItem).getFluidTank(0, null);
                    if (itemFluidTank == null) {
                        //If something went wrong and we don't have a fluid tank fail
                        return;
                    }
                    if (button == 0) { //Insert fluid into dropper
                        if (!storedGas.isEmpty() || fluidTank.isEmpty()) {
                            return;
                        }
                        FluidStack fluidInTank = fluidTank.getFluid();
                        FluidStack simulatedRemainder = itemFluidTank.insert(fluidInTank, Action.SIMULATE, AutomationType.MANUAL);
                        int remainder = simulatedRemainder.getAmount();
                        int amount = fluidInTank.getAmount();
                        if (remainder < amount) {
                            //We are able to fit at least some of the fluid from our tank into the item
                            FluidStack extractedFluid = fluidTank.extract(amount - remainder, Action.EXECUTE, AutomationType.MANUAL);
                            if (!extractedFluid.isEmpty()) {
                                //If we were able to actually extract it from our tank, then insert it into the item
                                if (!itemFluidTank.insert(extractedFluid, Action.EXECUTE, AutomationType.MANUAL).isEmpty()) {
                                    //TODO: Print warning/error
                                }
                                ((ServerPlayerEntity) player).sendContainerToPlayer(player.openContainer);
                            }
                        }
                    } else if (button == 1) { //Extract fluid from dropper
                        if (!storedGas.isEmpty() || fluidTank.getNeeded() == 0) {
                            return;
                        }
                        FluidStack simulatedRemainder = fluidTank.insert(storedFluid, Action.SIMULATE, AutomationType.MANUAL);
                        int fluidInItemAmount = storedFluid.getAmount();
                        int remainder = simulatedRemainder.getAmount();
                        if (remainder < fluidInItemAmount) {
                            FluidStack drainedGas = itemFluidTank.extract(fluidInItemAmount - remainder, Action.EXECUTE, AutomationType.MANUAL);
                            if (!drainedGas.isEmpty()) {
                                //If we were able to actually extract it from the item, then insert it into our gas tank
                                if (!fluidTank.insert(drainedGas, Action.EXECUTE, AutomationType.INTERNAL).isEmpty()) {
                                    //TODO: Print warning/error
                                }
                                ((ServerPlayerEntity) player).sendContainerToPlayer(player.openContainer);
                            }
                        }
                    }
                }
            }
        }
public static void useDropper(PlayerEntity player, Object tank, int button) {
            ItemStack stack = player.inventory.getItemStack();
            if (stack.isEmpty() || !(stack.getItem() instanceof ItemGaugeDropper)) {
                return;
            }
            if (!stack.isEmpty()) {
                FluidStack storedFluid = StorageUtils.getStoredFluidFromNBT(stack);
                if (tank instanceof IChemicalTank) {
                    IChemicalTank<?, ?> chemicalTank = (IChemicalTank<?, ?>) tank;
                    if (chemicalTank.getEmptyStack() == GasStack.EMPTY) {
                       
                        IChemicalTank<Gas, GasStack> gasTank = (IChemicalTank<Gas, GasStack>) chemicalTank;
                        Optional<IGasHandler> capability = MekanismUtils.toOptional(stack.getCapability(Capabilities.GAS_HANDLER_CAPABILITY));
                        if (capability.isPresent()) {
                            IGasHandler gasHandlerItem = capability.get();
                            if (gasHandlerItem.getGasTankCount() > 0) {
                               
                                GasStack storedGas = gasHandlerItem.getGasInTank(0);
                                if (!storedGas.isTypeEqual(gasTank.getStack())) {
                                    return;
                                }
                                if (button == 0) {
                                    if (!storedFluid.isEmpty() || gasTank.isEmpty()) {
                                        return;
                                    }
                                    GasStack gasInTank = gasTank.getStack();
                                    GasStack simulatedRemainder = gasHandlerItem.insertGas(gasInTank, Action.SIMULATE);
                                    int remainder = simulatedRemainder.getAmount();
                                    int amount = gasInTank.getAmount();
                                    if (remainder < amount) {
                                       
                                        GasStack extractedGas = gasTank.extract(amount - remainder, Action.EXECUTE, AutomationType.INTERNAL);
                                        if (!extractedGas.isEmpty()) {
                                           
                                            if (!gasHandlerItem.insertGas(extractedGas, Action.EXECUTE).isEmpty()) {
                                               
                                            }
                                            ((ServerPlayerEntity) player).sendContainerToPlayer(player.openContainer);
                                        }
                                    }
                                } else if (button == 1) {
                                    if (!storedFluid.isEmpty() || gasTank.getNeeded() == 0) {
                                       
                                        return;
                                    }
                                    GasStack simulatedRemainder = gasTank.insert(storedGas, Action.SIMULATE, AutomationType.INTERNAL);
                                    int gasInItemAmount = storedGas.getAmount();
                                    int remainder = simulatedRemainder.getAmount();
                                    if (remainder < gasInItemAmount) {
                                        GasStack extractedGas = gasHandlerItem.extractGas(0, gasInItemAmount - remainder, Action.EXECUTE);
                                        if (!extractedGas.isEmpty()) {
                                           
                                            if (!gasTank.insert(extractedGas, Action.EXECUTE, AutomationType.INTERNAL).isEmpty()) {
                                               
                                            }
                                            ((ServerPlayerEntity) player).sendContainerToPlayer(player.openContainer);
                                        }
                                    }
                                } else if (button == 2) {
                                    gasTank.setEmpty();
                                }
                            }
                        } else if (chemicalTank.getEmptyStack() == InfusionStack.EMPTY) {
                           
                            IChemicalTank<InfuseType, InfusionStack> infusionTank = (IChemicalTank<InfuseType, InfusionStack>) chemicalTank;
                           
                        }
                    }
                   
                } else if (tank instanceof IExtendedFluidTank) {
                    IExtendedFluidTank fluidTank = (IExtendedFluidTank) tank;
                    if (!storedFluid.isEmpty() && !fluidTank.isEmpty() && !storedFluid.isFluidEqual(fluidTank.getFluid())) {
                        return;
                    }
                    GasStack storedGas = GasStack.EMPTY;
                    Optional<IGasHandler> gasCapability = MekanismUtils.toOptional(stack.getCapability(Capabilities.GAS_HANDLER_CAPABILITY));
                    if (gasCapability.isPresent()) {
                        IGasHandler gasHandlerItem = gasCapability.get();
                        if (gasHandlerItem.getGasTankCount() > 0) {
                            storedGas = gasHandlerItem.getGasInTank(0);
                        }
                    }
                    if (button == 2) {
                        fluidTank.setEmpty();
                    }
                    Optional<IFluidHandlerItem> capability = MekanismUtils.toOptional(FluidUtil.getFluidHandler(stack));
                    if (!capability.isPresent()) {
                       
                        return;
                    }
                    IFluidHandlerItem fluidHandlerItem = capability.get();
                    if (!(fluidHandlerItem instanceof IMekanismFluidHandler)) {
                       
                       
                        return;
                    }
                    IExtendedFluidTank itemFluidTank = ((IMekanismFluidHandler) fluidHandlerItem).getFluidTank(0, null);
                    if (itemFluidTank == null) {
                       
                        return;
                    }
                    if (button == 0) {
                        if (!storedGas.isEmpty() || fluidTank.isEmpty()) {
                            return;
                        }
                        FluidStack fluidInTank = fluidTank.getFluid();
                        FluidStack simulatedRemainder = itemFluidTank.insert(fluidInTank, Action.SIMULATE, AutomationType.MANUAL);
                        int remainder = simulatedRemainder.getAmount();
                        int amount = fluidInTank.getAmount();
                        if (remainder < amount) {
                           
                            FluidStack extractedFluid = fluidTank.extract(amount - remainder, Action.EXECUTE, AutomationType.MANUAL);
                            if (!extractedFluid.isEmpty()) {
                               
                                if (!itemFluidTank.insert(extractedFluid, Action.EXECUTE, AutomationType.MANUAL).isEmpty()) {
                                   
                                }
                                ((ServerPlayerEntity) player).sendContainerToPlayer(player.openContainer);
                            }
                        }
                    } else if (button == 1) {
                        if (!storedGas.isEmpty() || fluidTank.getNeeded() == 0) {
                            return;
                        }
                        FluidStack simulatedRemainder = fluidTank.insert(storedFluid, Action.SIMULATE, AutomationType.MANUAL);
                        int fluidInItemAmount = storedFluid.getAmount();
                        int remainder = simulatedRemainder.getAmount();
                        if (remainder < fluidInItemAmount) {
                            FluidStack drainedGas = itemFluidTank.extract(fluidInItemAmount - remainder, Action.EXECUTE, AutomationType.MANUAL);
                            if (!drainedGas.isEmpty()) {
                               
                                if (!fluidTank.insert(drainedGas, Action.EXECUTE, AutomationType.INTERNAL).isEmpty()) {
                                   
                                }
                                ((ServerPlayerEntity) player).sendContainerToPlayer(player.openContainer);
                            }
                        }
                    }
                }
            }
        }
public static void usedropper(playerentity player, object tank, int button) { itemstack stack = player.inventory.getitemstack(); if (stack.isempty() || !(stack.getitem() instanceof itemgaugedropper)) { return; } if (!stack.isempty()) { fluidstack storedfluid = storageutils.getstoredfluidfromnbt(stack); if (tank instanceof ichemicaltank) { ichemicaltank<?, ?> chemicaltank = (ichemicaltank<?, ?>) tank; if (chemicaltank.getemptystack() == gasstack.empty) { ichemicaltank<gas, gasstack> gastank = (ichemicaltank<gas, gasstack>) chemicaltank; optional<igashandler> capability = mekanismutils.tooptional(stack.getcapability(capabilities.gas_handler_capability)); if (capability.ispresent()) { igashandler gashandleritem = capability.get(); if (gashandleritem.getgastankcount() > 0) { gasstack storedgas = gashandleritem.getgasintank(0); if (!storedgas.istypeequal(gastank.getstack())) { return; } if (button == 0) { if (!storedfluid.isempty() || gastank.isempty()) { return; } gasstack gasintank = gastank.getstack(); gasstack simulatedremainder = gashandleritem.insertgas(gasintank, action.simulate); int remainder = simulatedremainder.getamount(); int amount = gasintank.getamount(); if (remainder < amount) { gasstack extractedgas = gastank.extract(amount - remainder, action.execute, automationtype.internal); if (!extractedgas.isempty()) { if (!gashandleritem.insertgas(extractedgas, action.execute).isempty()) { } ((serverplayerentity) player).sendcontainertoplayer(player.opencontainer); } } } else if (button == 1) { if (!storedfluid.isempty() || gastank.getneeded() == 0) { return; } gasstack simulatedremainder = gastank.insert(storedgas, action.simulate, automationtype.internal); int gasinitemamount = storedgas.getamount(); int remainder = simulatedremainder.getamount(); if (remainder < gasinitemamount) { gasstack extractedgas = gashandleritem.extractgas(0, gasinitemamount - remainder, action.execute); if (!extractedgas.isempty()) { if (!gastank.insert(extractedgas, action.execute, automationtype.internal).isempty()) { } ((serverplayerentity) player).sendcontainertoplayer(player.opencontainer); } } } else if (button == 2) { gastank.setempty(); } } } else if (chemicaltank.getemptystack() == infusionstack.empty) { ichemicaltank<infusetype, infusionstack> infusiontank = (ichemicaltank<infusetype, infusionstack>) chemicaltank; } } } else if (tank instanceof iextendedfluidtank) { iextendedfluidtank fluidtank = (iextendedfluidtank) tank; if (!storedfluid.isempty() && !fluidtank.isempty() && !storedfluid.isfluidequal(fluidtank.getfluid())) { return; } gasstack storedgas = gasstack.empty; optional<igashandler> gascapability = mekanismutils.tooptional(stack.getcapability(capabilities.gas_handler_capability)); if (gascapability.ispresent()) { igashandler gashandleritem = gascapability.get(); if (gashandleritem.getgastankcount() > 0) { storedgas = gashandleritem.getgasintank(0); } } if (button == 2) { fluidtank.setempty(); } optional<ifluidhandleritem> capability = mekanismutils.tooptional(fluidutil.getfluidhandler(stack)); if (!capability.ispresent()) { return; } ifluidhandleritem fluidhandleritem = capability.get(); if (!(fluidhandleritem instanceof imekanismfluidhandler)) { return; } iextendedfluidtank itemfluidtank = ((imekanismfluidhandler) fluidhandleritem).getfluidtank(0, null); if (itemfluidtank == null) { return; } if (button == 0) { if (!storedgas.isempty() || fluidtank.isempty()) { return; } fluidstack fluidintank = fluidtank.getfluid(); fluidstack simulatedremainder = itemfluidtank.insert(fluidintank, action.simulate, automationtype.manual); int remainder = simulatedremainder.getamount(); int amount = fluidintank.getamount(); if (remainder < amount) { fluidstack extractedfluid = fluidtank.extract(amount - remainder, action.execute, automationtype.manual); if (!extractedfluid.isempty()) { if (!itemfluidtank.insert(extractedfluid, action.execute, automationtype.manual).isempty()) { } ((serverplayerentity) player).sendcontainertoplayer(player.opencontainer); } } } else if (button == 1) { if (!storedgas.isempty() || fluidtank.getneeded() == 0) { return; } fluidstack simulatedremainder = fluidtank.insert(storedfluid, action.simulate, automationtype.manual); int fluidinitemamount = storedfluid.getamount(); int remainder = simulatedremainder.getamount(); if (remainder < fluidinitemamount) { fluidstack drainedgas = itemfluidtank.extract(fluidinitemamount - remainder, action.execute, automationtype.manual); if (!drainedgas.isempty()) { if (!fluidtank.insert(drainedgas, action.execute, automationtype.internal).isempty()) { } ((serverplayerentity) player).sendcontainertoplayer(player.opencontainer); } } } } } }