Skip to content

Commit

Permalink
Add sodium 0.6 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Sep 14, 2024
1 parent 42290b2 commit fc61ff1
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class SubprojectPlugin: Plugin<Project> {
includeGroup("maven.modrinth")
}
}
flatDir {
dirs = setOf(project.rootProject.file("libs"))
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ jarSets {
dependencies {
modCompileOnly("net.fabricmc:fabric-loader:${property("fabric_loader_version")}")

modCompileOnly(":sodium-fabric-0.6.0-beta.2+mc1.21.1")

testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dev.engine_room.flywheel.impl.compat;

import java.util.function.Supplier;

import com.google.common.base.Suppliers;

import net.fabricmc.loader.api.FabricLoader;

public enum CompatMods {
SODIUM,
EMBEDDIUM;

private final Supplier<Boolean> isLoaded;

CompatMods() {
isLoaded = Suppliers.memoize(() -> FabricLoader.getInstance().isModLoaded(name()));
}

public boolean isLoaded() {
return isLoaded.get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dev.engine_room.flywheel.impl.compat;

import dev.engine_room.flywheel.lib.visualization.VisualizationHelper;
import net.caffeinemc.mods.sodium.api.blockentity.BlockEntityRenderHandler;
import net.caffeinemc.mods.sodium.api.blockentity.BlockEntityRenderPredicate;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;

public class SodiumCompat {
public static <T extends BlockEntity> Object forBlockEntityType(BlockEntityType<T> type) {
BlockEntityRenderPredicate<T> predicate = (getter, pos, be) -> VisualizationHelper.tryAddBlockEntity(be);
BlockEntityRenderHandler.instance().addRenderPredicate(type, predicate);
return predicate;
}

public static <T extends BlockEntity> void removePredicate(BlockEntityType<T> type, Object predicate) {
BlockEntityRenderHandler.instance().removeRenderPredicate(type, (BlockEntityRenderPredicate<T>) predicate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@
import org.spongepowered.asm.mixin.Unique;

import dev.engine_room.flywheel.api.visualization.BlockEntityVisualizer;
import dev.engine_room.flywheel.impl.compat.CompatMods;
import dev.engine_room.flywheel.impl.compat.SodiumCompat;
import dev.engine_room.flywheel.impl.extension.BlockEntityTypeExtension;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;

@Mixin(BlockEntityType.class)
abstract class BlockEntityTypeMixin<T extends BlockEntity> implements BlockEntityTypeExtension<T> {
@Unique
@Nullable
private BlockEntityVisualizer<? super T> flywheel$visualizer;

@Unique
@Nullable
private Object flywheel$sodiumPredicate;

@Override
@Nullable
public BlockEntityVisualizer<? super T> flywheel$getVisualizer() {
Expand All @@ -22,6 +29,13 @@ abstract class BlockEntityTypeMixin<T extends BlockEntity> implements BlockEntit

@Override
public void flywheel$setVisualizer(@Nullable BlockEntityVisualizer<? super T> visualizer) {
if (CompatMods.SODIUM.isLoaded() && !CompatMods.EMBEDDIUM.isLoaded()) {
if (flywheel$visualizer == null && visualizer != null) {
flywheel$sodiumPredicate = SodiumCompat.forBlockEntityType((BlockEntityType<?>) (Object) this);
} else if (flywheel$visualizer != null && visualizer == null && flywheel$sodiumPredicate != null) {
SodiumCompat.removePredicate((BlockEntityType<?>) (Object) this, flywheel$sodiumPredicate);
}
}
this.flywheel$visualizer = visualizer;
}
}
2 changes: 1 addition & 1 deletion fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ dependencies {
modImplementation("net.fabricmc:fabric-loader:${property("fabric_loader_version")}")
modApi("net.fabricmc.fabric-api:fabric-api:${property("fabric_api_version")}")

modCompileOnly("maven.modrinth:sodium:${property("sodium_version")}-fabric")
modCompileOnly(":sodium-fabric-0.6.0-beta.2+mc1.21.1")
modCompileOnly("maven.modrinth:iris:${property("iris_version")}-fabric")

"forApi"(project(path = ":common", configuration = "commonApiOnly"))
Expand Down

This file was deleted.

This file was deleted.

3 changes: 1 addition & 2 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
"mixins": [
"flywheel.backend.mixins.json",
"flywheel.impl.mixins.json",
"flywheel.impl.sodium.mixins.json",
"flywheel.impl.fabric.mixins.json"
],
"depends": {
"minecraft": "${minecraft_semver_version_range}",
"fabric-api": "${fabric_api_version_range}"
},
"breaks": {
"sodium": "<0.5.0"
"sodium": ["<0.6.0-beta.2"]
}
}
14 changes: 0 additions & 14 deletions fabric/src/main/resources/flywheel.impl.sodium.mixins.json

This file was deleted.

8 changes: 1 addition & 7 deletions forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ loom {
add(backend, "backend-flywheel.refmap.json")
}

forge {
mixinConfig("flywheel.backend.mixins.json")
mixinConfig("flywheel.impl.mixins.json")
mixinConfig("flywheel.impl.sodium.mixins.json")
}

runs {
configureEach {
property("forge.logging.markers", "")
Expand All @@ -88,7 +82,7 @@ repositories {
dependencies {
neoForge("net.neoforged:neoforge:${property("neoforge_version")}")

modCompileOnly("maven.modrinth:sodium:${property("sodium_version")}-neoforge")
modCompileOnly(":sodium-neoforge-0.6.0-beta.2+mc1.21.1")
modCompileOnly("maven.modrinth:iris:${property("iris_version")}-neoforge")

//modCompileOnly("maven.modrinth:embeddium:${property("embeddium_version")}")
Expand Down

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions forge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ displayTest = "IGNORE_ALL_VERSION"
config = "flywheel.backend.mixins.json"
[[mixins]]
config = "flywheel.impl.mixins.json"
[[mixins]]
config = "flywheel.impl.sodium.mixins.json"

[[dependencies.${mod_id}]]
modId = "minecraft"
Expand Down
14 changes: 0 additions & 14 deletions forge/src/main/resources/flywheel.impl.sodium.mixins.json

This file was deleted.

1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ neoforge_version_range = [21.0.167,)
# General build dependency versions
java_version = 21
arch_loom_version=1.7.412
cursegradle_version = 1.4.0
parchment_version = 2024.07.07

# Minecraft build dependency versions
Expand Down
Binary file added libs/sodium-fabric-0.6.0-beta.2+mc1.21.1.jar
Binary file not shown.
Binary file added libs/sodium-neoforge-0.6.0-beta.2+mc1.21.1.jar
Binary file not shown.

0 comments on commit fc61ff1

Please sign in to comment.