Skip to content

Commit

Permalink
why is compareTo so confusing
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysdh540 committed Feb 10, 2024
1 parent 9b53260 commit 55fdbc3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

@NoBootstrap
public enum SupportedMinecraftVersion {
v1_18_2,
v1_19_2,
v1_20_1,

;

public static final SupportedMinecraftVersion CURRENT = current();
Expand All @@ -28,16 +28,4 @@ private static SupportedMinecraftVersion current() {
public String toString() {
return name().substring(1).replace('_', '.');
}

public boolean isCurrent() {
return this == CURRENT;
}

public boolean isCurrentOrNewer() {
return this.ordinal() <= CURRENT.ordinal();
}

public boolean isCurrentOrOlder() {
return this.ordinal() >= CURRENT.ordinal();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import dev.rdh.createunlimited.CreateUnlimited;

import dev.rdh.createunlimited.config.CUConfigs;
import dev.rdh.createunlimited.multiversion.SupportedMinecraftVersion;

import manifold.rt.api.NoBootstrap;
import net.fabricmc.api.ModInitializer;
Expand All @@ -15,6 +14,8 @@
import java.lang.reflect.Proxy;
import java.util.function.Consumer;

import static dev.rdh.createunlimited.multiversion.SupportedMinecraftVersion.*;

@NoBootstrap
public class CreateUnlimitedFabric implements ModInitializer {
@Override
Expand Down Expand Up @@ -75,12 +76,12 @@ private static Class<?> findNestedClass(Class<?> outerClass, String nestedClassN

private static Class<?> getModConfigEventsClass() {
try {
if(SupportedMinecraftVersion.v1_19_2.isCurrentOrOlder()) {
if(v1_19_2 >= CURRENT) {
return Class.forName("net.minecraftforge.api.fml.event.config.ModConfigEvents");
} else if(SupportedMinecraftVersion.v1_20_1.isCurrentOrNewer()) {
} else if(v1_20_1 <= CURRENT) {
return Class.forName("fuzs.forgeconfigapiport.api.config.v2.ModConfigEvents");
} else {
throw new IllegalStateException("Unsupported Minecraft version: " + SupportedMinecraftVersion.CURRENT);
throw new IllegalStateException("Unsupported Minecraft version: " + CURRENT);
}
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.mojang.brigadier.builder.LiteralArgumentBuilder;

import dev.rdh.createunlimited.CreateUnlimited;
import dev.rdh.createunlimited.multiversion.SupportedMinecraftVersion;

import manifold.rt.api.NoBootstrap;
import net.fabricmc.fabric.api.command.v2.ArgumentTypeRegistry;
Expand All @@ -30,6 +29,8 @@
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

import static dev.rdh.createunlimited.multiversion.SupportedMinecraftVersion.*;

@NoBootstrap
public class UtilImpl {

Expand All @@ -44,13 +45,13 @@ public static void registerCommand(LiteralArgumentBuilder<CommandSourceStack> co
private static void setupConfigRegistry() {
MethodHandles.Lookup lookup = MethodHandles.lookup();
try {
if(SupportedMinecraftVersion.v1_19_2.isCurrentOrOlder()) {
if(v1_19_2 >= CURRENT) {
Class<?> modLoadingContextClass = Class.forName("net.minecraftforge.api.ModLoadingContext");
modLoadingContextRegisterConfig = lookup.findStatic(modLoadingContextClass, "registerConfig",
MethodType.methodType(ModConfig.class, String.class, Type.class, IConfigSpec.class));
}

if(SupportedMinecraftVersion.v1_20_1.isCurrentOrNewer()) {
if(v1_20_1 <= CURRENT) {
Class<?> forgeConfigRegistryClass = Class.forName("fuzs.forgeconfigapiport.api.config.v2.ForgeConfigRegistry");
forgeConfigRegistryRegister = lookup.findVirtual(forgeConfigRegistryClass, "register",
MethodType.methodType(ModConfig.class, String.class, Type.class, IConfigSpec.class));
Expand All @@ -61,16 +62,17 @@ private static void setupConfigRegistry() {
}
}

@SuppressWarnings("DataFlowIssue")
public static void registerConfig(ModConfig.Type type, IConfigSpec<?> spec) {
if(modLoadingContextRegisterConfig == null && forgeConfigRegistryRegister == null) {
setupConfigRegistry();
}
try {
if(SupportedMinecraftVersion.v1_19_2.isCurrentOrOlder()) {
if(v1_19_2 >= CURRENT) {
ModConfig ignore = (ModConfig) modLoadingContextRegisterConfig.invokeExact(CreateUnlimited.ID, type, spec);
}

if(SupportedMinecraftVersion.v1_20_1.isCurrentOrNewer()) {
if(v1_20_1 <= CURRENT) {
//cannot use invokeExact because the instance class only exists in 1.20.1
forgeConfigRegistryRegister.invoke(forgeConfigRegistryInstance, CreateUnlimited.ID, type, spec);
}
Expand Down
2 changes: 2 additions & 0 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ dependencies {
modImplementation "com.tterrag.registrate:Registrate:${registrate}"
modImplementation "com.jozufozu.flywheel:flywheel-forge-${flywheel_mc}:${flywheel}"

forgeRuntimeLibrary("io.github.llamalad7:mixinextras-common:${rootProject.mixin_extras}")

// Dev Env Optimizations
if (rootProject.hasProperty("bmb")) {
modRuntimeOnly "curse.maven:better-mods-button-541584:${rootProject.bmb}"
Expand Down
11 changes: 6 additions & 5 deletions forge/src/main/java/dev/rdh/createunlimited/forge/UtilImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.mojang.brigadier.builder.LiteralArgumentBuilder;

import dev.rdh.createunlimited.CreateUnlimited;
import dev.rdh.createunlimited.multiversion.SupportedMinecraftVersion;

import net.minecraft.commands.CommandSourceStack;

Expand All @@ -31,6 +30,8 @@

import manifold.rt.api.NoBootstrap;

import static dev.rdh.createunlimited.multiversion.SupportedMinecraftVersion.*;

@NoBootstrap
@SuppressWarnings({"UnstableApiUsage", "RedundantSuppression"})
public class UtilImpl {
Expand Down Expand Up @@ -75,14 +76,14 @@ public static boolean isDevEnv() {
@SuppressWarnings({"unchecked", "JavaReflectionMemberAccess"})
private static RegistryObject<Attribute> makeReachAttribute() {
try {
if(SupportedMinecraftVersion.v1_20_1.isCurrentOrNewer()) {
if(v1_20_1 <= CURRENT) {
return (RegistryObject<Attribute>) ForgeMod.class.getField("BLOCK_REACH").get(null);
} else if(SupportedMinecraftVersion.v1_19_2.isCurrentOrOlder()) {
} else if(v1_19_2 <= CURRENT) {
return (RegistryObject<Attribute>) ForgeMod.class.getField("REACH_DISTANCE").get(null);
}
throw new IllegalStateException("Unsupported minecraft version: " + SupportedMinecraftVersion.CURRENT);
throw new IllegalStateException("Unsupported minecraft version: " + CURRENT);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException("Failed to get reach attribute for minecraft version " + SupportedMinecraftVersion.CURRENT, e);
throw new RuntimeException("Failed to get reach attribute for minecraft version " + CURRENT, e);
}
}

Expand Down
3 changes: 2 additions & 1 deletion gradle/subprojects.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ dependencies {
})

annotationProcessor(compileOnly("systems.manifold:manifold-props:${manifold_version}"))
annotationProcessor(compileOnly("systems.manifold:manifold-ext:${manifold_version}"))

def me = "io.github.llamalad7:mixinextras-common:${rootProject.mixin_extras}"
annotationProcessor(implementation(me))
if (project.name != 'common') {
if(project != project(':common')) {
shade(me)
}
}
Expand Down

0 comments on commit 55fdbc3

Please sign in to comment.