Skip to content

Commit

Permalink
Fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
superhize committed Feb 14, 2024
1 parent 257c538 commit 4c9a7db
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 52 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ tasks.shadowJar {
// If you want to include other dependencies and shadow them, you can relocate them in here
relocate("io.github.moulberry.moulconfig", "$baseGroup.deps.moulconfig")
relocate("moe.nea.libautoupdate", "$baseGroup.deps.libautoupdate")
mergeServiceFiles()
}

tasks.jar {
Expand Down
2 changes: 2 additions & 0 deletions do-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ git commit -m "Bump version"
git tag "$newversion"
git push origin main "$newversion"
./gradlew publishAllPublicationsToHizeRepository

pause
24 changes: 12 additions & 12 deletions src/main/kotlin/be/hize/onlyfarm/OnlyFarmMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,24 @@ internal class OnlyFarmMod {

@Mod.EventHandler
fun preInit(event: FMLPreInitializationEvent) {

}

@Mod.EventHandler
fun init(event: FMLInitializationEvent) {
configManager = ConfigManager()
configManager.firstLoad()
Runtime.getRuntime().addShutdownHook(Thread { configManager.saveConfig(ConfigFileType.FEATURES, "shutdown-hook") })
loadModule(this)

loadModule(MinecraftData())
loadModule(HypixelUtils)
loadModule(ScoreboardData)
loadModule(AutoUpdate)

loadModule(ButtonOnPause())

Commands.init()
}

@Mod.EventHandler
fun init(event: FMLInitializationEvent) {
configManager = ConfigManager()
configManager.firstLoad()
Runtime.getRuntime().addShutdownHook(Thread { configManager.saveConfig(ConfigFileType.FEATURES, "shutdown-hook") })

loadModule(AutoUpdate)
}

private fun loadModule(obj: Any) {
Expand All @@ -73,16 +72,17 @@ internal class OnlyFarmMod {
}

companion object {
@JvmStatic
val feature: Features get() = configManager.features
lateinit var configManager: ConfigManager
const val MOD_ID = "onlyfarm"

@JvmStatic
val version: String
get() = Loader.instance().indexedModList[MOD_ID]!!.version

@JvmStatic
val feature: Features get() = configManager.features
lateinit var configManager: ConfigManager
val modules: MutableList<Any> = ArrayList()

private val globalJob: Job = Job(null)
val coroutineScope = CoroutineScope(
CoroutineName("OnlyFarm") + SupervisorJob(globalJob)
Expand Down
43 changes: 11 additions & 32 deletions src/main/kotlin/be/hize/onlyfarm/config/ConfigManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,14 @@ package be.hize.onlyfarm.config
import be.hize.onlyfarm.OnlyFarmMod
import be.hize.onlyfarm.utils.KotlinTypeAdapterFactory
import be.hize.onlyfarm.utils.Logger
import be.hize.onlyfarm.utils.SimpleTimeMark
import be.hize.onlyfarm.utils.SimpleTimeMark.Companion.asTimeMark
import be.hize.onlyfarm.utils.Utils
import be.hize.onlyfarm.utils.Utils.shutdownMinecraft
import com.google.gson.GsonBuilder
import com.google.gson.JsonObject
import com.google.gson.TypeAdapter
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonWriter
import io.github.moulberry.moulconfig.observer.PropertyTypeAdapterFactory
import io.github.moulberry.moulconfig.processor.BuiltinMoulConfigGuis
import io.github.moulberry.moulconfig.processor.ConfigProcessorDriver
import io.github.moulberry.moulconfig.processor.MoulConfigProcessor
import net.minecraft.item.ItemStack
import net.minecraft.launchwrapper.Launch
import java.io.*
import java.nio.charset.StandardCharsets
import java.nio.file.Files
Expand All @@ -31,24 +25,6 @@ class ConfigManager {
.serializeSpecialFloatingPointValues()
.registerTypeAdapterFactory(PropertyTypeAdapterFactory())
.registerTypeAdapterFactory(KotlinTypeAdapterFactory())
.registerTypeAdapter(UUID::class.java, object : TypeAdapter<UUID>() {
override fun write(out: JsonWriter, value: UUID) {
out.value(value.toString())
}

override fun read(reader: JsonReader): UUID {
return UUID.fromString(reader.nextString())
}
}.nullSafe())
.registerTypeAdapter(SimpleTimeMark::class.java, object : TypeAdapter<SimpleTimeMark>() {
override fun write(out: JsonWriter, value: SimpleTimeMark) {
out.value(value.toMillis())
}

override fun read(reader: JsonReader): SimpleTimeMark {
return reader.nextString().toLong().asTimeMark()
}
}.nullSafe())
.enableComplexMapKeySerialization()
.create()

Expand Down Expand Up @@ -79,11 +55,14 @@ class ConfigManager {
}

val features = OnlyFarmMod.feature
processor = MoulConfigProcessor(OnlyFarmMod.feature)
processor = MoulConfigProcessor(features)
BuiltinMoulConfigGuis.addProcessors(processor)
// UpdateManager.injectConfigProcessor(processor)
val configProcessorDriver = ConfigProcessorDriver(processor)
configProcessorDriver.processConfig(features)
try{
configProcessorDriver.processConfig(features)
}catch(ex: Exception){
println("Exc: ${ex.localizedMessage}")
}
}


Expand All @@ -99,10 +78,10 @@ class ConfigManager {

logger.log("load-$fileName-now")

output = if (fileType==ConfigFileType.FEATURES) {
output = if (fileType == ConfigFileType.FEATURES) {
val jsonObject = gson.fromJson(bufferedReader.readText(), JsonObject::class.java)
val run = { gson.fromJson(jsonObject, defaultValue.javaClass) }
if (Launch.blackboard["fml.deobfuscatedEnvironment"] as Boolean) {
if (Utils.isInDevEnviromen()) {
try {
run()
} catch (e: Throwable) {
Expand Down Expand Up @@ -131,7 +110,7 @@ class ConfigManager {
}
}

if (output==defaultValue) {
if (output == defaultValue) {
logger.log("Setting $fileName to be blank as it did not exist. It will be saved once something is written to it")
}

Expand All @@ -146,7 +125,7 @@ class ConfigManager {
private fun saveFile(file: File?, fileName: String, data: Any, reason: String) {
if (disableSaving) return
logger.log("saveConfig: $reason")
if (file==null) throw Error("Can not save $fileName, ${fileName}File is null!")
if (file == null) throw Error("Can not save $fileName, ${fileName}File is null!")
try {
logger.log("Saving $fileName file")
file.parentFile.mkdirs()
Expand Down
10 changes: 4 additions & 6 deletions src/main/kotlin/be/hize/onlyfarm/config/Features.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package be.hize.onlyfarm.config;

import be.hize.onlyfarm.OnlyFarmMod;
import be.hize.onlyfarm.config.features.Farming;
import be.hize.onlyfarm.config.features.Other;
import be.hize.onlyfarm.config.features.FarmingConfig;
import be.hize.onlyfarm.config.features.OtherConfig;
import com.google.gson.annotations.Expose;
import io.github.moulberry.moulconfig.Config;
import io.github.moulberry.moulconfig.Social;
Expand Down Expand Up @@ -43,11 +43,9 @@ public String getTitle() {

@Expose
@Category(name = "Farming", desc = "Only category that matter.")
public Farming farming = new Farming();
public FarmingConfig farming = new FarmingConfig();

@Expose
@Category(name = "Other", desc = "Not farming related, so it matter less.")
public Other other = new Other();


public OtherConfig other = new OtherConfig();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean;
import io.github.moulberry.moulconfig.annotations.ConfigOption;

public class Farming {
public class FarmingConfig {

@Expose
@ConfigOption(name = "1.12 Crop HitBox", desc = "Enable 1.12 Crop HitBox")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean;
import io.github.moulberry.moulconfig.annotations.ConfigOption;

public class Other {
public class OtherConfig {
@Expose
@ConfigOption(name = "Config Button", desc = "Add a button to the pause menu to configure OnlyFarm")
@ConfigEditorBoolean
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/be/hize/onlyfarm/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import net.minecraft.block.BlockCrops
import net.minecraft.block.BlockNetherWart
import net.minecraft.block.BlockPotato
import net.minecraft.client.Minecraft
import net.minecraft.launchwrapper.Launch
import net.minecraft.util.AxisAlignedBB
import net.minecraft.util.BlockPos
import net.minecraft.world.World
Expand Down Expand Up @@ -52,6 +53,8 @@ object Utils {
FMLCommonHandler.instance().handleExit(-1)
}

fun isInDevEnviromen() = Launch.blackboard["fml.deobfuscatedEnvironment"] as Boolean

fun updateCropsMaxY(world: World, pos: BlockPos, block: Block) {
if (!HypixelUtils.onSkyblock) return
val blockState = world.getBlockState(pos)
Expand Down

0 comments on commit 4c9a7db

Please sign in to comment.