use of net.minecraftforge.fluids.IFluidTank in project gregtech6 by GregTech6.
the class MultiTileEntityBathingPot method onTick2.
@Override
public void onTick2(long aTimer, boolean aIsServerSide) {
if (aIsServerSide) {
if (SERVER_TIME % 600 == 10 && worldObj.isRaining() && getRainOffset(0, 1, 0)) {
BiomeGenBase tBiome = getBiome();
if (tBiome.rainfall > 0 && tBiome.temperature >= 0.2) {
Block tInFront = getBlockAtSide(SIDE_TOP);
if (!(tInFront instanceof BlockLiquid) && !(tInFront instanceof IFluidBlock) && !tInFront.isSideSolid(worldObj, xCoord, yCoord + 1, zCoord, FORGE_DIR_OPPOSITES[SIDE_TOP]) && !tInFront.isSideSolid(worldObj, xCoord, yCoord + 1, zCoord, FORGE_DIR[SIDE_TOP])) {
FluidStack tWater = FL.Water.make((long) Math.max(1, tBiome.rainfall * 200) * (worldObj.isThundering() ? 2 : 1));
if (tWater != null) {
IFluidTank tTank = getFluidTankFillable2(SIDE_TOP, tWater);
if (tTank != null)
tTank.fill(tWater, T);
}
}
}
}
boolean tBreak = F;
mDisplay = 0;
for (FluidTankGT tTank : mTanksOutput) if (tTank.has()) {
mDisplay = (short) (-2 - tTank.getFluid().getFluidID());
tBreak = T;
break;
}
if (!tBreak) {
for (FluidTankGT tTank : mTanksInput) if (tTank.has()) {
mDisplay = (short) (-2 - tTank.getFluid().getFluidID());
tBreak = T;
break;
}
if (!tBreak) {
ItemStack tStack;
for (int i = 0; i < 7; i++) if (ST.valid(tStack = slot(6 - i))) {
OreDictItemData tData = OM.data_(tStack);
if (tData == null || tData.mMaterial == null) {
mDisplay = -1;
} else {
mDisplay = tData.mMaterial.mMaterial.mID;
}
tBreak = T;
break;
}
}
}
}
}
use of net.minecraftforge.fluids.IFluidTank in project EvilCraft by CyclopsMC.
the class BlockTankHelpers method tileDataToItemStack.
/**
* Convert fluid capabilities of tile to item.
* @param tile The tile that has already been removed from the world.
* @param itemStack The input itemstack.
* @return The resulting itemstack.
*/
public static ItemStack tileDataToItemStack(BlockEntity tile, ItemStack itemStack) {
IFluidHandler fluidHandlerTile = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY).orElse(null);
if (fluidHandlerTile != null) {
IFluidHandlerItemCapacity fluidHandlerItemCapacity = itemStack.getCapability(Capabilities.FLUID_HANDLER_ITEM_CAPACITY).orElse(null);
if (fluidHandlerItemCapacity != null) {
if (fluidHandlerTile instanceof IFluidTank) {
IFluidTank fluidTank = (IFluidTank) fluidHandlerTile;
fluidHandlerItemCapacity.setCapacity(fluidTank.getCapacity());
itemStack = fluidHandlerItemCapacity.getContainer();
}
}
IFluidHandlerItem fluidHandlerItem = itemStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY).orElse(null);
if (fluidHandlerItem != null) {
FluidActionResult res = FluidUtil.tryFillContainer(itemStack, fluidHandlerTile, Integer.MAX_VALUE, null, true);
if (res.isSuccess()) {
itemStack = res.getResult();
}
}
}
return itemStack;
}
use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCE.
the class WorkableTieredMetaTileEntity method canInputFluid.
protected boolean canInputFluid(FluidStack inputFluid) {
RecipeMap<?> recipeMap = workable.recipeMap;
if (recipeMap.canInputFluidForce(inputFluid.getFluid()))
// if recipe map forces input of given fluid, return true
return true;
Set<Recipe> matchingRecipes = null;
for (IFluidTank fluidTank : importFluids) {
FluidStack fluidInTank = fluidTank.getFluid();
if (fluidInTank != null) {
if (matchingRecipes == null) {
// if we didn't have a list of recipes with any fluids, obtain it from first tank with fluid
matchingRecipes = new HashSet<>(recipeMap.getRecipesForFluid(fluidInTank));
} else {
// else, remove recipes that don't contain fluid in this tank from list
matchingRecipes.removeIf(recipe -> !recipe.hasInputFluid(fluidInTank));
}
}
}
if (matchingRecipes == null) {
// if all tanks are empty, generally fluid can be inserted if there are recipes for it
return !recipeMap.getRecipesForFluid(inputFluid).isEmpty();
} else {
// otherwise, we can insert fluid only if one of recipes accept it as input
return matchingRecipes.stream().anyMatch(recipe -> recipe.hasInputFluid(inputFluid));
}
}
use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCE.
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 GregTech by GregTechCE.
the class FluidTankList method deserializeNBT.
@Override
public void deserializeNBT(NBTTagCompound nbt) {
NBTTagList tanks = nbt.getTagList("Tanks", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < Math.min(fluidTanks.size(), nbt.getInteger("TankAmount")); i++) {
NBTBase nbtTag = tanks.get(i);
IFluidTank fluidTank = fluidTanks.get(i);
if (fluidTank instanceof FluidTank) {
((FluidTank) fluidTank).readFromNBT((NBTTagCompound) nbtTag);
} else if (fluidTank instanceof INBTSerializable) {
((INBTSerializable) fluidTank).deserializeNBT(nbtTag);
}
}
}
Aggregations