Skip to content

Commit

Permalink
Enable pulling from waterlogged blocks, Closes #20
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Sep 20, 2021
1 parent 8d2932c commit 58613bf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FlowingFluidBlock;
import net.minecraft.block.IWaterLoggable;
import net.minecraft.fluid.Fluids;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
Expand Down Expand Up @@ -40,6 +43,8 @@ public FluidStack getFluidInTank(int tank) {
Block block = this.state.getBlock();
if (block instanceof FlowingFluidBlock && this.state.get(FlowingFluidBlock.LEVEL) == 0) {
return new FluidStack(((FlowingFluidBlock) block).getFluid(), FluidHelpers.BUCKET_VOLUME);
} else if (this.state.hasProperty(BlockStateProperties.WATERLOGGED) && this.state.get(BlockStateProperties.WATERLOGGED)) {
return new FluidStack(Fluids.WATER, FluidHelpers.BUCKET_VOLUME);
} else {
return FluidStack.EMPTY;
}
Expand Down Expand Up @@ -67,6 +72,10 @@ public FluidStack drain(FluidStack resource, FluidAction action) {
if (block instanceof FlowingFluidBlock
&& ((FlowingFluidBlock) block).getFluid() == resource.getFluid()) {
return this.drain(resource.getAmount(), action);
} else if (this.state.hasProperty(BlockStateProperties.WATERLOGGED)
&& this.state.get(BlockStateProperties.WATERLOGGED)
&& block instanceof IWaterLoggable) {
return this.drain(resource.getAmount(), action);
}
return FluidStack.EMPTY;
}
Expand All @@ -82,6 +91,14 @@ public FluidStack drain(int maxDrain, FluidAction action) {
this.world.setBlockState(this.blockPos, Blocks.AIR.getDefaultState(), 11);
}
return new FluidStack(((FlowingFluidBlock) block).getFluid(), FluidHelpers.BUCKET_VOLUME);
} else if (this.state.hasProperty(BlockStateProperties.WATERLOGGED)
&& this.state.get(BlockStateProperties.WATERLOGGED)
&& block instanceof IWaterLoggable
&& maxDrain >= FluidHelpers.BUCKET_VOLUME) {
if (action.execute()) {
((IWaterLoggable) block).pickupFluid(world, blockPos, state);
}
return new FluidStack(Fluids.WATER, FluidHelpers.BUCKET_VOLUME);
}
return FluidStack.EMPTY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FlowingFluidBlock;
import net.minecraft.block.IWaterLoggable;
import net.minecraft.block.material.Material;
import net.minecraft.fluid.Fluid;
import net.minecraft.nbt.CompoundNBT;
Expand Down Expand Up @@ -226,7 +227,7 @@ protected boolean pullFluidsFromWorld() {
}

private LazyOptional<IFluidHandler> wrapFluidBlock(BlockState blockState, World world, BlockPos targetPos) {
if (blockState.getBlock() instanceof FlowingFluidBlock) {
if (blockState.getBlock() instanceof FlowingFluidBlock || blockState.getBlock() instanceof IWaterLoggable) {
return LazyOptional.of(() -> new FluidHandlerBlock(blockState, world, targetPos));
}
return LazyOptional.empty();
Expand Down

0 comments on commit 58613bf

Please sign in to comment.