Skip to content

Commit

Permalink
Backport changes from 1.21.1
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Oct 12, 2024
1 parent 4057742 commit dd80ea4
Show file tree
Hide file tree
Showing 26 changed files with 132 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,25 @@ class SubprojectPlugin: Plugin<Project> {
includeGroup("maven.modrinth")
}
}
flatDir {
dirs = setOf(project.rootProject.file("libs"))
}
}
}

@Suppress("UnstableApiUsage")
private fun setupDependencies(project: Project) {
project.dependencies.apply {
val minecraft_version: String by project
val parchment_minecraft_version: String by project
val parchment_version: String by project
val loom = project.the<LoomGradleExtensionAPI>()

add("minecraft", "com.mojang:minecraft:${minecraft_version}")

add("mappings", loom.layered {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip")
parchment("org.parchmentmc.data:parchment-${parchment_minecraft_version}:${parchment_version}@zip")
})

add("api", "com.google.code.findbugs:jsr305:3.0.2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.SourceSet
import java.util.*

open class TransitiveSourceSetsExtension(private val project: Project) {
var compileClasspath: FileCollection? = null
Expand All @@ -25,7 +26,7 @@ open class TransitiveSourceSetsExtension(private val project: Project) {

fun createCompileConfigurations() {
val configs = transitives.mapValues { (sourceSet, _) ->
project.configurations.create("for${sourceSet.name.capitalize()}") {
project.configurations.create("for${sourceSet.name.replaceFirstChar { it.uppercase() }}") {
isCanBeConsumed = true
isCanBeResolved = false
}
Expand All @@ -43,7 +44,7 @@ open class TransitiveSourceSetsExtension(private val project: Project) {

fun createRuntimeConfigurations() {
val configs = transitives.mapValues { (sourceSet, _) ->
project.configurations.create("run${sourceSet.name.capitalize()}") {
project.configurations.create("run${sourceSet.name.replaceFirstChar { it.uppercase() }}") {
isCanBeConsumed = true
isCanBeResolved = false
}
Expand Down
3 changes: 3 additions & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ jarSets {
dependencies {
modCompileOnly("net.fabricmc:fabric-loader:${property("fabric_loader_version")}")

modCompileOnly("maven.modrinth:embeddium:${property("embeddium_version")}")
modCompileOnly(":sodium-fabric-1.20.1-0.6.0-intermediary-mappings")

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import dev.engine_room.flywheel.api.Flywheel;
import dev.engine_room.flywheel.backend.FlwBackend;
import dev.engine_room.flywheel.impl.compat.CompatMods;
import dev.engine_room.flywheel.impl.compat.EmbeddiumCompat;
import dev.engine_room.flywheel.impl.registry.IdRegistryImpl;
import dev.engine_room.flywheel.lib.util.ShadersModHandler;
import dev.engine_room.flywheel.vanilla.VanillaVisuals;
Expand All @@ -28,6 +30,10 @@ public static void init() {

// vanilla
VanillaVisuals.init();

// Embeddium Compat
if (CompatMods.EMBEDDIUM.isLoaded())
EmbeddiumCompat.init();
}

public static void freezeRegistries() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.engine_room.flywheel.impl;

import java.util.function.BooleanSupplier;

import dev.engine_room.flywheel.api.internal.DependencyInjection;
import net.minecraft.client.multiplayer.ClientLevel;

Expand All @@ -11,4 +13,6 @@ public interface FlwImplXplat {
String getVersionStr();

FlwConfig getConfig();

BooleanSupplier getModLoaded(String modId);
}
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.BooleanSupplier;

import dev.engine_room.flywheel.impl.FlwImplXplat;

public enum CompatMods {
SODIUM("sodium"),
EMBEDDIUM("embeddium"),
IRIS("iris"),
OCULUS("oculus");

private final BooleanSupplier isLoaded;

CompatMods(String modid) {
isLoaded = FlwImplXplat.INSTANCE.getModLoaded(modid);
}

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

import org.embeddedt.embeddium.api.ChunkDataBuiltEvent;

public class EmbeddiumCompat {
public static void init() {
ChunkDataBuiltEvent.BUS.addListener(event -> {
event.getDataBuilder().removeBlockEntitiesIf(InstancedRenderDispatcher::tryAddBlockEntity);
});
}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ abstract class LevelRendererMixin {
}

@Inject(method = "renderEntity", at = @At("HEAD"), cancellable = true)
private void flywheel$decideNotToRenderEntity(Entity pEntity, double pCamX, double pCamY, double pCamZ, float pPartialTick, PoseStack pPoseStack, MultiBufferSource pBufferSource, CallbackInfo ci) {
if (VisualizationManager.supportsVisualization(pEntity.level()) && VisualizationHelper.skipVanillaRender(pEntity)) {
private void flywheel$decideNotToRenderEntity(Entity entity, double camX, double camY, double camZ, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, CallbackInfo ci) {
if (VisualizationManager.supportsVisualization(entity.level()) && VisualizationHelper.skipVanillaRender(entity)) {
ci.cancel();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package dev.engine_room.flywheel.impl;

import java.util.function.BooleanSupplier;

import dev.engine_room.flywheel.api.event.ReloadLevelRendererCallback;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.multiplayer.ClientLevel;

public class FlwImplXplatImpl implements FlwImplXplat {
Expand All @@ -18,4 +21,9 @@ public String getVersionStr() {
public FlwConfig getConfig() {
return FabricFlwConfig.INSTANCE;
}

@Override
public BooleanSupplier getModLoaded(String modId) {
return () -> FabricLoader.getInstance().isModLoaded(modId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.UnknownNullability;

import dev.engine_room.flywheel.impl.compat.CompatMods;
import dev.engine_room.flywheel.lib.internal.FlwLibXplat;
import dev.engine_room.flywheel.lib.model.baked.BakedModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.BlockModelBuilder;
Expand All @@ -11,7 +12,6 @@
import dev.engine_room.flywheel.lib.model.baked.FabricMultiBlockModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.MultiBlockModelBuilder;
import dev.engine_room.flywheel.lib.util.ShadersModHandler;
import net.fabricmc.loader.api.FabricLoader;
import net.irisshaders.iris.api.v0.IrisApi;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
Expand Down Expand Up @@ -52,8 +52,7 @@ public MultiBlockModelBuilder createMultiBlockModelBuilder(BlockAndTintGetter le
@Override
@Nullable
public ShadersModHandler.InternalHandler createIrisHandler() {
if (!FabricLoader.getInstance()
.isModLoaded("iris")) {
if (!CompatMods.IRIS.isLoaded()) {
return null;
}

Expand Down
3 changes: 2 additions & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"fabric-api": "${fabric_api_version_range}"
},
"breaks": {
"sodium": "<0.5.0"
"sodium": ["<0.5.0", "~0.6.0- <0.6.0-beta.2"],
"embeddium": "<0.3.25"
}
}
3 changes: 1 addition & 2 deletions forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ loom {
forge {
mixinConfig("flywheel.backend.mixins.json")
mixinConfig("flywheel.impl.mixins.json")
mixinConfig("flywheel.impl.sodium.mixins.json")
}

runs {
Expand All @@ -84,7 +83,7 @@ loom {
dependencies {
forge("net.minecraftforge:forge:${property("minecraft_version")}-${property("forge_version")}")

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

modCompileOnly("maven.modrinth:oculus:${property("oculus_version")}")

"forApi"(project(path = ":common", configuration = "commonApiOnly"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package dev.engine_room.flywheel.impl;

import java.util.function.BooleanSupplier;

import dev.engine_room.flywheel.api.event.ReloadLevelRendererEvent;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.loading.LoadingModList;

public class FlwImplXplatImpl implements FlwImplXplat {
@Override
Expand All @@ -19,4 +22,9 @@ public String getVersionStr() {
public FlwConfig getConfig() {
return ForgeFlwConfig.INSTANCE;
}

@Override
public BooleanSupplier getModLoaded(String modId) {
return () -> LoadingModList.get().getModFileById(modId) != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.UnknownNullability;

import dev.engine_room.flywheel.impl.compat.CompatMods;
import dev.engine_room.flywheel.lib.internal.FlwLibXplat;
import dev.engine_room.flywheel.lib.model.baked.BakedModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.BlockModelBuilder;
Expand All @@ -23,7 +24,6 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;

public class FlwLibXplatImpl implements FlwLibXplat {
Expand Down Expand Up @@ -68,8 +68,7 @@ public MultiBlockModelBuilder createMultiBlockModelBuilder(BlockAndTintGetter le
@Override
@Nullable
public ShadersModHandler.InternalHandler createIrisHandler() {
if (!ModList.get()
.isLoaded("oculus")) {
if (!(CompatMods.IRIS.isLoaded() || CompatMods.OCULUS.isLoaded())) {
return null;
}

Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit dd80ea4

Please sign in to comment.