use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCEu.
the class GTUtility method fluidHandlerToList.
/**
* @return a list of fluidstack linked with given fluid handler
* modifications in list will reflect on fluid handler and wise-versa
*/
public static List<FluidStack> fluidHandlerToList(IMultipleTankHandler fluidInputs) {
List<IFluidTank> backedList = fluidInputs.getFluidTanks();
return new AbstractList<FluidStack>() {
@Override
public FluidStack set(int index, FluidStack element) {
IFluidTank fluidTank = backedList.get(index);
FluidStack oldStack = fluidTank.getFluid();
if (!(fluidTank instanceof FluidTank))
return oldStack;
((FluidTank) backedList.get(index)).setFluid(element);
return oldStack;
}
@Override
public FluidStack get(int index) {
return backedList.get(index).getFluid();
}
@Override
public int size() {
return backedList.size();
}
};
}
use of net.minecraftforge.fluids.IFluidTank in project GTplusplus by GTNewHorizons.
the class GregtechPump method drainIFluidTank.
/*
* Vanilla IFluidTank
*/
public boolean drainIFluidTank(TileEntity tTileEntity, ItemStack aStack, World aWorld, EntityPlayer aPlayer, int aX, int aY, int aZ) {
if (tTileEntity == null) {
Logger.INFO("Invalid Tile, somehow.");
return false;
}
if ((tTileEntity instanceof IFluidTank || tTileEntity instanceof IFluidHandler)) {
if (this.getFluid(aStack) == null || (this.getFluid(aStack) != null && this.getFluid(aStack).amount < this.getCapacity(aStack))) {
Logger.INFO("Trying to find Stored Fluid - Behaviour Class.");
FluidStack aStored = getStoredFluidOfVanillaTank(tTileEntity);
if (aStored != null) {
int mAmountInserted = fill(aStack, aStored);
FluidStack newStackRemainingInTank;
if (mAmountInserted > 0) {
if (mAmountInserted == aStored.amount) {
newStackRemainingInTank = null;
} else {
newStackRemainingInTank = FluidUtils.getFluidStack(aStored, (aStored.amount - mAmountInserted));
}
boolean b = setStoredFluidOfVanillaTank(tTileEntity, newStackRemainingInTank);
Logger.INFO("Cleared Tank? " + b + " | mAmountInserted: " + mAmountInserted);
Logger.INFO("Returning " + b + " - drainTankVanilla.");
if (b) {
PlayerUtils.messagePlayer(aPlayer, "Drained " + mAmountInserted + "L of " + aStored.getLocalizedName() + ".");
}
return b;
}
} else {
Logger.INFO("Found no valid Fluidstack - drainTankVanilla.");
}
} else {
Logger.INFO("Pump is full.");
}
}
Logger.INFO("Could not drain vanilla tank.");
return false;
}
use of net.minecraftforge.fluids.IFluidTank in project GTplusplus by GTNewHorizons.
the class GregtechPump method tryDrainTile.
/**
* Tile Handling
*/
/*
* Custom Fluid Handling for Tiles and GT Tiles.
*/
public boolean tryDrainTile(ItemStack aStack, World aWorld, EntityPlayer aPlayer, int aX, int aY, int aZ) {
try {
if (aWorld.isRemote || aStack == null) {
return false;
} else {
int aTier = (aStack.getItemDamage() - 1000);
int removal;
if (aTier == 0) {
removal = 0;
} else if (aTier == 1) {
removal = 32;
} else if (aTier == 2) {
removal = 128;
} else if (aTier == 3) {
removal = 512;
} else {
removal = 8;
}
if (!canUse(aStack, removal) && aTier > 0) {
PlayerUtils.messagePlayer(aPlayer, "Not enough power.");
Logger.INFO("No Power");
return false;
}
final Block aBlock = aWorld.getBlock(aX, aY, aZ);
if (aBlock == null) {
return false;
}
TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
if (tTileEntity == null) {
return false;
} else {
double aCharge = this.getCharge(aStack);
boolean didDrain = false;
if (aTier > 0 && aCharge > 0) {
if (discharge(aStack, removal, aTier, true, true, false) > 0) {
didDrain = true;
}
} else if (aTier == 0) {
didDrain = true;
} else {
didDrain = false;
}
if (didDrain) {
if ((tTileEntity instanceof IGregTechTileEntity)) {
return this.drainTankGT(tTileEntity, aStack, aWorld, aPlayer, aX, aY, aZ);
} else // Try support Standard Fluid Tanks too (May disable if dupes appear again)
if ((tTileEntity instanceof IFluidTank || tTileEntity instanceof IFluidHandler)) {
// return this.drainIFluidTank(tTileEntity, aStack, aWorld, aPlayer, aX, aY, aZ);
return false;
}
}
}
}
} catch (Throwable t) {
}
return false;
}
use of net.minecraftforge.fluids.IFluidTank in project GTplusplus by GTNewHorizons.
the class GregtechPump method getStoredFluidOfVanillaTank.
public FluidStack getStoredFluidOfVanillaTank(IFluidHandler aTileEntity) {
if (aTileEntity instanceof IFluidTank) {
return getStoredFluidOfVanillaTank((IFluidTank) aTileEntity);
}
FluidStack f;
AutoMap<FluidTankInfo[]> m = new AutoMap<FluidTankInfo[]>();
for (int i = 0; i < 6; i++) {
m.put(aTileEntity.getTankInfo(ForgeDirection.getOrientation(i)));
}
if (m.get(0) != null && m.get(0)[0] != null && m.get(0)[0].fluid != null) {
return m.get(0)[0].fluid;
} else {
return null;
}
}
use of net.minecraftforge.fluids.IFluidTank in project Binnie by ForestryMC.
the class MachineUtil method liquidInTank.
public boolean liquidInTank(final int tankIndex, final int amount) {
IFluidTank tank = this.getTank(tankIndex);
FluidStack drain = tank.drain(amount, false);
return drain != null && drain.amount == amount;
}
Aggregations