Skip to content

Commit

Permalink
Fix #124
Browse files Browse the repository at this point in the history
  • Loading branch information
hlysine committed Jul 27, 2024
1 parent 760a33a commit fe06802
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.copycatsplus.copycats.foundation.copycat.model.fabric;

import com.copycatsplus.copycats.Copycats;
import com.copycatsplus.copycats.compat.Mods;
import com.copycatsplus.copycats.compat.fabric.IndiumMutableQuadView;
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
Expand All @@ -8,6 +9,8 @@
import org.apache.commons.lang3.NotImplementedException;
import org.jetbrains.annotations.ApiStatus;

import java.util.concurrent.atomic.AtomicBoolean;

@SuppressWarnings("UnstableApiUsage")
@ApiStatus.Internal
public class IntermediateMutableQuadView extends MutableQuadViewImpl {
Expand All @@ -21,7 +24,27 @@ public void emitDirectly() {
throw new NotImplementedException("IntermediateMutableQuadView.emitDirectly() is not implemented");
}

/**
* Embeddium registers a stub for Indium but does not provide Indium classes,
* so classes need to be checked for existence at runtime.
*/
private static final AtomicBoolean indiumAvailable = new AtomicBoolean(true);

public static MutableQuadView create() {
return Mods.INDIUM.<MutableQuadView>runIfInstalled(() -> IndiumMutableQuadView::new).orElseGet(IntermediateMutableQuadView::new);
if (!indiumAvailable.get()) {
return new IntermediateMutableQuadView();
}
return Mods.INDIUM.<MutableQuadView>runIfInstalled(() -> {
try {
IndiumMutableQuadView instance = new IndiumMutableQuadView();
return () -> instance;
} catch (NoClassDefFoundError t) {
if (indiumAvailable.compareAndSet(true, false)) {
Copycats.LOGGER.warn("Failed to load Indium classes, falling back to Fabric API");
t.printStackTrace();
}
return IntermediateMutableQuadView::new;
}
}).orElseGet(IntermediateMutableQuadView::new);
}
}

0 comments on commit fe06802

Please sign in to comment.