Skip to content

Commit 02f7e14

Browse files
committed
API preparations based on feedback
1 parent 3662601 commit 02f7e14

18 files changed

+184
-61
lines changed

build.gradle.kts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,10 @@ minecraft_fp {
3333
repositories {
3434
exclusive(mavenpattern(), "com.falsepattern")
3535
cursemavenEX()
36-
modrinthEX()
3736
}
3837

3938
dependencies {
4039
implementationSplit("com.falsepattern:falsepatternlib-mc1.7.10:1.5.9")
4140
implementationSplit("com.falsepattern:chunkapi-mc1.7.10:0.6.1")
42-
compileOnly(deobfCurse("buildcraft-61811:4055732"))
43-
devOnlyNonPublishable(deobfCurse("thermal-expansion-69163:2388758"))
44-
devOnlyNonPublishable(deobfCurse("thermal-foundation-222880:2388752"))
4541
compileOnly(deobfCurse("cofhcore-69162:2388750"))
46-
47-
runtimeOnlyNonPublishable(deobfModrinth("baubles-expanded:2.1.4"))
4842
}

src/main/java/mega/fluidlogged/internal/mixin/hook/FLBlockAccess.java renamed to src/main/java/mega/fluidlogged/api/FLBlockAccess.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,31 @@
2020
* along with FluidLogged. If not, see <https://www.gnu.org/licenses/>.
2121
*/
2222

23-
package mega.fluidlogged.internal.mixin.hook;
23+
package mega.fluidlogged.api;
2424

2525
import lombok.val;
26+
import org.jetbrains.annotations.ApiStatus;
2627
import org.jetbrains.annotations.Nullable;
2728

29+
import net.minecraft.world.ChunkCache;
30+
import net.minecraft.world.World;
2831
import net.minecraftforge.fluids.Fluid;
2932

33+
/**
34+
* Implemented on {@link net.minecraft.world.World} and {@link net.minecraft.world.ChunkCache} via mixins.
35+
*/
36+
@ApiStatus.NonExtendable
3037
public interface FLBlockAccess {
38+
/**
39+
* Retrieves the fluid from a fluidlogged block. Null if not fluidlogged. Note that this returns null if the block itself is a fluid block!
40+
*/
41+
@Nullable Fluid fl$getFluid(int x, int y, int z);
42+
43+
/**
44+
* Makes a block fluidlogged with the given fluid. Does NOT verify whether the block can be fluidlogged!
45+
* Pass in null to clear.
46+
*/
47+
void fl$setFluid(int x, int y, int z, @Nullable Fluid fluid);
3148
default boolean fl$isFluidLogged(int x, int y, int z, @Nullable Fluid fluid) {
3249
val fluidInChunk = fl$getFluid(x, y, z);
3350
if (fluidInChunk == null)
@@ -36,6 +53,12 @@ public interface FLBlockAccess {
3653
return true;
3754
return fluid.equals(fluidInChunk);
3855
}
39-
void fl$setFluid(int x, int y, int z, @Nullable Fluid fluid);
40-
@Nullable Fluid fl$getFluid(int x, int y, int z);
56+
57+
static FLBlockAccess of(World world) {
58+
return (FLBlockAccess) world;
59+
}
60+
61+
static FLBlockAccess of(ChunkCache cache) {
62+
return (FLBlockAccess) cache;
63+
}
4164
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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.api;
24+
25+
import org.jetbrains.annotations.ApiStatus;
26+
import org.jetbrains.annotations.Nullable;
27+
28+
import net.minecraft.world.chunk.Chunk;
29+
import net.minecraftforge.fluids.Fluid;
30+
31+
/**
32+
* Implemented on {@link net.minecraft.world.chunk.Chunk} via a mixin.
33+
*/
34+
@ApiStatus.NonExtendable
35+
public interface FLChunk {
36+
/**
37+
* Retrieves the fluid from a fluidlogged block. Null if not fluidlogged. Note that this returns null if the block itself is a fluid block!
38+
*/
39+
@Nullable Fluid fl$getFluid(int x, int y, int z);
40+
41+
/**
42+
* Makes a block fluidlogged with the given fluid. Does NOT verify whether the block can be fluidlogged!
43+
* Pass in null to clear.
44+
*/
45+
void fl$setFluid(int x, int y, int z, @Nullable Fluid fluid);
46+
47+
static FLChunk of(Chunk chunk) {
48+
return (FLChunk) chunk;
49+
}
50+
}

src/main/java/mega/fluidlogged/api/bucket/BucketDriver.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,72 @@
2323
package mega.fluidlogged.api.bucket;
2424

2525
import mega.fluidlogged.internal.bucket.FLBucketDriver;
26+
import mega.fluidlogged.internal.mixin.hook.FLWorld;
27+
import mega.fluidlogged.internal.world.FLWorldDriver;
2628
import org.jetbrains.annotations.ApiStatus;
2729
import org.jetbrains.annotations.NotNull;
2830
import org.jetbrains.annotations.Nullable;
2931

32+
import net.minecraft.block.Block;
3033
import net.minecraft.item.ItemStack;
3134
import net.minecraftforge.fluids.Fluid;
3235

36+
/**
37+
* This is used for implementing custom buckets.
38+
* <p>
39+
* If a mod's buckets don't work, make sure it fires a FillBucketEvent in its {@link net.minecraft.item.Item#onItemRightClick}. If it uses some sort of custom "bucket" item not
40+
* registered in the forge registry, then implement the respective subclasses of this class.
41+
* <p>
42+
* See {@link mega.fluidlogged.internal.mixin.mixins.common.compat.cofh.ItemBucketMixin} for how to implement an event hook like that.
43+
*/
3344
public interface BucketDriver {
45+
/**
46+
* Used to check the "fullness" of a bucket item
47+
*/
3448
@ApiStatus.OverrideOnly
3549
interface Query extends BucketDriver {
50+
/**
51+
*
52+
* @param bucket A possible bucket item
53+
* @return Whether the bucket is filled or empty.
54+
* @implSpec Return null if this driver cannot handle the given item.
55+
*/
3656
@Nullable BucketState queryState(@NotNull ItemStack bucket);
3757
}
3858

59+
/**
60+
* Used to fill empty buckets with fluids
61+
*/
3962
@ApiStatus.OverrideOnly
4063
interface Fill extends BucketDriver {
64+
/**
65+
* Fills the given empty bucket with a fluid
66+
* @param fluid The fluid to fill the bucket with
67+
* @param bucket The bucket to fill
68+
* @return The filled bucket
69+
* @implSpec Return null if this driver cannot fill the given bucket.
70+
*/
4171
@Nullable ItemStack fillBucket(@NotNull Fluid fluid, @NotNull ItemStack bucket);
4272
}
4373

74+
/**
75+
* Used to empty out buckets into a fluid + empty bucket pair
76+
*/
4477
@ApiStatus.OverrideOnly
4578
interface Empty extends BucketDriver {
79+
/**
80+
* Empties a fluid out of the given bucket
81+
* @param bucket The bucket to empty out
82+
* @return The empty bucket and its fluid
83+
* @implSpec Return null if this driver cannot empty the given bucket.
84+
*/
4685
@Nullable BucketEmptyResults emptyBucket(@NotNull ItemStack bucket);
4786
}
4887

88+
/**
89+
* Register the provided driver.
90+
* @implSpec The driver must implement at least one of {@link Query}, {@link Fill}, or {@link Empty}, or this method throws an exception.
91+
*/
4992
static void register(@NotNull BucketDriver driver) {
5093
FLBucketDriver.INSTANCE.registerDriver(driver);
5194
}

src/main/java/mega/fluidlogged/internal/mixin/hook/FLChunk.java renamed to src/main/java/mega/fluidlogged/api/package-info.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,7 @@
1919
* You should have received a copy of the GNU Lesser General Public License
2020
* along with FluidLogged. If not, see <https://www.gnu.org/licenses/>.
2121
*/
22+
@ApiStatus.Experimental
23+
package mega.fluidlogged.api;
2224

23-
package mega.fluidlogged.internal.mixin.hook;
24-
25-
import org.jetbrains.annotations.Nullable;
26-
27-
import net.minecraftforge.fluids.Fluid;
28-
29-
public interface FLChunk {
30-
@Nullable Fluid fl$getFluid(int x, int y, int z);
31-
void fl$setFluid(int x, int y, int z, @Nullable Fluid fluid);
32-
}
25+
import org.jetbrains.annotations.ApiStatus;

src/main/java/mega/fluidlogged/api/world/WorldDriver.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,28 @@
2323
package mega.fluidlogged.api.world;
2424

2525
import mega.fluidlogged.internal.world.FLWorldDriver;
26+
import org.jetbrains.annotations.ApiStatus;
2627
import org.jetbrains.annotations.NotNull;
2728

2829
import net.minecraft.block.Block;
2930
import net.minecraftforge.fluids.Fluid;
3031

3132
public interface WorldDriver {
33+
@ApiStatus.OverrideOnly
3234
boolean canBeFluidLogged(@NotNull Block block, int meta, @NotNull Fluid fluid);
3335

3436
static void register(@NotNull WorldDriver driver) {
3537
FLWorldDriver.INSTANCE.registerDriver(driver);
3638
}
39+
40+
/**
41+
* Check whether a given block can be fluidlogged by a fluid.
42+
* @param block The block to check
43+
* @param meta The checked block's metadata
44+
* @param fluid The fluid that is trying to fluidlog the block
45+
* @return true to allow fluidlogging
46+
*/
47+
static boolean getCanBeFluidLogged(@NotNull Block block, int meta, @NotNull Fluid fluid) {
48+
return FLWorldDriver.INSTANCE.canBeFluidLogged(block, meta, fluid);
49+
}
3750
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import lombok.RequiredArgsConstructor;
2929
import lombok.val;
3030
import mega.fluidlogged.Tags;
31-
import mega.fluidlogged.internal.mixin.hook.FLChunk;
31+
import mega.fluidlogged.api.FLChunk;
3232
import mega.fluidlogged.internal.mixin.hook.FLPacket;
3333
import mega.fluidlogged.internal.mixin.hook.FLSubChunk;
3434
import mega.fluidlogged.internal.mixin.hook.FLWorld;

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
package mega.fluidlogged.internal;
2424

2525
import lombok.val;
26-
import mega.fluidlogged.internal.mixin.hook.FLBlockAccess;
26+
import mega.fluidlogged.api.FLBlockAccess;
2727
import mega.fluidlogged.internal.mixin.hook.FLWorld;
2828
import org.jetbrains.annotations.NotNull;
2929
import org.jetbrains.annotations.Nullable;
@@ -38,6 +38,7 @@
3838
import net.minecraft.util.MovingObjectPosition;
3939
import net.minecraft.world.IBlockAccess;
4040
import net.minecraft.world.World;
41+
import net.minecraft.world.chunk.Chunk;
4142
import net.minecraftforge.common.MinecraftForge;
4243
import net.minecraftforge.event.entity.player.FillBucketEvent;
4344
import net.minecraftforge.fluids.BlockFluidClassic;
@@ -137,8 +138,8 @@ public static void simulate(@NotNull World world, int x, int y, int z, @NotNull
137138
return null;
138139
}
139140

140-
public static @Nullable Fluid fromWorldBlock(@NotNull World world, int x, int y, int z, @NotNull Block block) {
141-
val meta = world.getBlockMetadata(x, y, z);
141+
public static @Nullable Fluid fromChunkBlock(@NotNull Chunk chunk, int x, int y, int z, @NotNull Block block) {
142+
val meta = chunk.getBlockMetadata(x, y, z);
142143
if (meta != 0) {
143144
return null;
144145
}

src/main/java/mega/fluidlogged/internal/bucket/FLBucketDriver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import mega.fluidlogged.api.bucket.BucketEmptyResults;
2828
import mega.fluidlogged.api.bucket.BucketState;
2929
import mega.fluidlogged.internal.FLUtil;
30-
import mega.fluidlogged.internal.mixin.hook.FLBlockAccess;
30+
import mega.fluidlogged.api.FLBlockAccess;
3131
import mega.fluidlogged.internal.world.FLWorldDriver;
3232

3333
import net.minecraft.item.ItemStack;

src/main/java/mega/fluidlogged/internal/core/ASMHooks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
package mega.fluidlogged.internal.core;
2424

2525
import lombok.val;
26-
import mega.fluidlogged.internal.mixin.hook.FLBlockAccess;
26+
import mega.fluidlogged.api.FLBlockAccess;
2727

2828
import net.minecraft.client.renderer.RenderBlocks;
2929

0 commit comments

Comments
 (0)