Java Code Examples for net.minecraftforge.fluids.FluidStack#isFluidEqual()

The following examples show how to use net.minecraftforge.fluids.FluidStack#isFluidEqual() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TileEntityPoweredInventoryFluid.java    From BigReactors with MIT License 6 votes vote down vote up
/**
 * Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.
 * 
 * @param from
 *            Orientation the Fluid is drained to.
 * @param resource
 *            FluidStack representing the Fluid and maximum amount of fluid to be drained.
 * @param doDrain
 *            If false, drain will only be simulated.
 * @return FluidStack representing the Fluid and amount that was (or would have been, if
 *         simulated) drained.
 */
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
	int tankToDrain = 0;
	if(from != ForgeDirection.UNKNOWN) {
		tankToDrain = getExposedTankFromSide(from.ordinal());
	}
	
	if(tankToDrain == FLUIDTANK_NONE) {
		return null;
	}
	else {
		// Can't drain that fluid from that side.
		if(!resource.isFluidEqual( tanks[tankToDrain].getFluid() )) {
			return null;
		}
		
		return drain(tankToDrain, resource.amount, doDrain);
	}
}
 
Example 2
Source File: BarrelRecipes.java    From Sakura_mod with MIT License 5 votes vote down vote up
public FluidStack getFluidStack(FluidStack fluid) {
	for (FluidStack entry : RecipesList.keySet()) {
		if(entry.isFluidEqual(fluid))
			return entry;
	}
	return null;
}
 
Example 3
Source File: ExtendedFluidTank.java    From CodeChickenCore with MIT License 5 votes vote down vote up
public FluidStack drain(FluidStack resource, boolean doDrain)
{
    if (resource == null || !resource.isFluidEqual(fluid))
        return null;
    
    return drain(resource.amount, doDrain);
}
 
Example 4
Source File: ItemHelper.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
public static boolean fluidStackEqual(FluidStack stack1, FluidStack stack2)
{
    if (stack1 == null && stack2 == null)
        return true;
    if (stack1 == null ^ stack2 == null)
        return false;

    return stack1.isFluidEqual(stack2) && stack2.amount == stack1.amount;
}
 
Example 5
Source File: ItemHelper.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
public static boolean fluidStackEqual(FluidStack stack, FluidStack input, boolean checkCount)
{
    if (stack == null && input == null)
        return true;
    if (stack == null ^ input == null)
        return false;

    return stack.isFluidEqual(input) && (!checkCount || input.amount <= stack.amount);
}
 
Example 6
Source File: GT_TileEntity_THTR.java    From bartworks with MIT License 5 votes vote down vote up
@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
    super.onPostTick(aBaseMetaTileEntity, aTick);
    if (aBaseMetaTileEntity.isServerSide()){
        if (this.HeliumSupply < GT_TileEntity_THTR.HELIUM_NEEDED){
            for (FluidStack fluidStack : this.getStoredFluids()){
                if (fluidStack.isFluidEqual(Materials.Helium.getGas(1000))) {
                    while (this.HeliumSupply < GT_TileEntity_THTR.HELIUM_NEEDED && fluidStack.amount > 0) {
                        this.HeliumSupply++;
                        fluidStack.amount--;
                    }
                }
            }
        }
        for (ItemStack itemStack : this.getStoredInputs()) {
            if (GT_Utility.areStacksEqual(itemStack, new ItemStack(GT_TileEntity_THTR.THTRMaterials.aTHTR_Materials, 1, 3))) {
                if (this.BISOPeletSupply + this.TRISOPeletSupply < 675000) {
                    while (this.BISOPeletSupply + this.TRISOPeletSupply < 675000 && itemStack.stackSize > 0) {
                        itemStack.stackSize--;
                        this.TRISOPeletSupply++;
                    }
                    this.updateSlots();
                }
            } else if (GT_Utility.areStacksEqual(itemStack, new ItemStack(GT_TileEntity_THTR.THTRMaterials.aTHTR_Materials, 1, 1))) {
                if (this.BISOPeletSupply + this.TRISOPeletSupply < 675000) {
                    while (this.BISOPeletSupply + this.TRISOPeletSupply < 675000 && itemStack.stackSize > 0) {
                        itemStack.stackSize--;
                        this.BISOPeletSupply++;

                    }
                    this.updateSlots();
                }
            }
        }
    }
}
 
Example 7
Source File: GT_TileEntity_VoidMiner_Base.java    From bartworks with MIT License 5 votes vote down vote up
private boolean consumeNobleGas(FluidStack gasToConsume) {
    for (FluidStack s : this.getStoredFluids()) {
        if (s.isFluidEqual(gasToConsume) && s.amount >= 1) {
            s.amount -= 1;
            this.updateSlots();
            return true;
        }
    }
    return false;
}
 
Example 8
Source File: TankSynchroniser.java    From EnderStorage with MIT License 5 votes vote down vote up
public void update(boolean client)
{
    FluidStack b_liquid;
    FluidStack a_liquid;
    if(client)
    {
        b_liquid = c_liquid.copy();
        
        if(s_liquid.isFluidEqual(c_liquid))
            c_liquid.amount = MathHelper.approachExpI(c_liquid.amount, s_liquid.amount, 0.1);
        else if(c_liquid.amount > 100)
            c_liquid.amount = MathHelper.retreatExpI(c_liquid.amount, 0, f_liquid.amount, 0.1, 1000);
        else
            c_liquid = FluidUtils.copy(s_liquid, 0);
        
        a_liquid = c_liquid;
    }
    else
    {
        s_liquid = storage.getFluid();
        b_liquid = s_liquid.copy();
        if(!s_liquid.isFluidEqual(c_liquid))
        {
            sendSyncPacket();
            c_liquid = s_liquid;
        }
        else if(Math.abs(c_liquid.amount-s_liquid.amount) > 250 || (s_liquid.amount == 0 && c_liquid.amount > 0))
        {
            sendSyncPacket();
            c_liquid = s_liquid;
        }

        a_liquid = s_liquid;                
    }
    if((b_liquid.amount == 0) != (a_liquid.amount == 0) || !b_liquid.isFluidEqual(a_liquid))
        onLiquidChanged();
}
 
Example 9
Source File: SimpleFluidFilter.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean checkInputFluid(FluidStack[] fluidFilterSlots, FluidStack fluidStack) {
    for (FluidStack filterStack : fluidFilterSlots) {
        if (filterStack != null && filterStack.isFluidEqual(fluidStack)) {
            return true;
        }
    }
    return false;
}
 
Example 10
Source File: WatchedFluidTank.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static boolean hasFluidChanged(FluidStack newFluid, FluidStack oldFluid) {
    if (newFluid == null && oldFluid == null) {
        return false; //both fluid stacks are null - no changes
    } else if (newFluid == null || oldFluid == null) {
        return true; //one of fluid stacks is null, and other is not - content changed
    } else {
        //both fluid stacks are not null - compare by fluid type and amount
        return !newFluid.isFluidEqual(oldFluid) || newFluid.amount != oldFluid.amount;
    }
}
 
Example 11
Source File: GenericTank.java    From OpenModsLib with MIT License 5 votes vote down vote up
private static IFluidFilter filter(final FluidStack... acceptableFluids) {
	if (acceptableFluids.length == 0) return NO_RESTRICTIONS;

	return stack -> {
		for (FluidStack acceptableFluid : acceptableFluids)
			if (acceptableFluid.isFluidEqual(stack)) return true;

		return false;
	};
}
 
Example 12
Source File: Recipe.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean hasInputFluid(FluidStack fluid) {
    for (FluidStack fluidStack : fluidInputs) {
        if (fluidStack.isFluidEqual(fluid)) {
            return true;
        }
    }
    return false;
}
 
Example 13
Source File: FluidIngredient.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean test(FluidStack fluidStack) {
    for (FluidStack matchingStack : getMatchingStacks()) {
        if (matchingStack.isFluidEqual(fluidStack))
            return true;
    }
    return false;
}
 
Example 14
Source File: DistillationRecipes.java    From Sakura_mod with MIT License 5 votes vote down vote up
public FluidStack getFluidStack(FluidStack fluid) {
	for (FluidStack entry : RecipesList.keySet()) {
		if(entry.isFluidEqual(fluid))
			return entry;
	}
	return null;
}
 
Example 15
Source File: PotRecipes.java    From Sakura_mod with MIT License 5 votes vote down vote up
public FluidStack getResultFluid(FluidStack fluid) {
	for (FluidStack entry : RecipesList.keySet()) {
		if(entry.isFluidEqual(fluid))
			return entry;
	}
	return null;
}
 
Example 16
Source File: TileEntitySaltFurnace.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@Override
public FluidStack drain(FluidStack resource, boolean doDrain) {
    if ((resource == null) || (!resource.isFluidEqual(nigariTank.getFluid()))) {
        return null;
    }

    if (!canDrain(resource.getFluid())) return null;

    return nigariTank.drain(resource.amount, doDrain);
}
 
Example 17
Source File: MetaTileEntityTank.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static boolean isTankFluidEqual(MetaTileEntityTank tank1, MetaTileEntityTank tank2) {
    FluidStack fluidStack1 = tank1.getActualTankFluid();
    FluidStack fluidStack2 = tank2.getActualTankFluid();
    return fluidStack1 == null || fluidStack2 == null || fluidStack1.isFluidEqual(fluidStack2);
}
 
Example 18
Source File: SyncedField.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean equals(FluidStack oldValue, FluidStack newValue){
    return oldValue.isFluidEqual(newValue) && oldValue.amount == newValue.amount;
}
 
Example 19
Source File: GT_TileEntity_BioVat.java    From bartworks with MIT License 4 votes vote down vote up
@Override
public boolean checkRecipe(ItemStack itemStack) {
    GT_Recipe.GT_Recipe_Map gtRecipeMap = this.getRecipeMap();

    if (gtRecipeMap == null)
        return false;

    ItemStack[] tInputs = getItemInputs().toArray(new ItemStack[0]);
    FluidStack[] tFluids = getFluidInputs().toArray(new FluidStack[0]);

    if (tFluids.length > 0) {

        GT_Recipe gtRecipe = gtRecipeMap.findRecipe(this.getBaseMetaTileEntity(), this.mLastRecipe, false, this.getMaxInputVoltage(), tFluids, itemStack, tInputs);

        if (gtRecipe == null)
            return false;

        if (!BW_Util.areStacksEqualOrNull((ItemStack) gtRecipe.mSpecialItems, itemStack))
            return false;

        int[] conditions = GT_TileEntity_BioVat.specialValueUnpack(gtRecipe.mSpecialValue);

        this.mNeededSievert = conditions[3];

        if (conditions[2] == 0 ?
                (this.mSievert < this.mNeededSievert || this.mGlassTier < conditions[0])
                : (this.mSievert != conditions[3] || this.mGlassTier < conditions[0]))
            return false;

        int times = 1;

        this.mEfficiency = (10000 - (this.getIdealStatus() - this.getRepairStatus()) * 1000);
        this.mEfficiencyIncrease = 10000;

        Set<FluidStack> storedFluidOutputs = this.getStoredFluidOutputs();

        if (gtRecipe.isRecipeInputEqual(true, tFluids, tInputs)) {
            if (storedFluidOutputs.size() > 0) {
                this.mOutputFluids = new FluidStack[gtRecipe.mFluidOutputs.length];
                for (FluidStack storedOutputFluid : storedFluidOutputs) {
                    if (storedOutputFluid.isFluidEqual(gtRecipe.getFluidOutput(0)))
                        for (FluidStack inputFluidStack : gtRecipe.mFluidInputs) {
                            int j = this.calcMod(storedOutputFluid.amount);
                            for (int i = 0; i < j; i++)
                                if (this.depleteInput(inputFluidStack))
                                    times++;
                        }
                }
                for (FluidStack storedfluidStack : storedFluidOutputs) {
                    for (int i = 0; i < gtRecipe.mFluidOutputs.length; i++) {
                        if (storedfluidStack.isFluidEqual(gtRecipe.getFluidOutput(i)))
                            this.mOutputFluids[i] = (new FluidStack(gtRecipe.getFluidOutput(i), times * gtRecipe.getFluidOutput(0).amount));
                    }

                }
            } else {
                this.mOutputFluids = gtRecipe.mFluidOutputs;
            }
        } else
            return false;

        BW_Util.calculateOverclockedNessMulti(gtRecipe.mEUt, gtRecipe.mDuration, 1, this.getMaxInputVoltage(), this);

        if (this.mEUt > 0)
            this.mEUt = -this.mEUt;
        this.mProgresstime = 0;

        if (gtRecipe.mCanBeBuffered)
            this.mLastRecipe = gtRecipe;

        this.updateSlots();
        return true;
    }
    return false;
}
 
Example 20
Source File: TileFluidKineticGenerator.java    From Production-Line with MIT License 4 votes vote down vote up
@Override
public void update() {
    if (!this.world.isRemote) {
        boolean needUpdate = false;

        if (this.fluidTank.getFluidAmount() <= this.fluidTank.getCapacity()) {
            for (TileSlot tileSlot : this.tileSlots) {
                if (tileSlot instanceof TileSlotFluidInput) {
                    ((TileSlotFluidInput) tileSlot).drainToTank();
                    needUpdate = true;
                }
            }
        }


        if (this.fluidTank.getFluid() != null && this.maxrequestkineticenergyTick(this.facing) > 0) {
            int amount = 0;
            for (RecipePart recipePart : FluidKineticGeneratorRecipes.instance.getProcessRecipesList()) {
                FluidStack fluidStack = ((FluidKineticGeneratorRecipes.RecipePartFluidKineticGenerator) recipePart).fluidStack;
                if (fluidStack.isFluidEqual(this.fluidTank.getFluid())) {
                    amount = fluidStack.amount;

                }
            }

            if (this.fluidTank.getFluidAmount() >= amount) {
                this.setActive(true);

                if (this.timer == 20) {
                    this.timer = 0;
                    this.fluidTank.getFluid().amount -= amount;
                }
                this.timer++;

            } else {
                this.setActive(false);
                this.timer = 0;
            }

            if (this.fluidTank.getFluidAmount() < 0) {
                this.fluidTank.getFluid().amount = 0;
            }

        }
        else {
            this.setActive(false);
        }

        if (needUpdate) {
            this.markDirty();
        }
    }
}