diff --git a/patches/minecraft/net/minecraft/fluid/FlowingFluid.java.patch b/patches/minecraft/net/minecraft/fluid/FlowingFluid.java.patch new file mode 100644 index 0000000000..6fcbd94ba0 --- /dev/null +++ b/patches/minecraft/net/minecraft/fluid/FlowingFluid.java.patch @@ -0,0 +1,20 @@ +--- a/net/minecraft/fluid/FlowingFluid.java ++++ b/net/minecraft/fluid/FlowingFluid.java +@@ -159,7 +159,7 @@ + BlockState blockstate = p_205576_1_.func_180495_p(blockpos); + FluidState fluidstate = blockstate.func_204520_s(); + if (fluidstate.func_206886_c().func_207187_a(this) && this.func_212751_a(direction, p_205576_1_, p_205576_2_, p_205576_3_, blockpos, blockstate)) { +- if (fluidstate.func_206889_d()) { ++ if (fluidstate.func_206889_d() && net.minecraftforge.event.ForgeEventFactory.canCreateFluidSource(p_205576_1_, blockpos, blockstate, this.func_205579_d())) { + ++j; + } + +@@ -167,7 +167,7 @@ + } + } + +- if (this.func_205579_d() && j >= 2) { ++ if (j >= 2) { + BlockState blockstate1 = p_205576_1_.func_180495_p(p_205576_2_.func_177977_b()); + FluidState fluidstate1 = blockstate1.func_204520_s(); + if (blockstate1.func_185904_a().func_76220_a() || this.func_211758_g(fluidstate1)) { diff --git a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java index 81d9e2307e..7fcf30ef3a 100644 --- a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java +++ b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java @@ -76,6 +76,7 @@ import net.minecraft.util.text.ITextComponent; import net.minecraft.world.Explosion; import net.minecraft.world.GameRules; import net.minecraft.world.IWorld; +import net.minecraft.world.IWorldReader; import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; import net.minecraft.world.WorldSettings; @@ -656,7 +657,7 @@ public class ForgeEventFactory return event.getTable(); } - public static boolean canCreateFluidSource(World world, BlockPos pos, BlockState state, boolean def) + public static boolean canCreateFluidSource(IWorldReader world, BlockPos pos, BlockState state, boolean def) { CreateFluidSourceEvent evt = new CreateFluidSourceEvent(world, pos, state); MinecraftForge.EVENT_BUS.post(evt); diff --git a/src/main/java/net/minecraftforge/event/world/BlockEvent.java b/src/main/java/net/minecraftforge/event/world/BlockEvent.java index 1702ae7d87..efbd4b9d2d 100644 --- a/src/main/java/net/minecraftforge/event/world/BlockEvent.java +++ b/src/main/java/net/minecraftforge/event/world/BlockEvent.java @@ -34,6 +34,7 @@ import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.util.Direction; import net.minecraft.world.IWorld; +import net.minecraft.world.IWorldReader; import net.minecraft.world.World; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.ToolType; @@ -243,11 +244,32 @@ public class BlockEvent extends Event * even if the liquid usually does do that (like water). */ @HasResult - public static class CreateFluidSourceEvent extends BlockEvent + public static class CreateFluidSourceEvent extends Event { - public CreateFluidSourceEvent(World world, BlockPos pos, BlockState state) + private final IWorldReader world; + private final BlockPos pos; + private final BlockState state; + + public CreateFluidSourceEvent(IWorldReader world, BlockPos pos, BlockState state) { - super(world, pos, state); + this.world = world; + this.pos = pos; + this.state = state; + } + + public IWorldReader getWorld() + { + return world; + } + + public BlockPos getPos() + { + return pos; + } + + public BlockState getState() + { + return state; } } diff --git a/src/test/java/net/minecraftforge/debug/fluid/FiniteWaterTest.java b/src/test/java/net/minecraftforge/debug/fluid/FiniteWaterTest.java new file mode 100644 index 0000000000..4912f2df8e --- /dev/null +++ b/src/test/java/net/minecraftforge/debug/fluid/FiniteWaterTest.java @@ -0,0 +1,53 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2020. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.debug.fluid; + +import net.minecraft.block.BlockState; +import net.minecraft.fluid.FluidState; +import net.minecraft.fluid.Fluids; +import net.minecraftforge.event.world.BlockEvent; +import net.minecraftforge.eventbus.api.Event; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; + +@Mod("finite_water_test") +@Mod.EventBusSubscriber() +public class FiniteWaterTest +{ + private static final boolean ENABLED = false; + + @SubscribeEvent + public static void handleFiniteWaterSource(BlockEvent.CreateFluidSourceEvent event) + { + if (ENABLED) + { + BlockState state = event.getState(); + FluidState fluidState = state.getFluidState(); + if (fluidState.getFluid().isEquivalentTo(Fluids.WATER)) + { + event.setResult(Event.Result.DENY); + } + else if (fluidState.getFluid().isEquivalentTo(Fluids.LAVA)) + { + event.setResult(Event.Result.ALLOW); + } + } + } +} diff --git a/src/test/resources/META-INF/mods.toml b/src/test/resources/META-INF/mods.toml index b519c735c5..0491585abe 100644 --- a/src/test/resources/META-INF/mods.toml +++ b/src/test/resources/META-INF/mods.toml @@ -78,3 +78,5 @@ license="LGPL v2.1" modId="tool_interact_test" [[mods]] modId="custom_elytra_test" +[[mods]] + modId="finite_water_test" \ No newline at end of file