From 15bccbc82c7c2bc3becada6fe06e2c3f5481c483 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Sun, 4 Aug 2024 20:23:33 -0700 Subject: [PATCH] Add PlatformHooks --- .../moonrise/fabric/FabricHooks.java | 10 ++++++++ ....spottedleaf.moonrise.common.PlatformHooks | 1 + .../moonrise/neoforge/NeoForgeHooks.java | 10 ++++++++ ....spottedleaf.moonrise.common.PlatformHooks | 1 + .../moonrise/common/PlatformHooks.java | 24 +++++++++++++++++++ 5 files changed, 46 insertions(+) create mode 100644 fabric/src/main/java/ca/spottedleaf/moonrise/fabric/FabricHooks.java create mode 100644 fabric/src/main/resources/META-INF/services/ca.spottedleaf.moonrise.common.PlatformHooks create mode 100644 neoforge/src/main/java/ca/spottedleaf/moonrise/neoforge/NeoForgeHooks.java create mode 100644 neoforge/src/main/resources/META-INF/services/ca.spottedleaf.moonrise.common.PlatformHooks create mode 100644 src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java diff --git a/fabric/src/main/java/ca/spottedleaf/moonrise/fabric/FabricHooks.java b/fabric/src/main/java/ca/spottedleaf/moonrise/fabric/FabricHooks.java new file mode 100644 index 00000000..4479c46a --- /dev/null +++ b/fabric/src/main/java/ca/spottedleaf/moonrise/fabric/FabricHooks.java @@ -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() { + + } +} diff --git a/fabric/src/main/resources/META-INF/services/ca.spottedleaf.moonrise.common.PlatformHooks b/fabric/src/main/resources/META-INF/services/ca.spottedleaf.moonrise.common.PlatformHooks new file mode 100644 index 00000000..8d1ae1e1 --- /dev/null +++ b/fabric/src/main/resources/META-INF/services/ca.spottedleaf.moonrise.common.PlatformHooks @@ -0,0 +1 @@ +ca.spottedleaf.moonrise.fabric.FabricHooks diff --git a/neoforge/src/main/java/ca/spottedleaf/moonrise/neoforge/NeoForgeHooks.java b/neoforge/src/main/java/ca/spottedleaf/moonrise/neoforge/NeoForgeHooks.java new file mode 100644 index 00000000..de3cf7a3 --- /dev/null +++ b/neoforge/src/main/java/ca/spottedleaf/moonrise/neoforge/NeoForgeHooks.java @@ -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() { + + } +} diff --git a/neoforge/src/main/resources/META-INF/services/ca.spottedleaf.moonrise.common.PlatformHooks b/neoforge/src/main/resources/META-INF/services/ca.spottedleaf.moonrise.common.PlatformHooks new file mode 100644 index 00000000..2960270e --- /dev/null +++ b/neoforge/src/main/resources/META-INF/services/ca.spottedleaf.moonrise.common.PlatformHooks @@ -0,0 +1 @@ +ca.spottedleaf.moonrise.neoforge.NeoForgeHooks diff --git a/src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java b/src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java new file mode 100644 index 00000000..b3922d36 --- /dev/null +++ b/src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java @@ -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")); + } + } +}