Skip to content

Commit cfec67f

Browse files
committed
nuke the manual simulation
1 parent 8624671 commit cfec67f

File tree

12 files changed

+239
-266
lines changed

12 files changed

+239
-266
lines changed

build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@ minecraft_fp {
2929
repositories {
3030
exclusive(mavenpattern(), "com.falsepattern")
3131
cursemavenEX()
32+
modrinthEX()
3233
}
3334

3435
dependencies {
3536
implementationSplit("com.falsepattern:falsepatternlib-mc1.7.10:1.5.9")
3637
implementationSplit("com.falsepattern:chunkapi-mc1.7.10:0.6.1")
38+
compileOnly(deobfCurse("buildcraft-61811:4055732"))
39+
devOnlyNonPublishable(deobfCurse("thermal-expansion-69163:2388758"))
40+
devOnlyNonPublishable(deobfCurse("thermal-foundation-222880:2388752"))
3741
compileOnly(deobfCurse("cofhcore-69162:2388750"))
42+
43+
runtimeOnlyNonPublishable(deobfModrinth("baubles-expanded:2.1.4"))
3844
}

src/main/java/mega/fluidlogged/internal/FLUtil.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import lombok.val;
2626
import mega.fluidlogged.internal.mixin.hook.FLBlockAccess;
2727
import mega.fluidlogged.internal.mixin.hook.FLWorld;
28-
import mega.fluidlogged.internal.sim.ForgeFluidSim;
29-
import mega.fluidlogged.internal.sim.VanillaFluidSim;
3028
import org.jetbrains.annotations.NotNull;
3129
import org.jetbrains.annotations.Nullable;
3230

@@ -53,19 +51,18 @@
5351

5452
public class FLUtil {
5553
public static Block getFluidOrBlock(IBlockAccess access, int x, int y, int z) {
56-
val b = access.getBlock(x, y, z);
5754
if (!(access instanceof FLBlockAccess))
58-
return b;
55+
return access.getBlock(x, y, z);
5956
val fluid = ((FLBlockAccess)access).fl$getFluid(x, y, z);
6057
if (fluid == null)
61-
return b;
58+
return access.getBlock(x, y, z);
6259
val block = fluid.getBlock();
6360
if (block == null)
64-
return b;
61+
return access.getBlock(x, y, z);
6562
return block;
6663
}
6764

68-
public static int getFluidMeta(IBlockAccess access, int x, int y, int z) {
65+
public static int getFluidMeta(IBlockAccess access, int x, int y, int z, int max) {
6966
if (!(access instanceof FLBlockAccess))
7067
return access.getBlockMetadata(x, y, z);
7168
val fluid = ((FLBlockAccess)access).fl$getFluid(x, y, z);
@@ -74,7 +71,7 @@ public static int getFluidMeta(IBlockAccess access, int x, int y, int z) {
7471
val block = fluid.getBlock();
7572
if (block == null)
7673
return access.getBlockMetadata(x, y, z);
77-
return 0;
74+
return max;
7875
}
7976

8077
public static void fireBucketEvent(ItemStack item, World world, EntityPlayer player, Consumer<ItemStack> resultCallback, MovingObjectPosition pos) {
@@ -109,7 +106,7 @@ public static void onFluidPlacedInto(@NotNull World world, int x, int y, int z,
109106
if (fluidBlock instanceof BlockLiquid) {
110107
((FLWorld)world).fl$scheduleFluidUpdate(x, y, z, block, fluidBlock.tickRate(world));
111108
} else if (fluidBlock instanceof IFluidBlock) {
112-
// TODO
109+
((FLWorld)world).fl$scheduleFluidUpdate(x, y, z, block, fluidBlock.tickRate(world));
113110
}
114111
}
115112

@@ -118,20 +115,26 @@ public static void simulate(@NotNull World world, int x, int y, int z, @NotNull
118115
if (block == null)
119116
return;
120117
if (block instanceof BlockLiquid) {
121-
VanillaFluidSim.simulate(world, x, y, z, random, (BlockLiquid) resolveVanillaSimulationLiquid(block));
118+
val simBlock = resolveVanillaSimulationLiquid(block);
119+
if (simBlock != null) {
120+
simBlock.updateTick(world, x, y, z, random);
121+
}
122122
} else if (block instanceof BlockFluidClassic) {
123-
ForgeFluidSim.simulate(world, x, y, z, random, (BlockFluidClassic) block);
123+
block.updateTick(world, x, y, z, random);
124124
}
125125
}
126126

127-
private static Block resolveVanillaSimulationLiquid(Block block) {
127+
private static @Nullable BlockDynamicLiquid resolveVanillaSimulationLiquid(Block block) {
128+
if (block instanceof BlockDynamicLiquid) {
129+
return (BlockDynamicLiquid) block;
130+
}
128131
if (block instanceof BlockStaticLiquid) {
129132
val dynamic = Block.getBlockById(Block.getIdFromBlock(block) - 1);
130133
if (dynamic instanceof BlockDynamicLiquid && dynamic.getMaterial() == block.getMaterial()) {
131-
return dynamic;
134+
return (BlockDynamicLiquid) dynamic;
132135
}
133136
}
134-
return block;
137+
return null;
135138
}
136139

137140
public static @Nullable Fluid fromWorldBlock(@NotNull World world, int x, int y, int z, @NotNull Block block) {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* This file is part of FluidLogged.
3+
*
4+
* Copyright (C) 2025 The MEGA Team, FalsePattern
5+
* All Rights Reserved
6+
*
7+
* The above copyright notice, this permission notice and the word "MEGA"
8+
* shall be included in all copies or substantial portions of the Software.
9+
*
10+
* FluidLogged is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Lesser General Public License as published by
12+
* the Free Software Foundation, only version 3 of the License.
13+
*
14+
* FluidLogged is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with FluidLogged. If not, see <https://www.gnu.org/licenses/>.
21+
*/
22+
23+
package mega.fluidlogged.internal.mixin.mixins.client;
24+
25+
import mega.fluidlogged.internal.FLUtil;
26+
import org.spongepowered.asm.mixin.Mixin;
27+
import org.spongepowered.asm.mixin.injection.At;
28+
import org.spongepowered.asm.mixin.injection.Redirect;
29+
30+
import net.minecraft.block.Block;
31+
import net.minecraft.world.IBlockAccess;
32+
import net.minecraftforge.fluids.BlockFluidBase;
33+
34+
@Mixin(BlockFluidBase.class)
35+
public abstract class BlockFluidBaseMixin {
36+
@Redirect(method = "shouldSideBeRendered",
37+
at = @At(value = "INVOKE",
38+
target = "Lnet/minecraft/world/IBlockAccess;getBlock(III)Lnet/minecraft/block/Block;"),
39+
require = 1)
40+
private Block getFluidLogged(IBlockAccess instance, int x, int y, int z) {
41+
return FLUtil.getFluidOrBlock(instance, x, y, z);
42+
}
43+
}

src/main/java/mega/fluidlogged/internal/mixin/mixins/client/RenderBlockFluidMixin.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
package mega.fluidlogged.internal.mixin.mixins.client;
2424

2525
import com.llamalad7.mixinextras.sugar.Local;
26-
import lombok.val;
26+
import mega.fluidlogged.internal.FLUtil;
2727
import mega.fluidlogged.internal.mixin.hook.FLBlockAccess;
2828
import org.spongepowered.asm.mixin.Mixin;
2929
import org.spongepowered.asm.mixin.injection.At;
@@ -42,25 +42,15 @@ public abstract class RenderBlockFluidMixin {
4242
target = "Lnet/minecraft/world/IBlockAccess;getBlock(III)Lnet/minecraft/block/Block;"),
4343
require = 4)
4444
private Block fluidHeightGetBlock(IBlockAccess world, int x, int y, int z) {
45-
val fluid = ((FLBlockAccess)world).fl$getFluid(x, y, z);
46-
val blockFluid = fluid == null ? null : fluid.getBlock();
47-
if (blockFluid == null) {
48-
return world.getBlock(x, y, z);
49-
}
50-
return blockFluid;
45+
return FLUtil.getFluidOrBlock(world, x, y, z);
5146
}
5247

5348
@Redirect(method = "getFluidHeightForRender",
5449
at = @At(value = "INVOKE",
5550
target = "Lnet/minecraft/world/IBlockAccess;getBlockMetadata(III)I"),
5651
require = 1)
5752
private int fluidHeightGetBlockMeta(IBlockAccess world, int x, int y, int z, @Local(argsOnly = true) BlockFluidBase inputBlock) {
58-
val fluid = ((FLBlockAccess)world).fl$getFluid(x, y, z);
59-
val blockFluid = fluid == null ? null : fluid.getBlock();
60-
if (blockFluid == null) {
61-
return world.getBlockMetadata(x, y, z);
62-
}
63-
return inputBlock.getMaxRenderHeightMeta();
53+
return FLUtil.getFluidMeta(world, x, y, z, inputBlock.getMaxRenderHeightMeta());
6454
}
6555

6656
@Redirect(method = "getFluidHeightForRender",
@@ -73,4 +63,20 @@ private float fluidHeightQuanta(BlockFluidBase instance, IBlockAccess world, int
7363
}
7464
return instance.getQuantaPercentage(world, x, y, z);
7565
}
66+
67+
@Redirect(method = "renderWorldBlock",
68+
at = @At(value = "INVOKE",
69+
target = "Lnet/minecraft/world/IBlockAccess;getBlock(III)Lnet/minecraft/block/Block;"),
70+
require = 1)
71+
private Block renderWorldBlockGetBlock(IBlockAccess instance, int x, int y, int z) {
72+
return FLUtil.getFluidOrBlock(instance, x, y, z);
73+
}
74+
75+
@Redirect(method = "renderWorldBlock",
76+
at = @At(value = "INVOKE",
77+
target = "Lnet/minecraft/world/IBlockAccess;getBlockMetadata(III)I"),
78+
require = 1)
79+
private int renderWorldBlockGetMetadata(IBlockAccess instance, int x, int y, int z) {
80+
return FLUtil.getFluidMeta(instance, x, y, z, 0);
81+
}
7682
}

src/main/java/mega/fluidlogged/internal/mixin/mixins/client/RenderBlocksMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ private Block hijackGetBlock(IBlockAccess instance, int x, int y, int z) {
4747
target = "Lnet/minecraft/world/IBlockAccess;getBlockMetadata(III)I"),
4848
require = 1)
4949
private int hijackMeta(IBlockAccess instance, int x, int y, int z) {
50-
return FLUtil.getFluidMeta(instance, x, y, z);
50+
return FLUtil.getFluidMeta(instance, x, y, z, 0);
5151
}
5252
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* This file is part of FluidLogged.
3+
*
4+
* Copyright (C) 2025 The MEGA Team, FalsePattern
5+
* All Rights Reserved
6+
*
7+
* The above copyright notice, this permission notice and the word "MEGA"
8+
* shall be included in all copies or substantial portions of the Software.
9+
*
10+
* FluidLogged is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Lesser General Public License as published by
12+
* the Free Software Foundation, only version 3 of the License.
13+
*
14+
* FluidLogged is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with FluidLogged. If not, see <https://www.gnu.org/licenses/>.
21+
*/
22+
23+
package mega.fluidlogged.internal.mixin.mixins.common;
24+
25+
import org.spongepowered.asm.mixin.Mixin;
26+
import org.spongepowered.asm.mixin.Shadow;
27+
import org.spongepowered.asm.mixin.injection.At;
28+
import org.spongepowered.asm.mixin.injection.Redirect;
29+
30+
import net.minecraft.block.BlockDynamicLiquid;
31+
import net.minecraft.world.World;
32+
33+
@Mixin(BlockDynamicLiquid.class)
34+
public abstract class BlockDynamicLiquidMixin {
35+
@Shadow protected abstract void func_149811_n(World p_149811_1_, int p_149811_2_, int p_149811_3_, int p_149811_4_);
36+
37+
@Redirect(method = "updateTick",
38+
at = @At(value = "INVOKE",
39+
target = "Lnet/minecraft/block/BlockDynamicLiquid;func_149811_n(Lnet/minecraft/world/World;III)V"),
40+
require = 2)
41+
private void safeMakeStatic(BlockDynamicLiquid instance, World world, int x, int y, int z) {
42+
if (world.getBlock(x, y, z) != instance) {
43+
return;
44+
}
45+
((BlockDynamicLiquidMixin)(Object)instance).func_149811_n(world, x, y, z);
46+
}
47+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* This file is part of FluidLogged.
3+
*
4+
* Copyright (C) 2025 The MEGA Team, FalsePattern
5+
* All Rights Reserved
6+
*
7+
* The above copyright notice, this permission notice and the word "MEGA"
8+
* shall be included in all copies or substantial portions of the Software.
9+
*
10+
* FluidLogged is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Lesser General Public License as published by
12+
* the Free Software Foundation, only version 3 of the License.
13+
*
14+
* FluidLogged is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with FluidLogged. If not, see <https://www.gnu.org/licenses/>.
21+
*/
22+
23+
package mega.fluidlogged.internal.mixin.mixins.common;
24+
25+
import com.llamalad7.mixinextras.sugar.Local;
26+
import lombok.val;
27+
import mega.fluidlogged.internal.mixin.hook.FLBlockAccess;
28+
import org.spongepowered.asm.mixin.Mixin;
29+
import org.spongepowered.asm.mixin.injection.At;
30+
import org.spongepowered.asm.mixin.injection.Constant;
31+
import org.spongepowered.asm.mixin.injection.ModifyConstant;
32+
import org.spongepowered.asm.mixin.injection.Redirect;
33+
34+
import net.minecraft.block.material.Material;
35+
import net.minecraft.world.IBlockAccess;
36+
import net.minecraft.world.World;
37+
import net.minecraftforge.fluids.BlockFluidBase;
38+
import net.minecraftforge.fluids.BlockFluidClassic;
39+
import net.minecraftforge.fluids.Fluid;
40+
41+
@Mixin(BlockFluidClassic.class)
42+
public abstract class BlockFluidClassicMixin extends BlockFluidBase {
43+
public BlockFluidClassicMixin(Fluid fluid, Material material) {
44+
super(fluid, material);
45+
}
46+
47+
@Redirect(method = "updateTick",
48+
at = @At(value = "INVOKE",
49+
target = "Lnet/minecraft/world/World;getBlockMetadata(III)I"),
50+
require = 1)
51+
private int metaOnlyIfNotLogged(World instance, int x, int y, int z) {
52+
if (instance.getBlock(x, y, z) != this) {
53+
return 0;
54+
}
55+
return instance.getBlockMetadata(x, y, z);
56+
}
57+
58+
@Redirect(method = "updateTick",
59+
at = @At(value = "INVOKE",
60+
target = "Lnet/minecraft/world/World;setBlockMetadataWithNotify(IIIII)Z",
61+
ordinal = 1),
62+
require = 1)
63+
private boolean setBlockOnlyIfNotLogged(World instance, int x, int y, int z, int meta, int flag) {
64+
if (instance.getBlock(x, y, z) != this) {
65+
return false;
66+
}
67+
return instance.setBlockMetadataWithNotify(x, y, z, meta, flag);
68+
}
69+
70+
@ModifyConstant(method = "getQuantaValue",
71+
constant = @Constant(intValue = -1),
72+
remap = false,
73+
require = 1)
74+
private int hackGetBlock(int constant,
75+
@Local(argsOnly = true) IBlockAccess world,
76+
@Local(ordinal = 0,
77+
argsOnly = true) int x,
78+
@Local(ordinal = 1,
79+
argsOnly = true) int y,
80+
@Local(ordinal = 2,
81+
argsOnly = true) int z) {
82+
if (!(world instanceof FLBlockAccess)) {
83+
return constant;
84+
}
85+
val fluid = ((FLBlockAccess)world).fl$getFluid(x, y, z);
86+
if (fluid == null) {
87+
return constant;
88+
}
89+
90+
val fluidBlock = fluid.getBlock();
91+
if (fluidBlock != this) {
92+
return constant;
93+
}
94+
95+
return quantaPerBlock;
96+
}
97+
}

src/main/java/mega/fluidlogged/internal/mixin/mixins/common/BlockLiquidMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private Block hijackGetBlock(World world, int x, int y, int z) {
4747
target = "Lnet/minecraft/world/World;getBlockMetadata(III)I"),
4848
require = 1)
4949
private int hijackGetMeta(World world, int x, int y, int z) {
50-
return FLUtil.getFluidMeta(world, x, y, z);
50+
return FLUtil.getFluidMeta(world, x, y, z, 0);
5151
}
5252

5353
@Redirect(method = "getEffectiveFlowDecay",
@@ -63,7 +63,7 @@ private Block hijackGetBlockDecay(IBlockAccess instance, int x, int y, int z) {
6363
target = "Lnet/minecraft/world/IBlockAccess;getBlockMetadata(III)I"),
6464
require = 1)
6565
private int hijackMetaDecay(IBlockAccess instance, int x, int y, int z) {
66-
return FLUtil.getFluidMeta(instance, x, y, z);
66+
return FLUtil.getFluidMeta(instance, x, y, z, 0);
6767
}
6868

6969
@Redirect(method = "func_149805_n",

src/main/java/mega/fluidlogged/internal/mixin/mixins/common/EntityMixin.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ private Block checkFluidMaterial(World world, int x, int y, int z, Operation<Blo
7070
remap = false,
7171
require = 1)
7272
private float hackFilledPercentage(IFluidBlock instance, World world, int x, int y, int z) {
73-
// TODO
7473
return instance.getFilledPercentage(world, x, y, z);
7574
}
7675

src/main/java/mega/fluidlogged/internal/mixin/plugin/Mixin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public enum Mixin implements IMixin {
3838
// @formatter:off
3939

4040
common_BlockLiquidMixin(Side.COMMON, always(), "BlockLiquidMixin"),
41+
common_BlockDynamicLiquidMixin(Side.COMMON, always(), "BlockDynamicLiquidMixin"),
42+
common_BlockFluidClassicMixin(Side.COMMON, always(), "BlockFluidClassicMixin"),
4143
common_BlockMixin(Side.COMMON, always(), "BlockMixin"),
4244
common_ChunkCacheMixin(Side.COMMON, always(), "ChunkCacheMixin"),
4345
common_ChunkMixin(Side.COMMON, always(), "ChunkMixin"),
@@ -48,6 +50,7 @@ public enum Mixin implements IMixin {
4850
common_WorldServerMixin(Side.COMMON, always(), "WorldServerMixin"),
4951

5052
client_ActiveRenderInfoMixin(Side.CLIENT, always(), "ActiveRenderInfoMixin"),
53+
client_BlockFluidBaseMixin(Side.CLIENT, always(), "BlockFluidBaseMixin"),
5154
client_BlockLiquidMixin(Side.CLIENT, always(), "BlockLiquidMixin"),
5255
client_RenderBlockFluidMixin(Side.CLIENT, always(), "RenderBlockFluidMixin"),
5356
client_RenderBlocksMixin(Side.CLIENT, always(), "RenderBlocksMixin"),

0 commit comments

Comments
 (0)