Skip to content

Commit

Permalink
Fix bug of unable to loading chunk when sepals with moonrise.
Browse files Browse the repository at this point in the history
Fix configuration key wrongs.
  • Loading branch information
cao-awa committed Nov 16, 2024
1 parent 0fee077 commit 83f89ca
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.16.7

# Mod Properties
mod_version = 1.0.5
mod_version = 1.0.6
maven_group = com.github.cao.awa.sepals
archives_base_name = sepals

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/github/cao/awa/sepals/Sepals.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

public class Sepals implements ModInitializer {
public static final Logger LOGGER = LogManager.getLogger("Sepals");
public static final String VERSION = "1.0.5";
public static final String VERSION = "1.0.6";
public static final SepalsConfig CONFIG = new SepalsConfig();
public static final SepalsConfig PERSISTENT_CONFIG = new SepalsConfig();
public static boolean isLithiumLoaded;
public static boolean isMoonriseLoaded;

@Override
public void onInitialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

public class SepalsModCompatibles {
public static final String LITHIUM_MOD_NAME = "lithium";
public static final String MOONRISE_MOD_NAME = "moonrise";
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SepalsConfig {
val CONFIG_FILE: File = File("config/sepals.json")

@JvmField
val FORCE_ENABLE_SEPALS_POI = SepalsConfigKey.create("forceEnableSepalsPoi", true)
val FORCE_ENABLE_SEPALS_POI = SepalsConfigKey.create("forceEnableSepalsPoi", false)

@JvmField
val ENABLE_SEPALS_VILLAGER = SepalsConfigKey.create("enableSepalsVillager", true)
Expand Down Expand Up @@ -47,7 +47,7 @@ class SepalsConfig {
private val config = JSONObject()

val isForceEnableSepalsPoi: Boolean get() = getConfig(FORCE_ENABLE_SEPALS_POI)
val isEnableSepalsVillager: Boolean get() = getConfig(FORCE_ENABLE_SEPALS_POI)
val isEnableSepalsVillager: Boolean get() = getConfig(ENABLE_SEPALS_VILLAGER)
val isEnableSepalsFrogLookAt: Boolean get() = getConfig(ENABLE_SEPALS_FROG_LOOK_AT)
val isEnableSepalsFrogAttackableSensor: Boolean get() = getConfig(ENABLE_SEPALS_FROG_ATTACKABLE_SENSOR)
val isEnableSepalsLivingTargetCache: Boolean get() = getConfig(ENABLE_SEPALS_LIVING_TARGET_CACHE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.cao.awa.sepals.mixin.world.storage;

import com.github.cao.awa.sepals.Sepals;
import com.github.cao.awa.sepals.world.poi.SepalsPointOfInterestStorage;
import com.mojang.datafixers.util.Pair;
import net.minecraft.registry.entry.RegistryEntry;
Expand Down Expand Up @@ -59,7 +60,7 @@ public void getInChunk(
PointOfInterestStorage.OccupationStatus occupationStatus,
CallbackInfoReturnable<Stream<PointOfInterest>> cir
) {
if (!SepalsPointOfInterestStorage.isLithiumLoaded()) {
if (!Sepals.isLithiumLoaded && !Sepals.isMoonriseLoaded) {
cir.setReturnValue(
SepalsPointOfInterestStorage.getInChunk(
instance(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,19 @@ public void postProcess(Map<String, ModContainer> mods, String mixinGroup, Strin
switch (mixinName) {
case "region_based_storage" -> {
boolean isLithiumLoaded = mods.containsKey(SepalsModCompatibles.LITHIUM_MOD_NAME);
boolean isMoonriseLoaded = mods.containsKey(SepalsModCompatibles.MOONRISE_MOD_NAME);

if (isLithiumLoaded) {
LOGGER.info("Lithium is loaded, auto-disabling sepals mixin: {}({})", "region_based_storage", mixinClassName);

SepalsPointOfInterestStorage.onLithiumLoaded();
}

if (isMoonriseLoaded) {
LOGGER.info("Moonrise is loaded, sepals won't intervention chunk loading in 'getInChunk' of POI");

SepalsPointOfInterestStorage.onMoonriseLoaded();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.cao.awa.sepals.world.poi;

import com.github.cao.awa.catheter.Catheter;
import com.github.cao.awa.sepals.Sepals;
import com.github.cao.awa.sepals.mixin.world.poi.*;
import com.github.cao.awa.sepals.mixin.world.storage.SerializingRegionBasedStorageAccessor;
import com.mojang.datafixers.util.Function4;
Expand Down Expand Up @@ -38,19 +39,25 @@ public class SepalsPointOfInterestStorage {
> getInChunkFunction = (storage, typePredicate, chunkPos, occupationStatus) -> ((RegionBasedStorageSectionExtended<PointOfInterestSet>) storage)
.sepals$getWithinChunkColumn(chunkPos.x, chunkPos.z)
.flatTo(set -> get(set, typePredicate, occupationStatus));
private static boolean lithiumLoaded = false;

public static void onLithiumLoaded() {
onRequiredVanillaGetInChunk();

Sepals.isLithiumLoaded = true;
}

public static void onMoonriseLoaded() {
onRequiredVanillaGetInChunk();

Sepals.isMoonriseLoaded = true;
}

public static void onRequiredVanillaGetInChunk() {
getInChunkFunction = (storage, typePredicate, chunkPos, occupationStatus) -> Catheter.of(storage.getInChunk(
typePredicate,
chunkPos,
occupationStatus
).toArray(PointOfInterest[]::new));
lithiumLoaded = true;
}

public static boolean isLithiumLoaded() {
return lithiumLoaded;
}

public static Catheter<PointOfInterest> getInSquare(
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
],
"depends": {
"fabricloader": "*",
"fabric": "*",
"fabric-language-kotlin": "*",
"minecraft": "1.21.x"
},
"suggests": {
"fabric": "*"
}
}

0 comments on commit 83f89ca

Please sign in to comment.