Skip to content

Commit

Permalink
FluidLogged compat
Browse files Browse the repository at this point in the history
  • Loading branch information
FalsePattern committed Feb 3, 2025
1 parent 081f729 commit 11d5180
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 12 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ dependencies {

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

compileOnly("mega:fluidlogged-mc1.7.10:0.1.2")

compileOnly("com.github.GTNewHorizons:lwjgl3ify:2.1.5:dev")

compileOnly(deobf("optifine:optifine:1.7.10_hd_u_e7"))
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/com/falsepattern/falsetweaks/Compat.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ private static class LWJGL3IFY {
PRESENT = present;
}
}
private static class FLUIDLOGGED {
private static final boolean PRESENT;
static {
boolean present;
try {
present = Launch.classLoader.getClassBytes("mega.fluidlogged.internal.core.CoreLoadingPlugin") != null;
} catch (IOException e) {
e.printStackTrace();
present = false;
}
PRESENT = present;
}
}

public static boolean neodymiumInstalled() {
return NEODYMIUM.PRESENT;
Expand All @@ -132,6 +145,10 @@ public static boolean optiFineHasShaders() {
return OPTIFINE.PRESENT && SHADERS.PRESENT;
}

public static boolean fluidloggedInstalled() {
return FLUIDLOGGED.PRESENT;
}

public static void applyCompatibilityTweaks() {
ThreadingCompat.init();
if (Loader.isModLoaded("apparatus")) {
Expand Down Expand Up @@ -171,7 +188,6 @@ public static float getAmbientOcclusionLightValue(Block block, int x, int y, int
return block.getAmbientOcclusionLightValue();
}
}

private static class ApparatusCompat {
@Getter
private static boolean apparatusPresent = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

package com.falsepattern.falsetweaks.modules.threadedupdates;

import com.falsepattern.falsetweaks.Compat;
import com.falsepattern.falsetweaks.Share;
import com.falsepattern.falsetweaks.Tags;
import com.falsepattern.falsetweaks.config.ModuleConfig;
Expand All @@ -45,6 +46,7 @@
import it.unimi.dsi.fastutil.ints.IntSet;
import lombok.RequiredArgsConstructor;
import lombok.val;
import mega.fluidlogged.api.FLBlockAccess;

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

private static final IntSet alreadyWarnedRenderTypes = new IntArraySet();

private static class FluidLoggedCompat {
public static int drawFluidLogged(WorldRenderer wr, UpdateTask task, ChunkCache chunkcache, Tessellator tess, int pass, int flags, RenderBlocks renderblocks, int x, int y, int z) {
val fluid = ((FLBlockAccess)chunkcache).fl$getFluid(x, y, z);
if (fluid == null) {
return flags;
}
val fluidBlock = fluid.getBlock();
if (fluidBlock == null) {
return flags;
}

if (fluidBlock.getRenderBlockPass() > pass) {
flags |= BIT_NextPass;
}
if (!fluidBlock.canRenderInPass(pass)) {
return flags;
}

flags = startTessellator(wr, task, tess, pass, flags);

try {
flags |= renderblocks.renderBlockByRenderType(fluidBlock, x, y, z) ? BIT_RenderedSomething : 0;
} catch (Exception ignored) {}
return flags;
}
}

private static int doChunkUpdateForRenderPassBlock(WorldRenderer wr, UpdateTask task, ChunkCache chunkcache, Tessellator tess, int pass, RenderBlocks renderblocks, int x, int y, int z, int flags) {
Block block = chunkcache.getBlock(x, y, z);
val rt = block.getRenderType();
Expand All @@ -238,24 +267,19 @@ private static int doChunkUpdateForRenderPassBlock(WorldRenderer wr, UpdateTask
}
}

if (Compat.fluidloggedInstalled()) {
flags = FluidLoggedCompat.drawFluidLogged(wr, task, chunkcache, tess, pass, flags, renderblocks, x, y, z);
}

if (block.getRenderBlockPass() > pass) {
flags |= BIT_NextPass;
}

if (!block.canRenderInPass(pass)) {
return flags;
}
if (!hasFlag(flags, BIT_StartedTessellator)) {
if (ModuleConfig.TRIANGULATOR()) {
ToggleableTessellatorManager.preRenderBlocks(pass);
}
flags |= BIT_StartedTessellator;
if (AGGRESSIVE_NEODYMIUM_THREADING) {
NeodymiumCompat.beginRenderPass(task, wr, pass);
}
tess.startDrawingQuads();
tess.setTranslation(-wr.posX, -wr.posY, -wr.posZ);
}

flags = startTessellator(wr, task, tess, pass, flags);

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

private static int startTessellator(WorldRenderer wr, UpdateTask task, Tessellator tess, int pass, int flags) {
if (!hasFlag(flags, BIT_StartedTessellator)) {
if (ModuleConfig.TRIANGULATOR()) {
ToggleableTessellatorManager.preRenderBlocks(pass);
}
flags |= BIT_StartedTessellator;
if (AGGRESSIVE_NEODYMIUM_THREADING) {
NeodymiumCompat.beginRenderPass(task, wr, pass);
}
tess.startDrawingQuads();
tess.setTranslation(-wr.posX, -wr.posY, -wr.posZ);
}
return flags;
}

public static boolean isMainThread() {
val thread = Thread.currentThread();
if (MAIN_THREAD == null)
Expand Down

0 comments on commit 11d5180

Please sign in to comment.