Skip to content

Commit 11d5180

Browse files
committed
FluidLogged compat
1 parent 081f729 commit 11d5180

3 files changed

Lines changed: 69 additions & 12 deletions

File tree

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ dependencies {
7070

7171
compileOnly("makamys:neodymium-mc1.7.10:0.4.3-unofficial:dev")
7272

73+
compileOnly("mega:fluidlogged-mc1.7.10:0.1.2")
74+
7375
compileOnly("com.github.GTNewHorizons:lwjgl3ify:2.1.5:dev")
7476

7577
compileOnly(deobf("optifine:optifine:1.7.10_hd_u_e7"))

src/main/java/com/falsepattern/falsetweaks/Compat.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,19 @@ private static class LWJGL3IFY {
107107
PRESENT = present;
108108
}
109109
}
110+
private static class FLUIDLOGGED {
111+
private static final boolean PRESENT;
112+
static {
113+
boolean present;
114+
try {
115+
present = Launch.classLoader.getClassBytes("mega.fluidlogged.internal.core.CoreLoadingPlugin") != null;
116+
} catch (IOException e) {
117+
e.printStackTrace();
118+
present = false;
119+
}
120+
PRESENT = present;
121+
}
122+
}
110123

111124
public static boolean neodymiumInstalled() {
112125
return NEODYMIUM.PRESENT;
@@ -132,6 +145,10 @@ public static boolean optiFineHasShaders() {
132145
return OPTIFINE.PRESENT && SHADERS.PRESENT;
133146
}
134147

148+
public static boolean fluidloggedInstalled() {
149+
return FLUIDLOGGED.PRESENT;
150+
}
151+
135152
public static void applyCompatibilityTweaks() {
136153
ThreadingCompat.init();
137154
if (Loader.isModLoaded("apparatus")) {
@@ -171,7 +188,6 @@ public static float getAmbientOcclusionLightValue(Block block, int x, int y, int
171188
return block.getAmbientOcclusionLightValue();
172189
}
173190
}
174-
175191
private static class ApparatusCompat {
176192
@Getter
177193
private static boolean apparatusPresent = false;

src/main/java/com/falsepattern/falsetweaks/modules/threadedupdates/ThreadedChunkUpdateHelper.java

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
package com.falsepattern.falsetweaks.modules.threadedupdates;
2525

26+
import com.falsepattern.falsetweaks.Compat;
2627
import com.falsepattern.falsetweaks.Share;
2728
import com.falsepattern.falsetweaks.Tags;
2829
import com.falsepattern.falsetweaks.config.ModuleConfig;
@@ -45,6 +46,7 @@
4546
import it.unimi.dsi.fastutil.ints.IntSet;
4647
import lombok.RequiredArgsConstructor;
4748
import lombok.val;
49+
import mega.fluidlogged.api.FLBlockAccess;
4850

4951
import net.minecraft.block.Block;
5052
import net.minecraft.block.material.Material;
@@ -219,6 +221,33 @@ private static int doChunkUpdateForRenderPass(WorldRenderer wr, UpdateTask task,
219221

220222
private static final IntSet alreadyWarnedRenderTypes = new IntArraySet();
221223

224+
private static class FluidLoggedCompat {
225+
public static int drawFluidLogged(WorldRenderer wr, UpdateTask task, ChunkCache chunkcache, Tessellator tess, int pass, int flags, RenderBlocks renderblocks, int x, int y, int z) {
226+
val fluid = ((FLBlockAccess)chunkcache).fl$getFluid(x, y, z);
227+
if (fluid == null) {
228+
return flags;
229+
}
230+
val fluidBlock = fluid.getBlock();
231+
if (fluidBlock == null) {
232+
return flags;
233+
}
234+
235+
if (fluidBlock.getRenderBlockPass() > pass) {
236+
flags |= BIT_NextPass;
237+
}
238+
if (!fluidBlock.canRenderInPass(pass)) {
239+
return flags;
240+
}
241+
242+
flags = startTessellator(wr, task, tess, pass, flags);
243+
244+
try {
245+
flags |= renderblocks.renderBlockByRenderType(fluidBlock, x, y, z) ? BIT_RenderedSomething : 0;
246+
} catch (Exception ignored) {}
247+
return flags;
248+
}
249+
}
250+
222251
private static int doChunkUpdateForRenderPassBlock(WorldRenderer wr, UpdateTask task, ChunkCache chunkcache, Tessellator tess, int pass, RenderBlocks renderblocks, int x, int y, int z, int flags) {
223252
Block block = chunkcache.getBlock(x, y, z);
224253
val rt = block.getRenderType();
@@ -238,24 +267,19 @@ private static int doChunkUpdateForRenderPassBlock(WorldRenderer wr, UpdateTask
238267
}
239268
}
240269

270+
if (Compat.fluidloggedInstalled()) {
271+
flags = FluidLoggedCompat.drawFluidLogged(wr, task, chunkcache, tess, pass, flags, renderblocks, x, y, z);
272+
}
273+
241274
if (block.getRenderBlockPass() > pass) {
242275
flags |= BIT_NextPass;
243276
}
244277

245278
if (!block.canRenderInPass(pass)) {
246279
return flags;
247280
}
248-
if (!hasFlag(flags, BIT_StartedTessellator)) {
249-
if (ModuleConfig.TRIANGULATOR()) {
250-
ToggleableTessellatorManager.preRenderBlocks(pass);
251-
}
252-
flags |= BIT_StartedTessellator;
253-
if (AGGRESSIVE_NEODYMIUM_THREADING) {
254-
NeodymiumCompat.beginRenderPass(task, wr, pass);
255-
}
256-
tess.startDrawingQuads();
257-
tess.setTranslation(-wr.posX, -wr.posY, -wr.posZ);
258-
}
281+
282+
flags = startTessellator(wr, task, tess, pass, flags);
259283

260284
try {
261285
flags |= renderblocks.renderBlockByRenderType(block, x, y, z) ? BIT_RenderedSomething : 0;
@@ -278,6 +302,21 @@ private static int doChunkUpdateForRenderPassBlock(WorldRenderer wr, UpdateTask
278302
return flags;
279303
}
280304

305+
private static int startTessellator(WorldRenderer wr, UpdateTask task, Tessellator tess, int pass, int flags) {
306+
if (!hasFlag(flags, BIT_StartedTessellator)) {
307+
if (ModuleConfig.TRIANGULATOR()) {
308+
ToggleableTessellatorManager.preRenderBlocks(pass);
309+
}
310+
flags |= BIT_StartedTessellator;
311+
if (AGGRESSIVE_NEODYMIUM_THREADING) {
312+
NeodymiumCompat.beginRenderPass(task, wr, pass);
313+
}
314+
tess.startDrawingQuads();
315+
tess.setTranslation(-wr.posX, -wr.posY, -wr.posZ);
316+
}
317+
return flags;
318+
}
319+
281320
public static boolean isMainThread() {
282321
val thread = Thread.currentThread();
283322
if (MAIN_THREAD == null)

0 commit comments

Comments
 (0)