From cd2729c443759984dd357fc12eb03b3cf5d52272 Mon Sep 17 00:00:00 2001 From: cao-awa Date: Thu, 28 Nov 2024 09:31:26 +0800 Subject: [PATCH] Completely removed kotlin depends. Disabled item merge test. Prepare to release '1.0.8'. --- build.gradle | 4 - gradle.properties | 2 +- settings.gradle | 3 - .../cao/awa/apricot/util/io/IOUtil.java | 353 ------------------ .../com/github/cao/awa/sepals/Sepals.java | 2 +- .../sepals/command/SepalsConfigCommand.java | 4 +- .../cao/awa/sepals/config/SepalsConfig.java | 142 +++++++ .../cao/awa/sepals/config/SepalsConfig.kt | 172 --------- .../awa/sepals/mixin/SepalsMixinPlugin.java | 2 +- .../mixin/entity/item/ItemEntityMixin.java | 104 +++--- 10 files changed, 199 insertions(+), 589 deletions(-) delete mode 100644 src/main/java/com/github/cao/awa/apricot/util/io/IOUtil.java create mode 100644 src/main/java/com/github/cao/awa/sepals/config/SepalsConfig.java delete mode 100644 src/main/java/com/github/cao/awa/sepals/config/SepalsConfig.kt diff --git a/build.gradle b/build.gradle index cbd5dc7..d584f01 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,6 @@ plugins { id 'fabric-loom' version '1.8.1' id 'maven-publish' - id 'org.jetbrains.kotlin.jvm' } version = project.mod_version @@ -126,6 +125,3 @@ publishing { // retrieving dependencies. } } -kotlin { - jvmToolchain(21) -} diff --git a/gradle.properties b/gradle.properties index ee7b834..bc6e02b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.16.7 # Mod Properties - mod_version = 1.0.7 + mod_version = 1.0.8 maven_group = com.github.cao.awa.sepals archives_base_name = sepals diff --git a/settings.gradle b/settings.gradle index 383f448..f936a6e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,9 +6,6 @@ pluginManagement { } gradlePluginPortal() } - plugins { - id 'org.jetbrains.kotlin.jvm' version '2.0.21' - } } plugins { id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0' diff --git a/src/main/java/com/github/cao/awa/apricot/util/io/IOUtil.java b/src/main/java/com/github/cao/awa/apricot/util/io/IOUtil.java deleted file mode 100644 index 58a12b7..0000000 --- a/src/main/java/com/github/cao/awa/apricot/util/io/IOUtil.java +++ /dev/null @@ -1,353 +0,0 @@ -package com.github.cao.awa.apricot.util.io; - -import java.io.*; - -/** - * Utils for I/O. - * - * @author cao_awa - * @since 1.0.0 - */ -public class IOUtil { - /** - * Write input to output. - * - * @param output - * Output - * @param input - * Input - * @throws IOException - * Happened IO error - * @author cao_awa - * @since 1.0.0 - */ - public static void write(OutputStream output, InputStream input) throws IOException { - output.write(input.readAllBytes()); - output.close(); - input.close(); - } - - /** - * Write input to output. - * - * @param output - * Output - * @param input - * Input - * @param buffer - * Buffer - * @throws IOException - * Happened IO error - * @author cao_awa - * @since 1.0.0 - */ - public static void write(OutputStream output, InputStream input, byte[] buffer) throws IOException { - int length; - while ((length = input.read(buffer)) != - 1) { - output.write( - buffer, - 0, - length - ); - } - - output.close(); - input.close(); - } - - /** - * Write bytes to output. - * - * @param output - * Output - * @param input - * Input - * @throws IOException - * Happened IO error - * @author cao_awa - * @since 1.0.0 - */ - public static void write(OutputStream output, byte[] input) throws IOException { - output.write(input); - output.close(); - } - - /** - * Write string to output. - * - * @param output - * Output - * @param input - * Input - * @throws IOException - * Happened IO error - * @author cao_awa - * @since 1.0.0 - */ - public static void write(OutputStream output, String input) throws IOException { - write0( - output, - input - ); - output.close(); - } - - /** - * Write string to output. - * - * @param output - * Output - * @param input - * Input - * @throws IOException - * Happened IO error - * @author cao_awa - * @since 1.0.0 - */ - public static void write0(OutputStream output, String input) throws IOException { - output.write(input.getBytes()); - } - - /** - * Write string to output. - * - * @param writer - * Writer - * @param input - * Input - * @throws IOException - * Happened IO error - * @author cao_awa - * @since 1.0.0 - */ - public static void write(Writer writer, String input) throws IOException { - write0( - writer, - input - ); - writer.close(); - } - - /** - * Write string to output. - * - * @param writer - * Writer - * @param input - * Input - * @throws IOException - * Happened IO error - * @author cao_awa - * @since 1.0.0 - */ - public static void write0(Writer writer, String input) throws IOException { - writer.write(input); - } - - /** - * Write string to output. - * - * @param writer - * Writer - * @param input - * Input - * @throws IOException - * Happened IO error - * @author cao_awa - * @since 1.0.0 - */ - public static void write0(OutputStream writer, byte[] input) throws IOException { - writer.write(input); - } - - /** - * Write information of reader to writer - * - * @param writer - * Writer - * @param reader - * Reader - * @throws IOException - * Happened IO error - * @author cao_awa - * @since 1.0.0 - */ - public static void write(Writer writer, Reader reader) throws IOException { - char[] chars = new char[4096]; - int length; - while ((length = reader.read(chars)) != - 1) { - writer.write( - chars, - 0, - length - ); - } - writer.close(); - reader.close(); - } - - /** - * Write chars to output. - * - * @param writer - * Writer - * @param input - * Input - * @throws IOException - * Happened IO error - * @author cao_awa - * @since 1.0.0 - */ - public static void write(Writer writer, char[] input) throws IOException { - writer.write(input); - writer.close(); - } - - /** - * Read input. - * - * @param input - * Input - * @throws IOException - * Happened IO error - * @author cao_awa - * @since 1.0.0 - */ - public static String read(InputStream input) throws IOException { - return read(new InputStreamReader(input)); - } - - /** - * Read input. - * - * @param input - * Input - * @throws IOException - * Happened IO error - * @author cao_awa - * @since 1.0.0 - */ - public static String read(Reader input) throws IOException { - char[] chars = new char[4096]; - int length; - StringBuilder builder = new StringBuilder(); - while ((length = input.read(chars)) != - 1) { - builder.append( - chars, - 0, - length - ); - } - input.close(); - return builder.toString(); - } - - /** - * Read input. - * - * @param input - * Input - * @throws IOException - * Happened IO error - * @author cao_awa - * @since 1.0.0 - */ - public static int read0(InputStream input, byte[] bytes) throws IOException { - return input.read(bytes); - } - - /** - * Read input. - * - * @param input - * Input - * @throws IOException - * Happened IO error - * @author cao_awa - * @since 1.0.0 - */ - public static String readLine(BufferedReader input) throws IOException { - return input.readLine(); - } - - /** - * Read input. - * - * @param input - * Input - * @throws IOException - * Happened IO error - * @author cao_awa - * @since 1.0.0 - */ - public static byte[] readBytes(InputStream input) throws IOException { - return input.readAllBytes(); - } - - /** - * Read input. - * - * @param input - * Input - * @throws IOException - * Happened IO error - * @author cao_awa - * @since 1.0.0 - */ - public static char[] readChars(InputStream input) throws IOException { - return readChars(new InputStreamReader(input)); - } - - /** - * Read input. - * - * @param input - * Input - * @throws IOException - * Happened IO error - * @author cao_awa - * @since 1.0.0 - */ - public static char[] readChars(Reader input) throws IOException { - char[] chars = new char[4096]; - int length; - StringBuilder builder = new StringBuilder(); - while ((length = input.read(chars)) != - 1) { - builder.append( - chars, - 0, - length - ); - } - input.close(); - return builder.toString() - .toCharArray(); - } - - public static void copy(String from, String to) throws IOException { - copy( - new File(from), - new File(to) - ); - } - - public static void copy(File from, File to) throws IOException { - BufferedInputStream input = new BufferedInputStream(new FileInputStream(from)); - BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(to)); - byte[] buff = new byte[16384]; - int length; - while ((length = input.read( - buff, - 0, - buff.length - )) != - 1) { - output.write( - buff, - 0, - length - ); - } - input.close(); - output.close(); - } -} diff --git a/src/main/java/com/github/cao/awa/sepals/Sepals.java b/src/main/java/com/github/cao/awa/sepals/Sepals.java index 28a9006..b7a4b69 100644 --- a/src/main/java/com/github/cao/awa/sepals/Sepals.java +++ b/src/main/java/com/github/cao/awa/sepals/Sepals.java @@ -11,7 +11,7 @@ public class Sepals implements ModInitializer { public static final Logger LOGGER = LogManager.getLogger("Sepals"); - public static final String VERSION = "1.0.7"; + public static final String VERSION = "1.0.8"; public static final SepalsConfig CONFIG = new SepalsConfig(); public static final SepalsConfig PERSISTENT_CONFIG = new SepalsConfig(); public static boolean isLithiumLoaded; diff --git a/src/main/java/com/github/cao/awa/sepals/command/SepalsConfigCommand.java b/src/main/java/com/github/cao/awa/sepals/command/SepalsConfigCommand.java index 1afd383..d12d826 100644 --- a/src/main/java/com/github/cao/awa/sepals/command/SepalsConfigCommand.java +++ b/src/main/java/com/github/cao/awa/sepals/command/SepalsConfigCommand.java @@ -47,13 +47,13 @@ private static int changeConfig(CommandContext context, Sepals.CONFIG.setConfig(key, value); if (temporary) { context.getSource().sendFeedback( - () -> Text.of("Config '" + SepalsConfig.ENABLE_SEPALS_ENTITIES_CRAMMING.name() + "' is '" + value + "' temporarily"), + () -> Text.of("Config '" + key.name() + "' is '" + value + "' temporarily"), true ); } else { Sepals.PERSISTENT_CONFIG.setConfig(key, value); context.getSource().sendFeedback( - () -> Text.of("Config '" + SepalsConfig.ENABLE_SEPALS_ENTITIES_CRAMMING.name() + "' is '" + value + "' now"), + () -> Text.of("Config '" + key.name() + "' is '" + value + "' now"), true ); diff --git a/src/main/java/com/github/cao/awa/sepals/config/SepalsConfig.java b/src/main/java/com/github/cao/awa/sepals/config/SepalsConfig.java new file mode 100644 index 0000000..d755318 --- /dev/null +++ b/src/main/java/com/github/cao/awa/sepals/config/SepalsConfig.java @@ -0,0 +1,142 @@ +package com.github.cao.awa.sepals.config; + +import com.alibaba.fastjson2.JSONObject; +import com.alibaba.fastjson2.JSONWriter; +import com.github.cao.awa.sepals.config.key.SepalsConfigKey; +import com.github.cao.awa.sinuatum.manipulate.Manipulate; +import com.github.cao.awa.sinuatum.util.io.IOUtil; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.nio.charset.StandardCharsets; + +public class SepalsConfig { + private static final Logger LOGGER = LogManager.getLogger("SepalsConfig"); + private static final File CONFIG_FILE = new File("config/sepals.json"); + public static final SepalsConfigKey FORCE_ENABLE_SEPALS_POI = SepalsConfigKey.create("forceEnableSepalsPoi", false); + public static final SepalsConfigKey ENABLE_SEPALS_VILLAGER = SepalsConfigKey.create("enableSepalsVillager", true); + public static final SepalsConfigKey ENABLE_SEPALS_FROG_LOOK_AT = SepalsConfigKey.create("enableSepalsFrogLookAt", true); + public static final SepalsConfigKey ENABLE_SEPALS_FROG_ATTACKABLE_SENSOR = SepalsConfigKey.create("enableSepalsFrogAttackableSensor", true); + public static final SepalsConfigKey ENABLE_SEPALS_LIVING_TARGET_CACHE = SepalsConfigKey.create("enableSepalsLivingTargetCache", true); + public static final SepalsConfigKey NEAREST_LIVING_ENTITIES_SENSOR_USE_QUICK_SORT = SepalsConfigKey.create("nearestLivingEntitiesSensorUseQuickSort", true); + public static final SepalsConfigKey ENABLE_SEPALS_BIASED_LONG_JUMP_TASK = SepalsConfigKey.create("enableSepalsBiasedLongJumpTask", true); + public static final SepalsConfigKey ENABLE_SEPALS_ENTITIES_CRAMMING = SepalsConfigKey.create("enableSepalsEntitiesCramming", true); + + private final JSONObject config = new JSONObject(); + + public boolean isForceEnableSepalsPoi() { + return getConfig(FORCE_ENABLE_SEPALS_POI); + } + + public boolean isEnableSepalsVillager() { + return getConfig(ENABLE_SEPALS_VILLAGER); + } + + public boolean isEnableSepalsFrogLookAt() { + return getConfig(ENABLE_SEPALS_FROG_LOOK_AT); + } + + public boolean isEnableSepalsFrogAttackableSensor() { + return getConfig(ENABLE_SEPALS_FROG_ATTACKABLE_SENSOR); + } + + public boolean isEnableSepalsLivingTargetCache() { + return getConfig(ENABLE_SEPALS_LIVING_TARGET_CACHE); + } + + public boolean isNearestLivingEntitiesSensorUseQuickSort() { + return getConfig(NEAREST_LIVING_ENTITIES_SENSOR_USE_QUICK_SORT); + } + + public boolean isEnableSepalsBiasedLongJumpTask() { + return getConfig(ENABLE_SEPALS_BIASED_LONG_JUMP_TASK); + } + + public boolean isEnableSepalsEntitiesCramming() { + return getConfig(ENABLE_SEPALS_ENTITIES_CRAMMING); + } + + public void setConfig(SepalsConfigKey configKey, X value) { + this.config.put(configKey.name(), configKey.checkLimits(checkOrThrow(configKey, value))); + } + + public void setConfig(SepalsConfigKey configKey, JSONObject json) { + this.config.put(configKey.name(), configKey.checkLimits(checkOrThrow(configKey, json.get(configKey.name())))); + } + + public X getConfig(@NotNull SepalsConfigKey configKey) { + Object value = this.config.get(configKey.name()); + if (value == null) { + return configKey.defaultValue(); + } + return checkOrThrow(configKey, value); + } + + @NotNull + private static X checkOrThrow(@NotNull SepalsConfigKey configKey, Object value) { + if (value == null) { + throw new NullPointerException("Config value should not be null"); + } + if (configKey.type().isInstance(value) || configKey.type().isAssignableFrom(value.getClass())) { + return Manipulate.cast(value); + } + throw new IllegalArgumentException("Config '" + configKey.name() + "' required '" + configKey.type() + "' but got '" + value.getClass() + "'"); + } + + public void load() { + try { + final JSONObject config = JSONObject.parse(IOUtil.read(new FileReader("config/sepals.json", StandardCharsets.UTF_8))); + + setConfig(FORCE_ENABLE_SEPALS_POI, config); + setConfig(ENABLE_SEPALS_VILLAGER, config); + setConfig(ENABLE_SEPALS_FROG_LOOK_AT, config); + setConfig(ENABLE_SEPALS_FROG_ATTACKABLE_SENSOR, config); + setConfig(ENABLE_SEPALS_LIVING_TARGET_CACHE, config); + setConfig(NEAREST_LIVING_ENTITIES_SENSOR_USE_QUICK_SORT, config); + setConfig(ENABLE_SEPALS_BIASED_LONG_JUMP_TASK, config); + setConfig(ENABLE_SEPALS_ENTITIES_CRAMMING, config); + } catch (Exception e) { + LOGGER.warn("Config not found, use default values", e); + } + } + + public void write() { + try { + if (!CONFIG_FILE.getParentFile().exists()) { + CONFIG_FILE.getParentFile().mkdirs(); + } + IOUtil.write( + new FileWriter(CONFIG_FILE, StandardCharsets.UTF_8), + this.config.toString(JSONWriter.Feature.PrettyFormat) + ); + } catch (Exception e) { + LOGGER.warn("Failed to save config", e); + } + } + + public void copyFrom(@NotNull SepalsConfig config) { + setConfig(FORCE_ENABLE_SEPALS_POI, config.isForceEnableSepalsPoi()); + setConfig(ENABLE_SEPALS_VILLAGER, config.isEnableSepalsVillager()); + setConfig(ENABLE_SEPALS_FROG_LOOK_AT, config.isEnableSepalsFrogLookAt()); + setConfig(ENABLE_SEPALS_FROG_ATTACKABLE_SENSOR, config.isEnableSepalsFrogAttackableSensor()); + setConfig(ENABLE_SEPALS_LIVING_TARGET_CACHE, config.isEnableSepalsLivingTargetCache()); + setConfig(NEAREST_LIVING_ENTITIES_SENSOR_USE_QUICK_SORT, config.isNearestLivingEntitiesSensorUseQuickSort()); + setConfig(ENABLE_SEPALS_BIASED_LONG_JUMP_TASK, config.isEnableSepalsBiasedLongJumpTask()); + setConfig(ENABLE_SEPALS_ENTITIES_CRAMMING, config.isEnableSepalsEntitiesCramming()); + } + + public void print() { + LOGGER.info("Sepals 'forceEnableSepalsPoi' flag is {}", isForceEnableSepalsPoi()); + LOGGER.info("Sepals 'enableSepalsVillager' flag is {}", isEnableSepalsVillager()); + LOGGER.info("Sepals 'enableSepalsFrogLookAt' flag is {}", isEnableSepalsFrogLookAt()); + LOGGER.info("Sepals 'enableSepalsFrogAttackableSensor' flag is {}", isEnableSepalsFrogAttackableSensor()); + LOGGER.info("Sepals 'enableSepalsLivingTargetCache' flag is {}", isEnableSepalsLivingTargetCache()); + LOGGER.info("Sepals 'nearestLivingEntitiesSensorUseQuickSort' flag is {}", isNearestLivingEntitiesSensorUseQuickSort()); + LOGGER.info("Sepals 'enableSepalsBiasedJumpLongTask' flag is {}", isEnableSepalsBiasedLongJumpTask()); + LOGGER.info("Sepals 'enableEntitiesCramming' flag is {}", isEnableSepalsEntitiesCramming()); + } +} diff --git a/src/main/java/com/github/cao/awa/sepals/config/SepalsConfig.kt b/src/main/java/com/github/cao/awa/sepals/config/SepalsConfig.kt deleted file mode 100644 index e2222be..0000000 --- a/src/main/java/com/github/cao/awa/sepals/config/SepalsConfig.kt +++ /dev/null @@ -1,172 +0,0 @@ -package com.github.cao.awa.sepals.config - -import com.alibaba.fastjson2.JSONObject -import com.alibaba.fastjson2.JSONWriter -import com.github.cao.awa.apricot.util.io.IOUtil -import com.github.cao.awa.sepals.config.key.SepalsConfigKey -import com.github.cao.awa.sinuatum.manipulate.Manipulate -import org.apache.logging.log4j.LogManager -import org.apache.logging.log4j.Logger -import java.io.File -import java.io.FileReader -import java.io.FileWriter -import java.nio.charset.StandardCharsets -import kotlin.jvm.Throws - -class SepalsConfig { - companion object { - val LOGGER: Logger = LogManager.getLogger("SepalsConfig") - val CONFIG_FILE: File = File("config/sepals.json") - - @JvmField - val FORCE_ENABLE_SEPALS_POI = SepalsConfigKey.create("forceEnableSepalsPoi", false) - - @JvmField - val ENABLE_SEPALS_VILLAGER = SepalsConfigKey.create("enableSepalsVillager", true) - - @JvmField - val ENABLE_SEPALS_FROG_LOOK_AT = SepalsConfigKey.create("enableSepalsFrogLookAt", true) - - @JvmField - val ENABLE_SEPALS_FROG_ATTACKABLE_SENSOR = SepalsConfigKey.create("enableSepalsFrogAttackableSensor", true) - - @JvmField - val ENABLE_SEPALS_LIVING_TARGET_CACHE = SepalsConfigKey.create("enableSepalsLivingTargetCache", true) - - @JvmField - val NEAREST_LIVING_ENTITIES_SENSOR_USE_QUICK_SORT = - SepalsConfigKey.create("nearestLivingEntitiesSensorUseQuickSort", true) - - @JvmField - val ENABLE_SEPALS_BIASED_LONG_JUMP_TASK = SepalsConfigKey.create("enableSepalsBiasedLongJumpTask", true) - - @JvmField - val ENABLE_SEPALS_ENTITIES_CRAMMING = SepalsConfigKey.create("enableSepalsEntitiesCramming", true) - } - - private val config = JSONObject() - - val isForceEnableSepalsPoi: 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) - val isNearestLivingEntitiesSensorUseQuickSort: Boolean - get() = getConfig( - NEAREST_LIVING_ENTITIES_SENSOR_USE_QUICK_SORT - ) - val isEnableSepalsBiasedLongJumpTask: Boolean get() = getConfig(ENABLE_SEPALS_BIASED_LONG_JUMP_TASK) - val isEnableSepalsEntitiesCramming: Boolean get() = getConfig(ENABLE_SEPALS_ENTITIES_CRAMMING) - - @Throws(IllegalArgumentException::class) - fun setConfig(configKey: SepalsConfigKey, value: X?) { - this.config[configKey.name] = configKey.checkLimits(checkOrThrow(configKey, value)) - } - - fun setConfig(configKey: SepalsConfigKey, json: JSONObject) { - this.config[configKey.name] = configKey.checkLimits(checkOrThrow(configKey, json[configKey.name])) - } - - @Throws(IllegalArgumentException::class) - fun getConfig(configKey: SepalsConfigKey): X { - val value = this.config[configKey.name] ?: return configKey.defaultValue - return checkOrThrow(configKey, value) - } - - @Throws(IllegalArgumentException::class) - private fun checkOrThrow(configKey: SepalsConfigKey<*>, value: Any?): X { - if (value == null) { - throw NullPointerException("Value should not be null") - } - if (configKey.type.isInstance(value) || configKey.type.isAssignableFrom(value.javaClass)) { - return Manipulate.cast(value) - } - throw IllegalArgumentException("Config '" + configKey.name + "' required '" + configKey.type + "' but got '" + value.javaClass + "'") - } - - fun load() { - var config: JSONObject? = null - try { - config = JSONObject.parse(IOUtil.read(FileReader("config/sepals.json", StandardCharsets.UTF_8))) - } catch (e: Exception) { - LOGGER.warn("Config not found, use default values") - } - - if (config != null) { - setConfig(FORCE_ENABLE_SEPALS_POI, config) - setConfig(ENABLE_SEPALS_VILLAGER, config) - setConfig(ENABLE_SEPALS_FROG_LOOK_AT, config) - setConfig(ENABLE_SEPALS_FROG_ATTACKABLE_SENSOR, config) - setConfig(ENABLE_SEPALS_LIVING_TARGET_CACHE, config) - setConfig(NEAREST_LIVING_ENTITIES_SENSOR_USE_QUICK_SORT, config) - setConfig(ENABLE_SEPALS_BIASED_LONG_JUMP_TASK, config) - setConfig(ENABLE_SEPALS_ENTITIES_CRAMMING, config) - } - } - - fun write() { - try { - if (!CONFIG_FILE.parentFile.exists()) { - CONFIG_FILE.parentFile.mkdirs() - } - IOUtil.write( - FileWriter(CONFIG_FILE, StandardCharsets.UTF_8), - config.toString(JSONWriter.Feature.PrettyFormat) - ) - } catch (e: Exception) { - LOGGER.warn("Failed to save config", e) - } - } - - fun copyFrom(config: SepalsConfig) { - setConfig(FORCE_ENABLE_SEPALS_POI, config.isForceEnableSepalsPoi) - setConfig(ENABLE_SEPALS_VILLAGER, config.isEnableSepalsVillager) - setConfig(ENABLE_SEPALS_FROG_LOOK_AT, config.isEnableSepalsFrogLookAt) - setConfig( - ENABLE_SEPALS_FROG_ATTACKABLE_SENSOR, - config.isEnableSepalsFrogAttackableSensor - ) - setConfig( - ENABLE_SEPALS_LIVING_TARGET_CACHE, - config.isEnableSepalsLivingTargetCache - ) - setConfig( - NEAREST_LIVING_ENTITIES_SENSOR_USE_QUICK_SORT, - config.isNearestLivingEntitiesSensorUseQuickSort - ) - setConfig( - ENABLE_SEPALS_BIASED_LONG_JUMP_TASK, - config.isEnableSepalsBiasedLongJumpTask - ) - setConfig( - ENABLE_SEPALS_ENTITIES_CRAMMING, - config.isEnableSepalsEntitiesCramming - ) - } - - fun print() { - LOGGER.info("Sepals 'forceEnableSepalsPoi' flag is {}", isForceEnableSepalsPoi) - LOGGER.info("Sepals 'enableSepalsVillager' flag is {}", isEnableSepalsVillager) - LOGGER.info("Sepals 'enableSepalsFrogLookAt' flag is {}", isEnableSepalsFrogLookAt) - LOGGER.info( - "Sepals 'enableSepalsFrogAttackableSensor' flag is {}", - isEnableSepalsFrogAttackableSensor - ) - LOGGER.info( - "Sepals 'enableSepalsLivingTargetCache' flag is {}", - isEnableSepalsLivingTargetCache - ) - LOGGER.info( - "Sepals 'nearestLivingEntitiesSensorUseQuickSort' flag is {}", - isNearestLivingEntitiesSensorUseQuickSort - ) - LOGGER.info( - "Sepals 'enableSepalsBiasedJumpLongTask' flag is {}", - isEnableSepalsBiasedLongJumpTask - ) - LOGGER.info( - "Sepals 'enableEntitiesCramming' flag is {}", - isEnableSepalsEntitiesCramming - ) - } -} diff --git a/src/main/java/com/github/cao/awa/sepals/mixin/SepalsMixinPlugin.java b/src/main/java/com/github/cao/awa/sepals/mixin/SepalsMixinPlugin.java index 1648be4..510de02 100644 --- a/src/main/java/com/github/cao/awa/sepals/mixin/SepalsMixinPlugin.java +++ b/src/main/java/com/github/cao/awa/sepals/mixin/SepalsMixinPlugin.java @@ -2,10 +2,10 @@ import com.alibaba.fastjson2.JSONObject; import com.github.cao.awa.apricot.util.collection.ApricotCollectionFactor; -import com.github.cao.awa.apricot.util.io.IOUtil; import com.github.cao.awa.sepals.transform.mixin.config.SepalsMixinConfig; import com.github.cao.awa.sepals.transform.mixin.handler.SepalsMixinHandler; import com.github.cao.awa.sinuatum.manipulate.ManipulateBuilder; +import com.github.cao.awa.sinuatum.util.io.IOUtil; import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.ModContainer; import org.objectweb.asm.tree.ClassNode; diff --git a/src/main/java/com/github/cao/awa/sepals/mixin/entity/item/ItemEntityMixin.java b/src/main/java/com/github/cao/awa/sepals/mixin/entity/item/ItemEntityMixin.java index 7933c1e..b921367 100644 --- a/src/main/java/com/github/cao/awa/sepals/mixin/entity/item/ItemEntityMixin.java +++ b/src/main/java/com/github/cao/awa/sepals/mixin/entity/item/ItemEntityMixin.java @@ -30,58 +30,58 @@ public ItemEntityMixin(EntityType type, World world) { super(type, world); } - @Shadow - protected abstract boolean canMerge(); - - @Shadow - protected abstract void tryMerge(ItemEntity other); - - @Inject( - method = "tryMerge()V", - at = @At(value = "HEAD"), - cancellable = true - ) - private void tryMerge(CallbackInfo ci) { - if (canMerge()) { - getBoxedEntities( - getWorld(), - getBoundingBox().expand(0.5, 0.0, 0.5), - itemEntity -> { - tryMerge(itemEntity); - return isRemoved(); - } - ); - } - ci.cancel(); - } - - @Unique - public void getBoxedEntities(World world, Box box, Predicate invalidate) { - if (world instanceof BoxedItemEntities entities) { - if (entities.canSetEntities()) { - entities.setEntities(world.getEntitiesByType(TypeFilter.instanceOf(ItemEntity.class), box, entity -> entity != (Object) this && ((ItemEntityAccessor) entity).invokeCanMerge())); - } - - for (ItemEntity entity : entities.entities()) { - ItemStack stack = entity.getStack(); - - if (stack.getMaxCount() == stack.getCount()) { - entities.invalidate(entity); - continue; - } - - if (!entity.getBoundingBox().intersects(box)) { - continue; - } - - if (invalidate.test(entity)) { - // Invalidate this item, because it no longer can be to other items. - entities.invalidate((ItemEntity) (Object) this); - break; - } - } - } - } +// @Shadow +// protected abstract boolean canMerge(); +// +// @Shadow +// protected abstract void tryMerge(ItemEntity other); +// +// @Inject( +// method = "tryMerge()V", +// at = @At(value = "HEAD"), +// cancellable = true +// ) +// private void tryMerge(CallbackInfo ci) { +// if (canMerge()) { +// getBoxedEntities( +// getWorld(), +// getBoundingBox().expand(0.5, 0.0, 0.5), +// itemEntity -> { +// tryMerge(itemEntity); +// return isRemoved(); +// } +// ); +// } +// ci.cancel(); +// } +// +// @Unique +// public void getBoxedEntities(World world, Box box, Predicate invalidate) { +// if (world instanceof BoxedItemEntities entities) { +// if (entities.canSetEntities()) { +// entities.setEntities(world.getEntitiesByType(TypeFilter.instanceOf(ItemEntity.class), box, entity -> entity != (Object) this && ((ItemEntityAccessor) entity).invokeCanMerge())); +// } +// +// for (ItemEntity entity : entities.entities()) { +// ItemStack stack = entity.getStack(); +// +// if (stack.getMaxCount() == stack.getCount()) { +// entities.invalidate(entity); +// continue; +// } +// +// if (!entity.getBoundingBox().intersects(box)) { +// continue; +// } +// +// if (invalidate.test(entity)) { +// // Invalidate this item, because it no longer can be to other items. +// entities.invalidate((ItemEntity) (Object) this); +// break; +// } +// } +// } +// } @Inject( method = "isFireImmune",