Skip to content

Commit

Permalink
Fix compatibility with new beta Lithium 0.14.x. Old releases of lithi…
Browse files Browse the repository at this point in the history
…um should work as is
  • Loading branch information
Patbox committed Oct 31, 2024
1 parent df0e2ae commit 84c2050
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fabric_version=0.102.1+1.21.1

maven_group = eu.pb4

mod_version = 0.9.17
mod_version = 0.9.18

minecraft_version_supported = ">=1.21-"

Expand Down
Binary file added jardeps/lithium-fabric-0.14.0-1.21.1-patched.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public static boolean shouldApplyMixin(String source, String mixinClassName, boo
case "rei" -> CompatStatus.REI;
case "emi" -> CompatStatus.EMI;
case "lithium" -> CompatStatus.LITHIUM;
case "lithium14" -> CompatStatus.LITHIUM_14;
case "jei" -> CompatStatus.JEI;
case "armor" -> CompatStatus.REQUIRE_ALT_ARMOR_HANDLER || armor;
case "ip" -> CompatStatus.IMMERSIVE_PORTALS;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package eu.pb4.polymer.common.impl;

import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.Version;
import net.fabricmc.loader.api.VersionParsingException;
import org.jetbrains.annotations.ApiStatus;

@ApiStatus.Internal
Expand Down Expand Up @@ -32,7 +34,10 @@ public final class CompatStatus {

public static final boolean POLYMC = LOADER.isModLoaded("polymc");
public static final boolean DISGUISELIB = LOADER.isModLoaded("disguiselib");
public static final boolean LITHIUM = LOADER.isModLoaded("lithium");

public static final boolean LITHIUM_14 = isModLoaded("lithium", "0.14.0-", "9.999.0");
public static final boolean LITHIUM = isModLoaded("lithium", "0.0.0", "0.14.0-");

public static final boolean WTHIT = LOADER.isModLoaded("wthit");
public static final boolean JADE = LOADER.isModLoaded("jade");
public static final boolean REI = LOADER.isModLoaded("roughlyenoughitems");
Expand All @@ -58,4 +63,21 @@ public final class CompatStatus {

public static final boolean IMMERSIVE_PORTALS = LOADER.isModLoaded("imm_ptl_core");

private static boolean isModLoaded(String modId, String minVersionInclusive, String maxVersionExclusive) {
var mod = LOADER.getModContainer(modId);

if (mod.isPresent()) {try {
return mod.get().getMetadata().getVersion().compareTo(Version.parse(minVersionInclusive)) >= 0
&& mod.get().getMetadata().getVersion().compareTo(Version.parse(maxVersionExclusive)) < 0;
} catch (VersionParsingException e) {
throw new RuntimeException(e);
}

}

return false;


}

}
1 change: 1 addition & 0 deletions polymer-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencies {
//modRuntime "supercoder79:databreaker:0.2.7"

modCompileOnly('maven.modrinth:lithium:mc1.21-0.12.7')
modCompileOnly(files("../jardeps/lithium-fabric-0.14.0-1.21.1-patched.jar"))

//modCompileOnly ('nl.theepicblock:PolyMc:5.1.0+1.19')
modCompileOnly('com.github.TheEpicBlock:PolyMc:5.6.1') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package eu.pb4.polymer.core.mixin.compat;

import eu.pb4.polymer.core.api.block.PolymerBlockUtils;
import eu.pb4.polymer.core.api.utils.PolymerUtils;
import eu.pb4.polymer.core.impl.client.InternalClientRegistry;
import net.caffeinemc.mods.lithium.common.world.chunk.LithiumHashPalette;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.BlockState;
import net.minecraft.util.collection.IndexedIterable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;

@Pseudo
@Mixin(value = LithiumHashPalette.class, priority = 500)
public class lithium14_BlockPaletteMixin {
@ModifyArg(method = {"writePacket", "getPacketSize" }, at = @At(value = "INVOKE", target = "Lnet/minecraft/util/collection/IndexedIterable;getRawId(Ljava/lang/Object;)I"))
public Object polymer$getIdRedirect(Object object) {
if (object instanceof BlockState blockState) {
return PolymerBlockUtils.getPolymerBlockState(blockState, PolymerUtils.getPlayerContext());
}
return object;
}

@Environment(EnvType.CLIENT)
@Redirect(method = "readPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/collection/IndexedIterable;get(I)Ljava/lang/Object;"), require = 0)
private Object polymer$replaceState(IndexedIterable<?> instance, int index) {
return InternalClientRegistry.decodeRegistry(instance, index);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;

Expand Down
1 change: 1 addition & 0 deletions polymer-core/src/main/resources/polymer-core.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"block.storage.WorldChunkMixin",
"command.ArgumentNodeMixin",
"command.CommandManagerMixin",
"compat.lithium14_BlockPaletteMixin",
"compat.lithium_BlockPaletteMixin",
"compat.fabric.fabricSync_StateIdTrackerMixin",
"compat.immersive_portals.ip_PlayerChunkLoadingMixin",
Expand Down

0 comments on commit 84c2050

Please sign in to comment.