Skip to content

Commit

Permalink
Add PlatformHooks
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Aug 5, 2024
1 parent aa114b2 commit 15bccbc
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ca.spottedleaf.moonrise.fabric;

import ca.spottedleaf.moonrise.common.PlatformHooks;

public final class FabricHooks implements PlatformHooks {
@Override
public void doSomePlatformAction() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ca.spottedleaf.moonrise.fabric.FabricHooks
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ca.spottedleaf.moonrise.neoforge;

import ca.spottedleaf.moonrise.common.PlatformHooks;

public final class NeoForgeHooks implements PlatformHooks {
@Override
public void doSomePlatformAction() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ca.spottedleaf.moonrise.neoforge.NeoForgeHooks
24 changes: 24 additions & 0 deletions src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ca.spottedleaf.moonrise.common;

import java.util.ServiceLoader;

// TODO - placeholder for if we need platform-specific impls for logic that needs to be called from common
public interface PlatformHooks {
static PlatformHooks get() {
return Holder.INSTANCE;
}

void doSomePlatformAction();

final class Holder {
private Holder() {
}

private static final PlatformHooks INSTANCE;

static {
INSTANCE = ServiceLoader.load(PlatformHooks.class, PlatformHooks.class.getClassLoader()).findFirst()
.orElseThrow(() -> new RuntimeException("Failed to locate PlatformHooks"));
}
}
}

0 comments on commit 15bccbc

Please sign in to comment.