use of net.minecraftforge.fluids.capability.IFluidHandler in project Railcraft by Railcraft.
the class TrainTransferHelper method canAcceptPushedFluid.
private boolean canAcceptPushedFluid(EntityMinecart requester, EntityMinecart cart, Fluid fluid) {
IFluidHandler fluidHandler = FluidTools.getFluidHandler(EnumFacing.UP, cart);
if (fluidHandler == null)
return false;
if (cart instanceof IFluidCart)
return ((IFluidCart) cart).canAcceptPushedFluid(requester, fluid);
AdvancedFluidHandler advancedFluidHandler = new AdvancedFluidHandler(fluidHandler);
return advancedFluidHandler.canPutFluid(new FluidStack(fluid, 1));
}
use of net.minecraftforge.fluids.capability.IFluidHandler in project Witchworks by Um-Mitternacht.
the class ItemRitual method onFinish.
@SuppressWarnings("ConstantConditions")
@Override
public void onFinish(TileKettle tile, World world, BlockPos pos) {
for (int i = 0; i < 20; i++) {
final float x = pos.getX() + 0.2F + MathHelper.clamp(world.rand.nextFloat(), 0F, 0.5F);
final float y = pos.getY() + 0.2F + world.rand.nextFloat();
final float z = pos.getZ() + 0.2F + MathHelper.clamp(world.rand.nextFloat(), 0F, 0.5F);
PacketHandler.spawnParticle(ParticleF.STEAM, world, x, y, z, 10, 0, 0, 0);
}
if (!stack.isEmpty()) {
if (tile.getContainer().isEmpty()) {
tile.setContainer(stack);
} else {
spawnItem(world, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D);
}
}
world.playSound(null, pos, SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 1F, 1F);
IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);
handler.drain(1000, true);
}
use of net.minecraftforge.fluids.capability.IFluidHandler in project Overloaded by CJ-MC-Mods.
the class BlockInfiniteWaterSource method onBlockActivated.
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (!worldIn.isRemote && hand == EnumHand.MAIN_HAND) {
TileEntity te = worldIn.getTileEntity(pos);
if (te != null && te instanceof TileInfiniteWaterSource) {
IFluidHandler handler = te.getCapability(FLUID_HANDLER_CAPABILITY, facing);
// FluidUtil.interactWithFluidHandler(playerIn.getHeldItem(hand), te.getCapability(FLUID_HANDLER_CAPABILITY, facing), playerIn);
FluidActionResult result = FluidUtil.tryFillContainerAndStow(playerIn.getHeldItem(hand), handler, null, Integer.MAX_VALUE, playerIn);
if (result.isSuccess())
playerIn.setHeldItem(hand, result.getResult());
}
}
return true;
}
use of net.minecraftforge.fluids.capability.IFluidHandler in project MinecraftForge by MinecraftForge.
the class FluidUtil method tryPickUpFluid.
/**
* Attempts to pick up a fluid in the world and put it in an empty container item.
*
* @param emptyContainer The empty container to fill.
* Will not be modified directly, if modifications are necessary a modified copy is returned in the result.
* @param playerIn The player filling the container. Optional.
* @param worldIn The world the fluid is in.
* @param pos The position of the fluid in the world.
* @param side The side of the fluid that is being drained.
* @return a {@link FluidActionResult} holding the result and the resulting container.
*/
@Nonnull
public static FluidActionResult tryPickUpFluid(@Nonnull ItemStack emptyContainer, @Nullable EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side) {
if (emptyContainer.isEmpty() || worldIn == null || pos == null) {
return FluidActionResult.FAILURE;
}
IBlockState state = worldIn.getBlockState(pos);
Block block = state.getBlock();
if (block instanceof IFluidBlock || block instanceof BlockLiquid) {
IFluidHandler targetFluidHandler = FluidUtil.getFluidHandler(worldIn, pos, side);
if (targetFluidHandler != null) {
FluidActionResult fluidActionResult = FluidUtil.tryFillContainer(emptyContainer, targetFluidHandler, Integer.MAX_VALUE, playerIn, true);
if (fluidActionResult.isSuccess()) {
return fluidActionResult;
}
}
}
return FluidActionResult.FAILURE;
}
use of net.minecraftforge.fluids.capability.IFluidHandler in project MinecraftForge by MinecraftForge.
the class FluidHandlerConcatenate method fill.
@Override
public int fill(FluidStack resource, boolean doFill) {
if (resource == null || resource.amount <= 0)
return 0;
resource = resource.copy();
int totalFillAmount = 0;
for (IFluidHandler handler : subHandlers) {
int fillAmount = handler.fill(resource, doFill);
totalFillAmount += fillAmount;
resource.amount -= fillAmount;
if (resource.amount <= 0)
break;
}
return totalFillAmount;
}
Aggregations