mirror of
https://github.com/AlmostReliable/almostunified.git
synced 2024-11-14 19:25:13 -05:00
move service related code to platform
This commit is contained in:
parent
e5843fa7d9
commit
a784c3055e
7 changed files with 26 additions and 47 deletions
|
@ -6,11 +6,12 @@ import net.minecraft.world.item.Item;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.ServiceLoader;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface AlmostUnifiedPlatform {
|
public interface AlmostUnifiedPlatform {
|
||||||
|
|
||||||
AlmostUnifiedPlatform INSTANCE = PlatformLoader.load(AlmostUnifiedPlatform.class);
|
AlmostUnifiedPlatform INSTANCE = load(AlmostUnifiedPlatform.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current platform
|
* Gets the current platform
|
||||||
|
@ -27,13 +28,6 @@ public interface AlmostUnifiedPlatform {
|
||||||
*/
|
*/
|
||||||
boolean isModLoaded(String modId);
|
boolean isModLoaded(String modId);
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the game is currently in a development environment.
|
|
||||||
*
|
|
||||||
* @return True if in a development environment, false otherwise.
|
|
||||||
*/
|
|
||||||
boolean isDevelopmentEnvironment();
|
|
||||||
|
|
||||||
boolean isClient();
|
boolean isClient();
|
||||||
|
|
||||||
Path getConfigPath();
|
Path getConfigPath();
|
||||||
|
@ -43,4 +37,17 @@ public interface AlmostUnifiedPlatform {
|
||||||
void bindRecipeHandlers(RecipeHandlerFactory factory);
|
void bindRecipeHandlers(RecipeHandlerFactory factory);
|
||||||
|
|
||||||
Set<UnifyTag<Item>> getStoneStrataTags(List<String> stoneStrataIds);
|
Set<UnifyTag<Item>> getStoneStrataTags(List<String> stoneStrataIds);
|
||||||
|
|
||||||
|
static <T> T load(Class<T> clazz) {
|
||||||
|
T loadedService = ServiceLoader.load(clazz)
|
||||||
|
.findFirst()
|
||||||
|
.orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName()));
|
||||||
|
AlmostUnified.LOG.debug("Loaded {} for service {}", loadedService, clazz);
|
||||||
|
return loadedService;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Platform {
|
||||||
|
FORGE,
|
||||||
|
FABRIC;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
package com.almostreliable.unified;
|
|
||||||
|
|
||||||
public enum Platform {
|
|
||||||
FORGE,
|
|
||||||
FABRIC
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
package com.almostreliable.unified;
|
|
||||||
|
|
||||||
import java.util.ServiceLoader;
|
|
||||||
|
|
||||||
@SuppressWarnings("UtilityClassWithoutPrivateConstructor")
|
|
||||||
public final class PlatformLoader {
|
|
||||||
static <T> T load(Class<T> clazz) {
|
|
||||||
final T loadedService = ServiceLoader.load(clazz)
|
|
||||||
.findFirst()
|
|
||||||
.orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName()));
|
|
||||||
AlmostUnified.LOG.debug("Loaded {} for service {}", loadedService, clazz);
|
|
||||||
return loadedService;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.almostreliable.unified.config;
|
package com.almostreliable.unified.config;
|
||||||
|
|
||||||
import com.almostreliable.unified.Platform;
|
import com.almostreliable.unified.AlmostUnifiedPlatform;
|
||||||
import com.almostreliable.unified.utils.JsonCompare;
|
import com.almostreliable.unified.utils.JsonCompare;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ public final class Defaults {
|
||||||
|
|
||||||
private Defaults() {}
|
private Defaults() {}
|
||||||
|
|
||||||
public static List<String> getModPriorities(Platform platform) {
|
public static List<String> getModPriorities(AlmostUnifiedPlatform.Platform platform) {
|
||||||
return switch (platform) {
|
return switch (platform) {
|
||||||
case FORGE -> List.of(
|
case FORGE -> List.of(
|
||||||
"minecraft",
|
"minecraft",
|
||||||
|
@ -93,7 +93,7 @@ public final class Defaults {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getTags(Platform platform) {
|
public static List<String> getTags(AlmostUnifiedPlatform.Platform platform) {
|
||||||
return switch (platform) {
|
return switch (platform) {
|
||||||
case FORGE -> List.of(
|
case FORGE -> List.of(
|
||||||
"forge:nuggets/{material}",
|
"forge:nuggets/{material}",
|
||||||
|
@ -129,13 +129,13 @@ public final class Defaults {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getIgnoredRecipeTypes(Platform platform) {
|
public static List<String> getIgnoredRecipeTypes(AlmostUnifiedPlatform.Platform platform) {
|
||||||
return switch (platform) {
|
return switch (platform) {
|
||||||
default -> List.of("cucumber:shaped_tag");
|
default -> List.of("cucumber:shaped_tag");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonCompare.CompareSettings getDefaultDuplicateRules(Platform platform) {
|
public static JsonCompare.CompareSettings getDefaultDuplicateRules(AlmostUnifiedPlatform.Platform platform) {
|
||||||
JsonCompare.CompareSettings result = new JsonCompare.CompareSettings();
|
JsonCompare.CompareSettings result = new JsonCompare.CompareSettings();
|
||||||
result.ignoreField(switch (platform) {
|
result.ignoreField(switch (platform) {
|
||||||
case FORGE -> "conditions";
|
case FORGE -> "conditions";
|
||||||
|
@ -148,7 +148,7 @@ public final class Defaults {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LinkedHashMap<ResourceLocation, JsonCompare.CompareSettings> getDefaultDuplicateOverrides(Platform platform) {
|
public static LinkedHashMap<ResourceLocation, JsonCompare.CompareSettings> getDefaultDuplicateOverrides(AlmostUnifiedPlatform.Platform platform) {
|
||||||
JsonCompare.CompareSettings result = new JsonCompare.CompareSettings();
|
JsonCompare.CompareSettings result = new JsonCompare.CompareSettings();
|
||||||
result.ignoreField(switch (platform) {
|
result.ignoreField(switch (platform) {
|
||||||
case FORGE -> "conditions";
|
case FORGE -> "conditions";
|
||||||
|
|
|
@ -38,7 +38,7 @@ public final class TestUtils {
|
||||||
public static final UnifyConfig DEFAULT_UNIFY_CONFIG = new UnifyConfig(
|
public static final UnifyConfig DEFAULT_UNIFY_CONFIG = new UnifyConfig(
|
||||||
Defaults.STONE_STRATA,
|
Defaults.STONE_STRATA,
|
||||||
Defaults.MATERIALS,
|
Defaults.MATERIALS,
|
||||||
Defaults.getTags(Platform.FORGE),
|
Defaults.getTags(AlmostUnifiedPlatform.Platform.FORGE),
|
||||||
TEST_MOD_PRIORITIES,
|
TEST_MOD_PRIORITIES,
|
||||||
new HashMap<>(),
|
new HashMap<>(),
|
||||||
new HashMap<>(),
|
new HashMap<>(),
|
||||||
|
@ -55,11 +55,13 @@ public final class TestUtils {
|
||||||
private TestUtils() {}
|
private TestUtils() {}
|
||||||
|
|
||||||
public static JsonCompare.CompareSettings getDefaultCompareSettings() {
|
public static JsonCompare.CompareSettings getDefaultCompareSettings() {
|
||||||
return Defaults.getDefaultDuplicateRules(Platform.FORGE);
|
return Defaults.getDefaultDuplicateRules(AlmostUnifiedPlatform.Platform.FORGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonCompare.CompareSettings getDefaultShapedCompareSettings() {
|
public static JsonCompare.CompareSettings getDefaultShapedCompareSettings() {
|
||||||
return Defaults.getDefaultDuplicateOverrides(Platform.FORGE).get(new ResourceLocation("crafting_shaped"));
|
return Defaults
|
||||||
|
.getDefaultDuplicateOverrides(AlmostUnifiedPlatform.Platform.FORGE)
|
||||||
|
.get(new ResourceLocation("crafting_shaped"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final ResourceKey<Registry<Item>> FAKE_ITEM_REGISTRY = FakeResourceKeyRegistry.create("item");
|
public static final ResourceKey<Registry<Item>> FAKE_ITEM_REGISTRY = FakeResourceKeyRegistry.create("item");
|
||||||
|
|
|
@ -28,11 +28,6 @@ public class AlmostUnifiedPlatformFabric implements AlmostUnifiedPlatform {
|
||||||
return FabricLoader.getInstance().isModLoaded(modId);
|
return FabricLoader.getInstance().isModLoaded(modId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDevelopmentEnvironment() {
|
|
||||||
return FabricLoader.getInstance().isDevelopmentEnvironment();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isClient() {
|
public boolean isClient() {
|
||||||
return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT;
|
return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT;
|
||||||
|
|
|
@ -38,11 +38,6 @@ public class AlmostUnifiedPlatformForge implements AlmostUnifiedPlatform {
|
||||||
return ModList.get().isLoaded(modId);
|
return ModList.get().isLoaded(modId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDevelopmentEnvironment() {
|
|
||||||
return !FMLLoader.isProduction();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isClient() {
|
public boolean isClient() {
|
||||||
return FMLLoader.getDist() == Dist.CLIENT;
|
return FMLLoader.getDist() == Dist.CLIENT;
|
||||||
|
|
Loading…
Reference in a new issue