improve FluidUtils for BuildCraftCompat needs
This commit is contained in:
parent
177eb3d9f1
commit
afe5e4efa5
1 changed files with 16 additions and 3 deletions
|
@ -1,8 +1,12 @@
|
||||||
package buildcraft.core.utils;
|
package buildcraft.core.utils;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.item.ItemBlock;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.fluids.Fluid;
|
import net.minecraftforge.fluids.Fluid;
|
||||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||||
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
import net.minecraftforge.fluids.IFluidBlock;
|
||||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||||
|
|
||||||
public final class FluidUtils {
|
public final class FluidUtils {
|
||||||
|
@ -10,21 +14,30 @@ public final class FluidUtils {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Fluid getFluidFromItemStack(ItemStack stack) {
|
public static FluidStack getFluidStackFromItemStack(ItemStack stack) {
|
||||||
if (stack != null) {
|
if (stack != null) {
|
||||||
if (stack.getItem() instanceof IFluidContainerItem) {
|
if (stack.getItem() instanceof IFluidContainerItem) {
|
||||||
IFluidContainerItem ctr = (IFluidContainerItem) stack.getItem();
|
IFluidContainerItem ctr = (IFluidContainerItem) stack.getItem();
|
||||||
if (ctr.getFluid(stack) != null) {
|
if (ctr.getFluid(stack) != null) {
|
||||||
return ctr.getFluid(stack).getFluid();
|
return ctr.getFluid(stack);
|
||||||
}
|
}
|
||||||
} else if (FluidContainerRegistry.isFilledContainer(stack) &&
|
} else if (FluidContainerRegistry.isFilledContainer(stack) &&
|
||||||
FluidContainerRegistry.getFluidForFilledItem(stack) != null) {
|
FluidContainerRegistry.getFluidForFilledItem(stack) != null) {
|
||||||
return FluidContainerRegistry.getFluidForFilledItem(stack).getFluid();
|
return FluidContainerRegistry.getFluidForFilledItem(stack);
|
||||||
|
} else if (stack.getItem() instanceof ItemBlock) {
|
||||||
|
Block b = Block.getBlockFromItem(stack.getItem());
|
||||||
|
if (b instanceof IFluidBlock) {
|
||||||
|
return new FluidStack(((IFluidBlock) b).getFluid(), 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Fluid getFluidFromItemStack(ItemStack stack) {
|
||||||
|
return getFluidStackFromItemStack(stack).getFluid();
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isFluidContainer(ItemStack stack) {
|
public static boolean isFluidContainer(ItemStack stack) {
|
||||||
return stack.getItem() instanceof IFluidContainerItem || FluidContainerRegistry.isFilledContainer(stack);
|
return stack.getItem() instanceof IFluidContainerItem || FluidContainerRegistry.isFilledContainer(stack);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue