From fd033b1204c30771a571897a3219866bb31394d3 Mon Sep 17 00:00:00 2001 From: Keuin Date: Fri, 15 Jan 2021 00:59:00 +0800 Subject: Version 1.4.1: add switch for fixing EntityTrackerEntry spamming. Improve option list. --- gradle.properties | 2 +- .../keuin/ohmyvanillamc/OhMyVanillaMinecraft.java | 27 +----------------- .../com/keuin/ohmyvanillamc/OmvmConfiguration.java | 32 +++++++++++++++++----- .../mixin/DisableEntityTrackerEntrySpamming.java | 9 +++++- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/gradle.properties b/gradle.properties index 7242478..8407992 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ minecraft_version=1.16.4 yarn_mappings=1.16.4+build.9 loader_version=0.11.0 # Mod Properties -mod_version=1.4.0 +mod_version=1.4.1 maven_group=com.keuin.omvm archives_base_name=oh-my-vanilla-mc # Dependencies diff --git a/src/main/java/com/keuin/ohmyvanillamc/OhMyVanillaMinecraft.java b/src/main/java/com/keuin/ohmyvanillamc/OhMyVanillaMinecraft.java index f76321a..fe9080e 100644 --- a/src/main/java/com/keuin/ohmyvanillamc/OhMyVanillaMinecraft.java +++ b/src/main/java/com/keuin/ohmyvanillamc/OhMyVanillaMinecraft.java @@ -4,10 +4,8 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonIOException; import net.fabricmc.api.ModInitializer; -import net.minecraft.server.network.EntityTrackerEntry; import java.io.*; -import java.lang.reflect.Field; import java.nio.charset.StandardCharsets; import java.util.logging.Logger; @@ -16,35 +14,12 @@ public class OhMyVanillaMinecraft implements ModInitializer { private static final Logger LOGGER = Logger.getLogger("OhMyVanillaMinecraft"); private static OmvmConfiguration configuration = null; - private static final OmvmConfiguration defaultConfiguration = new OmvmConfiguration( - false, - false, - false, - false - ); + private static final OmvmConfiguration defaultConfiguration = new OmvmConfiguration(); public static OmvmConfiguration getConfiguration() { return configuration != null ? configuration : defaultConfiguration; } - private static void disableEntityTrackerEntrySpamming() { - try { - //获取该类的字节码对象 - Class clazz = EntityTrackerEntry.class; - - //获取其私有成员 - Field name = clazz.getDeclaredField("LOGGER"); - - //暴力反射 - name.setAccessible(true); - - //重新赋值 参数一:实力 参数二:值 -// name.set(EntityTrackerEntry, "小鸭鸭"); - } catch (NoSuchFieldException ignored) { - // never mind - } - } - @Override public void onInitialize() { // This code runs as soon as Minecraft is in a mod-load-ready state. diff --git a/src/main/java/com/keuin/ohmyvanillamc/OmvmConfiguration.java b/src/main/java/com/keuin/ohmyvanillamc/OmvmConfiguration.java index 4992f9b..41bfeb2 100644 --- a/src/main/java/com/keuin/ohmyvanillamc/OmvmConfiguration.java +++ b/src/main/java/com/keuin/ohmyvanillamc/OmvmConfiguration.java @@ -4,18 +4,32 @@ import java.util.Objects; public class OmvmConfiguration { + private final boolean fixEntityTrackerEntrySpamming; private final boolean disableFishSchooling; private final boolean disablePhantomSpawning; private final boolean disableWanderingTraderSpawning; private final boolean reintroduceLlamaItemDuplicating; - public OmvmConfiguration(boolean disableFishSchooling, boolean disablePhantomSpawning, boolean disableWanderingTraderSpawning, boolean reintroduceLlamaItemDuplicating) { + public OmvmConfiguration() { + fixEntityTrackerEntrySpamming = true; + disableFishSchooling = false; + disablePhantomSpawning = false; + disableWanderingTraderSpawning = false; + reintroduceLlamaItemDuplicating = false; + } + + public OmvmConfiguration(boolean fixEntityTrackerEntrySpamming, boolean disableFishSchooling, boolean disablePhantomSpawning, boolean disableWanderingTraderSpawning, boolean reintroduceLlamaItemDuplicating) { + this.fixEntityTrackerEntrySpamming = fixEntityTrackerEntrySpamming; this.disableFishSchooling = disableFishSchooling; this.disablePhantomSpawning = disablePhantomSpawning; this.disableWanderingTraderSpawning = disableWanderingTraderSpawning; this.reintroduceLlamaItemDuplicating = reintroduceLlamaItemDuplicating; } + public boolean isFixEntityTrackerEntrySpamming() { + return fixEntityTrackerEntrySpamming; + } + public boolean isDisableFishSchooling() { return disableFishSchooling; } @@ -37,7 +51,8 @@ public class OmvmConfiguration { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; OmvmConfiguration that = (OmvmConfiguration) o; - return disableFishSchooling == that.disableFishSchooling && + return fixEntityTrackerEntrySpamming == that.fixEntityTrackerEntrySpamming && + disableFishSchooling == that.disableFishSchooling && disablePhantomSpawning == that.disablePhantomSpawning && disableWanderingTraderSpawning == that.disableWanderingTraderSpawning && reintroduceLlamaItemDuplicating == that.reintroduceLlamaItemDuplicating; @@ -45,14 +60,17 @@ public class OmvmConfiguration { @Override public int hashCode() { - return Objects.hash(disableFishSchooling, disablePhantomSpawning, disableWanderingTraderSpawning, reintroduceLlamaItemDuplicating); + return Objects.hash(fixEntityTrackerEntrySpamming, disableFishSchooling, disablePhantomSpawning, disableWanderingTraderSpawning, reintroduceLlamaItemDuplicating); } @Override public String toString() { - return "Disable Fish Schooling: " + disableFishSchooling + "\n" + - "Disable Phantom Spawning: " + disablePhantomSpawning + "\n" + - "Disable Wandering Trader Spawning: " + disableWanderingTraderSpawning + "\n" + - "Reintroduce Llama Item Duplicating: " + reintroduceLlamaItemDuplicating; + String s = ""; + s += "(BugFix) Fix Entity Tracker Entry Spamming: " + fixEntityTrackerEntrySpamming + "\n"; + s += "(Optimization) Disable Fish Schooling: " + disableFishSchooling + "\n"; + s += "(Exotic Feature) Disable Phantom Spawning: " + disablePhantomSpawning + "\n"; + s += "(Exotic Feature) Disable Wandering Trader Spawning: " + disableWanderingTraderSpawning + "\n"; + s += "(Obsolete Vanilla Feature) Reintroduce Llama Item Duplicating: " + reintroduceLlamaItemDuplicating; + return s; } } diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixin/DisableEntityTrackerEntrySpamming.java b/src/main/java/com/keuin/ohmyvanillamc/mixin/DisableEntityTrackerEntrySpamming.java index 523aeed..bf1f0b1 100644 --- a/src/main/java/com/keuin/ohmyvanillamc/mixin/DisableEntityTrackerEntrySpamming.java +++ b/src/main/java/com/keuin/ohmyvanillamc/mixin/DisableEntityTrackerEntrySpamming.java @@ -1,9 +1,12 @@ package com.keuin.ohmyvanillamc.mixin; import com.keuin.ohmyvanillamc.DummyLogger; +import com.keuin.ohmyvanillamc.OhMyVanillaMinecraft; import net.minecraft.server.network.EntityTrackerEntry; import org.apache.logging.log4j.Logger; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.gen.Accessor; @Mixin(EntityTrackerEntry.class) @@ -11,9 +14,13 @@ public class DisableEntityTrackerEntrySpamming { private static final Logger DUMMY_LOGGER = new DummyLogger(); + @Shadow + @Final + private static Logger LOGGER; + @Accessor("LOGGER") private static Logger LOGGER() { - return DUMMY_LOGGER; + return OhMyVanillaMinecraft.getConfiguration().isFixEntityTrackerEntrySpamming() ? DUMMY_LOGGER : LOGGER; } } -- cgit v1.2.3