[1.16] ForgeEventFactory#canCreateFluidSource reintroduced (#7181)
This commit is contained in:
parent
e803006360
commit
e3db429763
|
@ -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)) {
|
|
@ -76,6 +76,7 @@ import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraft.world.Explosion;
|
import net.minecraft.world.Explosion;
|
||||||
import net.minecraft.world.GameRules;
|
import net.minecraft.world.GameRules;
|
||||||
import net.minecraft.world.IWorld;
|
import net.minecraft.world.IWorld;
|
||||||
|
import net.minecraft.world.IWorldReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.server.ServerWorld;
|
import net.minecraft.world.server.ServerWorld;
|
||||||
import net.minecraft.world.WorldSettings;
|
import net.minecraft.world.WorldSettings;
|
||||||
|
@ -656,7 +657,7 @@ public class ForgeEventFactory
|
||||||
return event.getTable();
|
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);
|
CreateFluidSourceEvent evt = new CreateFluidSourceEvent(world, pos, state);
|
||||||
MinecraftForge.EVENT_BUS.post(evt);
|
MinecraftForge.EVENT_BUS.post(evt);
|
||||||
|
|
|
@ -34,6 +34,7 @@ import net.minecraft.util.NonNullList;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.world.IWorld;
|
import net.minecraft.world.IWorld;
|
||||||
|
import net.minecraft.world.IWorldReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeHooks;
|
import net.minecraftforge.common.ForgeHooks;
|
||||||
import net.minecraftforge.common.ToolType;
|
import net.minecraftforge.common.ToolType;
|
||||||
|
@ -243,11 +244,32 @@ public class BlockEvent extends Event
|
||||||
* even if the liquid usually does do that (like water).
|
* even if the liquid usually does do that (like water).
|
||||||
*/
|
*/
|
||||||
@HasResult
|
@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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -78,3 +78,5 @@ license="LGPL v2.1"
|
||||||
modId="tool_interact_test"
|
modId="tool_interact_test"
|
||||||
[[mods]]
|
[[mods]]
|
||||||
modId="custom_elytra_test"
|
modId="custom_elytra_test"
|
||||||
|
[[mods]]
|
||||||
|
modId="finite_water_test"
|
Loading…
Reference in New Issue