From 94f092015a05d0179e307468c717ad391e455742 Mon Sep 17 00:00:00 2001 From: Merrg1n <22628584+Merrg1n@users.noreply.github.com> Date: Sat, 13 Aug 2022 22:36:35 +0800 Subject: carpet ext --- .../keuin/ohmyvanillamc/OhMyVanillaMinecraft.java | 173 +------------------ .../com/keuin/ohmyvanillamc/OmvmExtension.java | 26 +++ .../java/com/keuin/ohmyvanillamc/OmvmSettings.java | 51 ++++++ .../com/keuin/ohmyvanillamc/ReflectionUtils.java | 51 ------ .../config/ImmutableOmvmConfiguration.java | 54 ------ .../ohmyvanillamc/config/OmvmConfiguration.java | 183 --------------------- .../mixin/DisableEntityTrackerEntrySpamming.java | 34 ---- .../ohmyvanillamc/mixin/DisableFishSchooling.java | 47 ------ .../mixin/Mc113809AbstractPlantStemBlockMixin.java | 86 ---------- .../mixin/Mc113809BambooBlockMixin.java | 90 ---------- .../mixin/Mc113809CactusBlockMixin.java | 81 --------- .../mixin/Mc113809ChorusFlowerBlockMixin.java | 162 ------------------ .../mixin/Mc113809SugarCaneBlockMixin.java | 75 --------- .../mixin/ReintroduceLlamaItemDuping.java | 105 ------------ .../EntityTrackerEntryMixin.java | 32 ++++ .../SchoolingFishEntityMixin.java | 50 ++++++ .../forceRipening/AbstractPlantStemBlockMixin.java | 86 ++++++++++ .../rule/forceRipening/BambooBlockMixin.java | 90 ++++++++++ .../rule/forceRipening/CactusBlockMixin.java | 81 +++++++++ .../rule/forceRipening/ChorusFlowerBlockMixin.java | 162 ++++++++++++++++++ .../rule/forceRipening/SugarCaneBlockMixin.java | 75 +++++++++ .../PlayerManagerMixin.java | 105 ++++++++++++ 22 files changed, 765 insertions(+), 1134 deletions(-) create mode 100644 src/main/java/com/keuin/ohmyvanillamc/OmvmExtension.java create mode 100644 src/main/java/com/keuin/ohmyvanillamc/OmvmSettings.java delete mode 100644 src/main/java/com/keuin/ohmyvanillamc/ReflectionUtils.java delete mode 100644 src/main/java/com/keuin/ohmyvanillamc/config/ImmutableOmvmConfiguration.java delete mode 100644 src/main/java/com/keuin/ohmyvanillamc/config/OmvmConfiguration.java delete mode 100644 src/main/java/com/keuin/ohmyvanillamc/mixin/DisableEntityTrackerEntrySpamming.java delete mode 100644 src/main/java/com/keuin/ohmyvanillamc/mixin/DisableFishSchooling.java delete mode 100644 src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809AbstractPlantStemBlockMixin.java delete mode 100644 src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809BambooBlockMixin.java delete mode 100644 src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809CactusBlockMixin.java delete mode 100644 src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809ChorusFlowerBlockMixin.java delete mode 100644 src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809SugarCaneBlockMixin.java delete mode 100644 src/main/java/com/keuin/ohmyvanillamc/mixin/ReintroduceLlamaItemDuping.java create mode 100644 src/main/java/com/keuin/ohmyvanillamc/mixins/fix/disableEntityTrackerEntrySpamming/EntityTrackerEntryMixin.java create mode 100644 src/main/java/com/keuin/ohmyvanillamc/mixins/rule/disableFishSchooling/SchoolingFishEntityMixin.java create mode 100644 src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/AbstractPlantStemBlockMixin.java create mode 100644 src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/BambooBlockMixin.java create mode 100644 src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/CactusBlockMixin.java create mode 100644 src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/ChorusFlowerBlockMixin.java create mode 100644 src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/SugarCaneBlockMixin.java create mode 100644 src/main/java/com/keuin/ohmyvanillamc/mixins/rule/reintroduceLlamaItemDuping/PlayerManagerMixin.java (limited to 'src/main/java/com/keuin/ohmyvanillamc') diff --git a/src/main/java/com/keuin/ohmyvanillamc/OhMyVanillaMinecraft.java b/src/main/java/com/keuin/ohmyvanillamc/OhMyVanillaMinecraft.java index 2cdad10..39b16d8 100644 --- a/src/main/java/com/keuin/ohmyvanillamc/OhMyVanillaMinecraft.java +++ b/src/main/java/com/keuin/ohmyvanillamc/OhMyVanillaMinecraft.java @@ -1,181 +1,22 @@ package com.keuin.ohmyvanillamc; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonIOException; -import com.keuin.ohmyvanillamc.config.ImmutableOmvmConfiguration; -import com.keuin.ohmyvanillamc.config.OmvmConfiguration; -import com.mojang.brigadier.Command; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.StringArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import com.mojang.brigadier.suggestion.Suggestions; -import com.mojang.brigadier.suggestion.SuggestionsBuilder; import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Style; -import net.minecraft.util.Formatting; - -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.concurrent.CompletableFuture; -import java.util.logging.Logger; -import java.util.stream.Stream; - -import static com.keuin.ohmyvanillamc.ReflectionUtils.getFieldName; -import static com.keuin.ohmyvanillamc.ReflectionUtils.setPrivateField; +import net.fabricmc.loader.api.FabricLoader; public class OhMyVanillaMinecraft implements ModInitializer { - private static final Logger LOGGER = Logger.getLogger("OhMyVanillaMinecraft"); + private static final String MOD_ID = "ohmyvanillamc"; - private static final OmvmConfiguration defaultConfiguration = - new ImmutableOmvmConfiguration(); - private static OmvmConfiguration configuration = null; + private static String version; - public static OmvmConfiguration getConfiguration() { - return configuration; + public static String getVersion() { + return version; } @Override public void onInitialize() { - // This code runs as soon as Minecraft is in a mod-load-ready state. - // However, some things (like resources) may still be uninitialized. - // Proceed with mild caution. - - LOGGER.info("Loading configuration..."); - - // load configuration - - final String fileName = "omvm.json"; - final File file = new File(fileName); - if (!file.exists()) { - LOGGER.info("Configuration file does not exist! Use default configuration."); - try (FileOutputStream fileOutputStream = new FileOutputStream(file)) { - final String jsonString = (new GsonBuilder().setPrettyPrinting().create()).toJson(defaultConfiguration); - try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream)) { - outputStreamWriter.write(jsonString); - } - } catch (FileNotFoundException e) { - LOGGER.severe("Cannot write default configuration to file `" + fileName + "`: " + e); - } catch (IOException e) { - LOGGER.severe("Failed to write default configuration to file `" + fileName + "`: " + e); - } - } else { - try (FileInputStream fileInputStream = new FileInputStream(file)) { - try (InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8)) { - try (BufferedReader reader = new BufferedReader(inputStreamReader)) { - configuration = (new Gson()).fromJson(reader, OmvmConfiguration.class); - } - } - } catch (IOException e) { - LOGGER.severe("Failed to read config file `" + fileName + "`: " + e); - } catch (JsonIOException e) { - LOGGER.severe("Failed to decode config json file `" + fileName + "`: " + e); - } - } - - if (configuration == null) { - configuration = new OmvmConfiguration(defaultConfiguration); - } - - LOGGER.info(getConfigurationString()); - - CommandRegistrationCallback.EVENT.register(new CommandRegistrationCallback() { - @Override - public void register(CommandDispatcher commandDispatcher, boolean b) { - commandDispatcher.register(CommandManager.literal("omvm").executes(new Command() { - @Override - public int run(CommandContext context) throws CommandSyntaxException { - String text = getConfigurationString(); - context.getSource().sendFeedback(new LiteralText(text), false); - return 1; // 1: success, -1: fail - } - })); - } - }); - - - String[] keys = getFieldName(configuration); - final Set keySet = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(keys))); - - CommandRegistrationCallback.EVENT.register(new CommandRegistrationCallback() { - @Override - public void register(CommandDispatcher commandDispatcher, boolean b) { - commandDispatcher.register(CommandManager.literal("omvm") - .then(CommandManager.literal("set") - .then(CommandManager.argument("key", StringArgumentType.word()) - .suggests(new SuggestionProvider() { - @Override - public CompletableFuture getSuggestions(CommandContext context, SuggestionsBuilder builder) throws CommandSyntaxException { - String remaining = builder.getRemaining().toLowerCase(Locale.ROOT); - keySet.stream().filter(key -> key.toLowerCase().startsWith(remaining)).forEach(builder::suggest); - return builder.buildFuture(); - } - }) - .then(CommandManager.argument("value", StringArgumentType.word()).suggests(new SuggestionProvider() { - @Override - public CompletableFuture getSuggestions(CommandContext context, SuggestionsBuilder builder) throws CommandSyntaxException { - String remaining = builder.getRemaining().toLowerCase(Locale.ROOT); - Stream.of("true", "false").filter(key -> key.toLowerCase().startsWith(remaining)).forEach(builder::suggest); - return builder.buildFuture(); - } - }) - .executes(new Command() { - @Override - public int run(CommandContext context) throws CommandSyntaxException { - try { - boolean previousFixSpamming = configuration.isFixEntityTrackerEntrySpamming(); - - String key = context.getArgument("key", String.class); - String value = context.getArgument("value", String.class); - - if (!keySet.contains(key)) { - StringBuilder sb = new StringBuilder(); - sb.append("Invalid key. Available keys:"); - keySet.forEach(k -> sb.append("\n- ").append(k)); - context.getSource().sendFeedback(new LiteralText(sb.toString()) - .setStyle(Style.EMPTY.withColor(Formatting.RED)), false); - return -1; - } - - if (!Arrays.asList("true", "false").contains(value)) { - context.getSource().sendFeedback(new LiteralText("Value must be `true` or `false`.") - .setStyle(Style.EMPTY.withColor(Formatting.RED)), false); - return -1; - } - - setPrivateField(configuration, key, Boolean.valueOf(value)); - context.getSource().sendFeedback( - new LiteralText("`" + key + "` has been temporarily set to `" + value + "`."), true - ); - - return 1; // 1: success, -1: fail - } catch (NoSuchFieldException | IllegalAccessException e) { - context.getSource().sendFeedback(new LiteralText("There is a bug. Tell trueKeuin.") - .setStyle(Style.EMPTY.withColor(Formatting.RED)), false); - return -1; - } - } - }) - ) - ))); - } - }); - + version = FabricLoader.getInstance().getModContainer(MOD_ID).orElseThrow(RuntimeException::new).getMetadata().getVersion().getFriendlyString(); + OmvmExtension.initialize(); } - - private String getConfigurationString() { - return "OhMyVanillaMinecraft\n==========\n" + configuration + "\n==========\n" - + "Force enabled tweaks:\n" + "Furnace fuel list lag fix\n" + "=========="; - } - - } diff --git a/src/main/java/com/keuin/ohmyvanillamc/OmvmExtension.java b/src/main/java/com/keuin/ohmyvanillamc/OmvmExtension.java new file mode 100644 index 0000000..e820fd6 --- /dev/null +++ b/src/main/java/com/keuin/ohmyvanillamc/OmvmExtension.java @@ -0,0 +1,26 @@ +package com.keuin.ohmyvanillamc; + +import carpet.CarpetExtension; +import carpet.CarpetServer; + +public class OmvmExtension implements CarpetExtension { + private static final OmvmExtension INSTANCE = new OmvmExtension(); + + public static OmvmExtension getInstance() { + return INSTANCE; + } + + public static void initialize() { + CarpetServer.manageExtension(INSTANCE); + } + + @Override + public void onGameStarted() { + CarpetServer.settingsManager.parseSettingsClass(OmvmSettings.class); + } + + @Override + public String version() { + return OhMyVanillaMinecraft.getVersion(); + } +} diff --git a/src/main/java/com/keuin/ohmyvanillamc/OmvmSettings.java b/src/main/java/com/keuin/ohmyvanillamc/OmvmSettings.java new file mode 100644 index 0000000..206fc22 --- /dev/null +++ b/src/main/java/com/keuin/ohmyvanillamc/OmvmSettings.java @@ -0,0 +1,51 @@ +package com.keuin.ohmyvanillamc; + +import carpet.settings.Rule; + +import static carpet.settings.RuleCategory.*; + +public class OmvmSettings { + public static final String OMVM = "OMVM"; + + @Rule( + desc = "Remove AI of laggy schooling fish (tropical fish, cod)", + category = {OMVM, FEATURE, OPTIMIZATION} + ) + public static boolean disableFishSchooling = false; + + @Rule( + desc = "Reintroduce item duping with llama on a boat", + category = {OMVM, FEATURE, EXPERIMENTAL} + ) + public static boolean reintroduceLlamaItemDuplicating = false; + + @Rule( + desc = "Reintroduce Force Ripening for kelp, twisted vine and weeping vine, See MC-113809", + category = {OMVM, FEATURE, EXPERIMENTAL} + ) + public static boolean enableStemForceRipening = false; + + @Rule( + desc = "Reintroduce Force Ripening for bamboo, See MC-113809", + category = {OMVM, FEATURE, EXPERIMENTAL} + ) + public static boolean enableBambooForceRipening = false; + + @Rule( + desc = "Reintroduce Force Ripening for cactus, See MC-113809", + category = {OMVM, FEATURE, EXPERIMENTAL} + ) + public static boolean enableCactusForceRipening = false; + + @Rule( + desc = "Reintroduce Force Ripening for chorus flower, See MC-113809", + category = {OMVM, FEATURE, EXPERIMENTAL} + ) + public static boolean enableChorusFlowerForceRipening = false; + + @Rule( + desc = "Reintroduce Force Ripening for sugar cane, See MC-113809", + category = {OMVM, FEATURE, EXPERIMENTAL} + ) + public static boolean enableSugarCaneForceRipening = false; +} diff --git a/src/main/java/com/keuin/ohmyvanillamc/ReflectionUtils.java b/src/main/java/com/keuin/ohmyvanillamc/ReflectionUtils.java deleted file mode 100644 index a87632e..0000000 --- a/src/main/java/com/keuin/ohmyvanillamc/ReflectionUtils.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.keuin.ohmyvanillamc; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Arrays; - -/** - * @Author 落叶飞翔的蜗牛 Keuin - * @Date 2018/3/10 - * @Description 常用反射函数 - */ -public final class ReflectionUtils { - - /** - * 获取私有成员变量的值 - */ - public static Object getPrivateField(Object instance, String filedName) throws NoSuchFieldException, IllegalAccessException { - Field field = instance.getClass().getDeclaredField(filedName); - field.setAccessible(true); - return field.get(instance); - } - - /** - * 设置私有成员的值 - */ - public static void setPrivateField(Object instance, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException { - Field field = instance.getClass().getDeclaredField(fieldName); - field.setAccessible(true); - field.set(instance, value); - } - - /** - * 访问私有方法 - */ - public static Object invokePrivateMethod(Object instance, String methodName, Class[] classes, Object... args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - Method method = instance.getClass().getDeclaredMethod(methodName, classes); - method.setAccessible(true); - return method.invoke(instance, args); - } - - /** - * 获取所有成员变量的名字 - * - * @param o 要获取成员变量的对象实例 - * @return 所有成员变量名字数组 - */ - public static String[] getFieldName(Object o) { - return Arrays.stream(o.getClass().getDeclaredFields()).map(Field::getName).toArray(String[]::new); - } -} \ No newline at end of file diff --git a/src/main/java/com/keuin/ohmyvanillamc/config/ImmutableOmvmConfiguration.java b/src/main/java/com/keuin/ohmyvanillamc/config/ImmutableOmvmConfiguration.java deleted file mode 100644 index 4ed9d65..0000000 --- a/src/main/java/com/keuin/ohmyvanillamc/config/ImmutableOmvmConfiguration.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.keuin.ohmyvanillamc.config; - -public class ImmutableOmvmConfiguration extends OmvmConfiguration { - - public ImmutableOmvmConfiguration() { - super(); - } - - public ImmutableOmvmConfiguration(OmvmConfiguration omvmConfiguration) { - super(omvmConfiguration); - } - - public ImmutableOmvmConfiguration(boolean fixEntityTrackerEntrySpamming, boolean disableFishSchooling, - boolean disablePhantomSpawning, boolean disableWanderingTraderSpawning, - boolean reintroduceLlamaItemDuplicating, boolean reintroduceZeroTickFarm, - boolean enableStemForceRipening, boolean enableBambooForceRipening, - boolean enableCactusForceRipening, boolean enableChorusFlowerForceRipening, - boolean enableSugarCaneForceRipening) { - super(fixEntityTrackerEntrySpamming, disableFishSchooling, disablePhantomSpawning, - disableWanderingTraderSpawning, reintroduceLlamaItemDuplicating, reintroduceZeroTickFarm, - enableStemForceRipening, enableBambooForceRipening, enableCactusForceRipening, - enableChorusFlowerForceRipening, enableSugarCaneForceRipening); - } - - @Override - public void setFixEntityTrackerEntrySpamming(boolean fixEntityTrackerEntrySpamming) { - throw new UnsupportedOperationException(); - } - - @Override - public void setDisableFishSchooling(boolean disableFishSchooling) { - throw new UnsupportedOperationException(); - } - - @Override - public void setDisablePhantomSpawning(boolean disablePhantomSpawning) { - throw new UnsupportedOperationException(); - } - - @Override - public void setDisableWanderingTraderSpawning(boolean disableWanderingTraderSpawning) { - throw new UnsupportedOperationException(); - } - - @Override - public void setReintroduceLlamaItemDuplicating(boolean reintroduceLlamaItemDuplicating) { - throw new UnsupportedOperationException(); - } - - @Override - public void setReintroduceZeroTickFarm(boolean reintroduceZeroTickFarm) { - throw new UnsupportedOperationException(); - } -} diff --git a/src/main/java/com/keuin/ohmyvanillamc/config/OmvmConfiguration.java b/src/main/java/com/keuin/ohmyvanillamc/config/OmvmConfiguration.java deleted file mode 100644 index 8f95b15..0000000 --- a/src/main/java/com/keuin/ohmyvanillamc/config/OmvmConfiguration.java +++ /dev/null @@ -1,183 +0,0 @@ -package com.keuin.ohmyvanillamc.config; - -import java.util.Objects; - -public class OmvmConfiguration { - - private boolean fixEntityTrackerEntrySpamming; - private boolean disableFishSchooling; - private boolean disablePhantomSpawning; - private boolean disableWanderingTraderSpawning; - private boolean reintroduceLlamaItemDuplicating; - private boolean reintroduceZeroTickFarm; - private boolean enableStemForceRipening; - private boolean enableBambooForceRipening; - private boolean enableCactusForceRipening; - private boolean enableChorusFlowerForceRipening; - private boolean enableSugarCaneForceRipening; - - public OmvmConfiguration() { - this(true, false, false, false, false, false, true, true, true, true, true); - } - - public OmvmConfiguration(OmvmConfiguration omvmConfiguration) { - this.fixEntityTrackerEntrySpamming = omvmConfiguration.fixEntityTrackerEntrySpamming; - this.disableFishSchooling = omvmConfiguration.disableFishSchooling; - this.disablePhantomSpawning = omvmConfiguration.disablePhantomSpawning; - this.disableWanderingTraderSpawning = omvmConfiguration.disableWanderingTraderSpawning; - this.reintroduceLlamaItemDuplicating = omvmConfiguration.reintroduceLlamaItemDuplicating; - this.reintroduceZeroTickFarm = omvmConfiguration.reintroduceZeroTickFarm; - this.enableStemForceRipening = omvmConfiguration.enableStemForceRipening; - this.enableBambooForceRipening = omvmConfiguration.enableBambooForceRipening; - this.enableCactusForceRipening = omvmConfiguration.enableCactusForceRipening; - this.enableChorusFlowerForceRipening = omvmConfiguration.enableChorusFlowerForceRipening; - this.enableSugarCaneForceRipening = omvmConfiguration.enableSugarCaneForceRipening; - } - - public OmvmConfiguration(boolean fixEntityTrackerEntrySpamming, boolean disableFishSchooling - , boolean disablePhantomSpawning, boolean disableWanderingTraderSpawning - , boolean reintroduceLlamaItemDuplicating, boolean reintroduceZeroTickFarm - , boolean enableStemForceRipening, boolean enableBambooForceRipening - , boolean enableCactusForceRipening, boolean enableChorusFlowerForceRipening - , boolean enableSugarCaneForceRipening) { - this.fixEntityTrackerEntrySpamming = fixEntityTrackerEntrySpamming; - this.disableFishSchooling = disableFishSchooling; - this.disablePhantomSpawning = disablePhantomSpawning; - this.disableWanderingTraderSpawning = disableWanderingTraderSpawning; - this.reintroduceLlamaItemDuplicating = reintroduceLlamaItemDuplicating; - this.reintroduceZeroTickFarm = reintroduceZeroTickFarm; - this.enableStemForceRipening = enableStemForceRipening; - this.enableBambooForceRipening = enableBambooForceRipening; - this.enableCactusForceRipening = enableCactusForceRipening; - this.enableChorusFlowerForceRipening = enableChorusFlowerForceRipening; - this.enableSugarCaneForceRipening = enableSugarCaneForceRipening; - } - - public boolean isFixEntityTrackerEntrySpamming() { - return fixEntityTrackerEntrySpamming; - } - - public boolean isDisableFishSchooling() { - return disableFishSchooling; - } - - public boolean isDisablePhantomSpawning() { - return disablePhantomSpawning; - } - - public boolean isDisableWanderingTraderSpawning() { - return disableWanderingTraderSpawning; - } - - public boolean isReintroduceLlamaItemDuplicating() { - return reintroduceLlamaItemDuplicating; - } - - public boolean isReintroduceZeroTickFarm() { - return reintroduceZeroTickFarm; - } - - public boolean isEnableStemForceRipening() { - return enableStemForceRipening; - } - - public void setEnableStemForceRipening(boolean enableStemForceRipening) { - this.enableStemForceRipening = enableStemForceRipening; - } - - public boolean isEnableBambooForceRipening() { - return enableBambooForceRipening; - } - - public void setEnableBambooForceRipening(boolean enableBambooForceRipening) { - this.enableBambooForceRipening = enableBambooForceRipening; - } - - public boolean isEnableCactusForceRipening() { - return enableCactusForceRipening; - } - - public void setEnableCactusForceRipening(boolean enableCactusForceRipening) { - this.enableCactusForceRipening = enableCactusForceRipening; - } - - public boolean isEnableChorusFlowerForceRipening() { - return enableChorusFlowerForceRipening; - } - - public void setEnableChorusFlowerForceRipening(boolean enableChorusFlowerForceRipening) { - this.enableChorusFlowerForceRipening = enableChorusFlowerForceRipening; - } - - public boolean isEnableSugarCaneForceRipening() { - return enableSugarCaneForceRipening; - } - - public void setEnableSugarCaneForceRipening(boolean enableSugarCaneForceRipening) { - this.enableSugarCaneForceRipening = enableSugarCaneForceRipening; - } - - public void setFixEntityTrackerEntrySpamming(boolean fixEntityTrackerEntrySpamming) { - this.fixEntityTrackerEntrySpamming = fixEntityTrackerEntrySpamming; - } - - public void setDisableFishSchooling(boolean disableFishSchooling) { - this.disableFishSchooling = disableFishSchooling; - } - - public void setDisablePhantomSpawning(boolean disablePhantomSpawning) { - this.disablePhantomSpawning = disablePhantomSpawning; - } - - public void setDisableWanderingTraderSpawning(boolean disableWanderingTraderSpawning) { - this.disableWanderingTraderSpawning = disableWanderingTraderSpawning; - } - - public void setReintroduceLlamaItemDuplicating(boolean reintroduceLlamaItemDuplicating) { - this.reintroduceLlamaItemDuplicating = reintroduceLlamaItemDuplicating; - } - - public void setReintroduceZeroTickFarm(boolean reintroduceZeroTickFarm) { - this.reintroduceZeroTickFarm = reintroduceZeroTickFarm; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - OmvmConfiguration that = (OmvmConfiguration) o; - return fixEntityTrackerEntrySpamming == that.fixEntityTrackerEntrySpamming && - disableFishSchooling == that.disableFishSchooling && - disablePhantomSpawning == that.disablePhantomSpawning && - disableWanderingTraderSpawning == that.disableWanderingTraderSpawning && - reintroduceLlamaItemDuplicating == that.reintroduceLlamaItemDuplicating && - reintroduceZeroTickFarm == that.reintroduceZeroTickFarm && - enableStemForceRipening == that.enableStemForceRipening && - enableBambooForceRipening == that.enableBambooForceRipening && - enableCactusForceRipening == that.enableCactusForceRipening && - enableChorusFlowerForceRipening == that.enableChorusFlowerForceRipening && - enableSugarCaneForceRipening == that.enableSugarCaneForceRipening; - } - - @Override - public int hashCode() { - return Objects.hash(fixEntityTrackerEntrySpamming, disableFishSchooling, disablePhantomSpawning, disableWanderingTraderSpawning, reintroduceLlamaItemDuplicating, reintroduceZeroTickFarm, enableStemForceRipening, enableBambooForceRipening, enableCactusForceRipening, enableChorusFlowerForceRipening, enableSugarCaneForceRipening); - } - - @Override - public String toString() { - 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 + "\n"; - s += "(Obsolete Vanilla Feature) Reintroduce 0-tick Plants Farm: " + reintroduceZeroTickFarm + "\n"; - s += "(Zero Tick Farm) Enable Stem Force Ripening: " + enableStemForceRipening + "\n"; - s += "(Zero Tick Farm) Enable Bamboo Force Ripening: " + enableBambooForceRipening + "\n"; - s += "(Zero Tick Farm) Enable Cactus Force Ripening: " + enableCactusForceRipening + "\n"; - s += "(Zero Tick Farm) Enable Chorus Flower Force Ripening: " + enableCactusForceRipening + "\n"; - s += "(Zero Tick Farm) Enable Sugar Cane Force Ripening: " + enableSugarCaneForceRipening + "\n"; - return s; - } -} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixin/DisableEntityTrackerEntrySpamming.java b/src/main/java/com/keuin/ohmyvanillamc/mixin/DisableEntityTrackerEntrySpamming.java deleted file mode 100644 index faf5c9d..0000000 --- a/src/main/java/com/keuin/ohmyvanillamc/mixin/DisableEntityTrackerEntrySpamming.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.keuin.ohmyvanillamc.mixin; - -import com.keuin.ohmyvanillamc.DummyLogger; -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) -public class DisableEntityTrackerEntrySpamming { - - private static final Logger LOGGER_DUMMY = new DummyLogger(); - - static { - setLOGGER(LOGGER_DUMMY); - } - - @Shadow - @Final - private static Logger LOGGER; - - @Accessor("LOGGER") - private static Logger getLOGGER() { - throw new AssertionError(); - } - - @Accessor("LOGGER") - private static void setLOGGER(Logger logger) { - throw new AssertionError(); - } - -} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixin/DisableFishSchooling.java b/src/main/java/com/keuin/ohmyvanillamc/mixin/DisableFishSchooling.java deleted file mode 100644 index c2de0d5..0000000 --- a/src/main/java/com/keuin/ohmyvanillamc/mixin/DisableFishSchooling.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.keuin.ohmyvanillamc.mixin; - -import com.keuin.ohmyvanillamc.OhMyVanillaMinecraft; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.ai.goal.FollowGroupLeaderGoal; -import net.minecraft.entity.passive.FishEntity; -import net.minecraft.entity.passive.SchoolingFishEntity; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(SchoolingFishEntity.class) -public abstract class DisableFishSchooling extends FishEntity { - - public DisableFishSchooling(EntityType type, World world) { - super(type, world); - } - - @Shadow public abstract boolean hasLeader(); - @Shadow private SchoolingFishEntity leader; - - /** - * @reason To disable SchoolingFish schooling. - * @author trueKeuin - */ - @Overwrite - public void moveTowardLeader() { - if (!OhMyVanillaMinecraft.getConfiguration().isDisableFishSchooling()) { - if (this.hasLeader()) { - this.getNavigation().startMovingTo(this.leader, 1.0D); - } - } - } - - /** - * @reason To disable SchoolingFish schooling. - * @author trueKeuin - */ - @Overwrite - public void initGoals() { - super.initGoals(); - if (!OhMyVanillaMinecraft.getConfiguration().isDisableFishSchooling()) { - this.goalSelector.add(5, new FollowGroupLeaderGoal((SchoolingFishEntity) (Object) this)); - } - } -} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809AbstractPlantStemBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809AbstractPlantStemBlockMixin.java deleted file mode 100644 index 47e2167..0000000 --- a/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809AbstractPlantStemBlockMixin.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.keuin.ohmyvanillamc.mixin; - -import com.keuin.ohmyvanillamc.OhMyVanillaMinecraft; -import net.minecraft.block.AbstractPlantPartBlock; -import net.minecraft.block.AbstractPlantStemBlock; -import net.minecraft.block.BlockState; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.state.property.IntProperty; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.shape.VoxelShape; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.Random; - -@Mixin(AbstractPlantStemBlock.class) -public abstract class Mc113809AbstractPlantStemBlockMixin extends AbstractPlantPartBlock { - - protected Mc113809AbstractPlantStemBlockMixin(Settings settings, Direction growthDirection, VoxelShape outlineShape, boolean tickWater) { - super(settings, growthDirection, outlineShape, tickWater); - } - - @Shadow - @Final - public static IntProperty AGE; - - @Shadow - @Final - private double growthChance; - - @Shadow - protected abstract boolean chooseStemState(BlockState state); - - /** - * @reason Revert to the super class's impl (Block's). - * @author trueKeuin - */ - @Overwrite - public boolean hasRandomTicks(BlockState state) { - return super.hasRandomTicks(state); - } - - /** - * Reintroduce the MC-113809 glitch for kelp, twisted vine and weeping vine. The implementation is identical to Minecraft 1.15.2. - * - * @author trueKeuin - * @reason reintroduce MC-113809 for bamboo. - */ - @Override - public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (!state.canPlaceAt(world, pos)) { - world.breakBlock(pos, true); - } else if (OhMyVanillaMinecraft.getConfiguration().isReintroduceZeroTickFarm() && OhMyVanillaMinecraft.getConfiguration().isEnableStemForceRipening()) { - realGrow(state, world, pos, random); - } - } - - /** - * Revert to base class (Block) implementation of randomTick: just simply call scheduledTick. - * (both 1.15.2 and 1.16.4 are the same) - * - * @author trueKeuin - * @reason revert to the base class `Block` implementation. - */ - @Overwrite - public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (OhMyVanillaMinecraft.getConfiguration().isReintroduceZeroTickFarm() && OhMyVanillaMinecraft.getConfiguration().isEnableStemForceRipening()) { - scheduledTick(state, world, pos, random); - } else { - realGrow(state, world, pos, random); - } - } - - private void realGrow(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (state.get(AGE) < 25 && random.nextDouble() < this.growthChance) { - BlockPos blockPos = pos.offset(this.growthDirection); - if (this.chooseStemState(world.getBlockState(blockPos))) { - world.setBlockState(blockPos, state.cycle(AGE)); - } - } - } - -} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809BambooBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809BambooBlockMixin.java deleted file mode 100644 index 7e25bf1..0000000 --- a/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809BambooBlockMixin.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.keuin.ohmyvanillamc.mixin; - -import com.keuin.ohmyvanillamc.OhMyVanillaMinecraft; -import net.minecraft.block.BambooBlock; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.state.property.IntProperty; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.Random; - -@Mixin(BambooBlock.class) -public abstract class Mc113809BambooBlockMixin extends Block { - - public Mc113809BambooBlockMixin(Settings settings) { - super(settings); - } - - @Shadow - @Final - public static IntProperty STAGE; - - @Shadow - protected abstract int countBambooBelow(BlockView world, BlockPos pos); - - @Shadow - protected abstract void updateLeaves(BlockState state, World world, BlockPos pos, Random random, int height); - - /** - * Reintroduce the base class's implementation. - * - * @reason reintroduce base class's implementation. - * @author trueKeuin - */ - @Overwrite - public boolean hasRandomTicks(BlockState state) { - boolean zf = OhMyVanillaMinecraft.getConfiguration().isReintroduceZeroTickFarm() && OhMyVanillaMinecraft.getConfiguration().isEnableBambooForceRipening(); - return ((state.get(STAGE) == 0) && !zf) || (randomTicks && zf); - } - - /** - * Revert to base class (Block) implementation of randomTick: just simply call scheduledTick. - * (both 1.15.2 and 1.16.4 are the same) - * - * @author trueKeuin - * @reason revert to the base class `Block` implementation. - */ - @Overwrite - public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (OhMyVanillaMinecraft.getConfiguration().isReintroduceZeroTickFarm() && OhMyVanillaMinecraft.getConfiguration().isEnableBambooForceRipening()) { - scheduledTick(state, world, pos, random); - } else { - realGrow(state, world, pos, random); - } - } - - /** - * Reintroduce the MC-113809 glitch for bamboo. The implementation is identical to Minecraft 1.15.2. - * - * @author trueKeuin - * @reason reintroduce MC-113809 for bamboo. - */ - @Overwrite - public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (!state.canPlaceAt(world, pos)) { - world.breakBlock(pos, true); - } else if (OhMyVanillaMinecraft.getConfiguration().isReintroduceZeroTickFarm() && OhMyVanillaMinecraft.getConfiguration().isEnableBambooForceRipening()) { - realGrow(state, world, pos, random); - } - } - - private void realGrow(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (state.get(STAGE) == 0) { - if (random.nextInt(3) == 0 && world.isAir(pos.up()) && world.getBaseLightLevel(pos.up(), 0) >= 9) { - int i = this.countBambooBelow(world, pos) + 1; - if (i < 16) { - this.updateLeaves(state, world, pos, random, i); - } - } - } - } - -} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809CactusBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809CactusBlockMixin.java deleted file mode 100644 index f2381c2..0000000 --- a/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809CactusBlockMixin.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.keuin.ohmyvanillamc.mixin; - -import com.keuin.ohmyvanillamc.OhMyVanillaMinecraft; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.CactusBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.state.property.IntProperty; -import net.minecraft.util.math.BlockPos; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.Random; - -@Mixin(CactusBlock.class) -public abstract class Mc113809CactusBlockMixin extends Block { - - public Mc113809CactusBlockMixin(Settings settings) { - super(settings); - } - - @Shadow - @Final - public static IntProperty AGE; - - /** - * Revert to base class (Block) implementation of randomTick: just simply call scheduledTick. - * (both 1.15.2 and 1.16.4 are the same) - * - * @author trueKeuin - * @reason revert to the base class `Block` implementation. - */ - @Overwrite - public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (OhMyVanillaMinecraft.getConfiguration().isReintroduceZeroTickFarm() && OhMyVanillaMinecraft.getConfiguration().isEnableCactusForceRipening()) { - scheduledTick(state, world, pos, random); - } else { - // here goes 1.16.4 version randomTick impl. - realGrow(state, world, pos); - } - } - - /** - * Reintroduce the MC-113809 glitch for cactus. The implementation is identical to Minecraft 1.15.2. - * - * @author trueKeuin - * @reason reintroduce MC-113809 for cactus. - */ - @Overwrite - public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (!state.canPlaceAt(world, pos)) { - world.breakBlock(pos, true); - } else if (OhMyVanillaMinecraft.getConfiguration().isReintroduceZeroTickFarm() && OhMyVanillaMinecraft.getConfiguration().isEnableCactusForceRipening()) { - realGrow(state, world, pos); - } - } - - private void realGrow(BlockState state, ServerWorld world, BlockPos pos) { - BlockPos blockPos = pos.up(); - if (world.isAir(blockPos)) { - int i; - for (i = 1; world.getBlockState(pos.down(i)).isOf(this); ++i) { - } - - if (i < 3) { - int j = state.get(AGE); - if (j == 15) { - world.setBlockState(blockPos, this.getDefaultState()); - BlockState blockState = state.with(AGE, 0); - world.setBlockState(pos, blockState, 4); - blockState.neighborUpdate(world, blockPos, this, pos, false); - } else { - world.setBlockState(pos, state.with(AGE, j + 1), 4); - } - - } - } - } -} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809ChorusFlowerBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809ChorusFlowerBlockMixin.java deleted file mode 100644 index 9f929ba..0000000 --- a/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809ChorusFlowerBlockMixin.java +++ /dev/null @@ -1,162 +0,0 @@ -package com.keuin.ohmyvanillamc.mixin; - -import com.keuin.ohmyvanillamc.OhMyVanillaMinecraft; -import net.minecraft.block.*; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.state.property.IntProperty; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; -import net.minecraft.world.WorldView; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.Random; - -@Mixin(ChorusFlowerBlock.class) -public abstract class Mc113809ChorusFlowerBlockMixin extends Block { - - public Mc113809ChorusFlowerBlockMixin(Settings settings) { - super(settings); - } - - @Shadow - @Final - public static IntProperty AGE; - - @Shadow - @Final - private ChorusPlantBlock plantBlock; - - @Shadow - private static boolean isSurroundedByAir(WorldView world, BlockPos pos, @Nullable Direction exceptDirection) { - throw new RuntimeException("Mixin error. Program should not go here."); - } - - @Shadow - private void grow(World world, BlockPos pos, int age) { - throw new RuntimeException("Mixin error. Program should not go here."); - } - - @Shadow - private void die(World world, BlockPos pos) { - throw new RuntimeException("Mixin error. Program should not go here."); - } - - /** - * Reintroduce the MC-113809 glitch for chorus flower. The implementation is identical to Minecraft 1.15.2. - * - * @author trueKeuin - * @reason reintroduce MC-113809 for chorus flower. - */ - @Overwrite - public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (!state.canPlaceAt(world, pos)) { - world.breakBlock(pos, true); - } else if (OhMyVanillaMinecraft.getConfiguration().isReintroduceZeroTickFarm() && OhMyVanillaMinecraft.getConfiguration().isEnableChorusFlowerForceRipening()) { - realGrow(state, world, pos, random); - } - - } - - /** - * Reintroduce the base class's implementation. - * - * @reason reintroduce base class's implementation. - * @author trueKeuin - */ - @Overwrite - public boolean hasRandomTicks(BlockState state) { - boolean zf = OhMyVanillaMinecraft.getConfiguration().isReintroduceZeroTickFarm() && OhMyVanillaMinecraft.getConfiguration().isEnableChorusFlowerForceRipening(); - return ((state.get(AGE) < 5) && !zf) || (randomTicks && zf); - } - - /** - * Revert to base class (Block) implementation of randomTick: just simply call scheduledTick. - * (both 1.15.2 and 1.16.4 are the same) - * - * @author trueKeuin - * @reason revert to the base class `Block` implementation. - */ - @Overwrite - public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (OhMyVanillaMinecraft.getConfiguration().isReintroduceZeroTickFarm() && OhMyVanillaMinecraft.getConfiguration().isEnableChorusFlowerForceRipening()) { - scheduledTick(state, world, pos, random); - } else { - realGrow(state, world, pos, random); - } - - } - - private void realGrow(BlockState state, ServerWorld world, BlockPos pos, Random random) { - BlockPos blockPos = pos.up(); - if (world.isAir(blockPos) && blockPos.getY() < 256) { - int i = state.get(AGE); - if (i < 5) { - boolean bl = false; - boolean bl2 = false; - BlockState blockState = world.getBlockState(pos.down()); - Block block = blockState.getBlock(); - int l; - if (block == Blocks.END_STONE) { - bl = true; - } else if (block == this.plantBlock) { - l = 1; - - for (int k = 0; k < 4; ++k) { - Block block2 = world.getBlockState(pos.down(l + 1)).getBlock(); - if (block2 != this.plantBlock) { - if (block2 == Blocks.END_STONE) { - bl2 = true; - } - break; - } - - ++l; - } - - if (l < 2 || l <= random.nextInt(bl2 ? 5 : 4)) { - bl = true; - } - } else if (blockState.isAir()) { - bl = true; - } - - if (bl && isSurroundedByAir(world, blockPos, (Direction) null) && world.isAir(pos.up(2))) { - world.setBlockState(pos, this.plantBlock.withConnectionProperties(world, pos), 2); - this.grow(world, blockPos, i); - } else if (i < 4) { - l = random.nextInt(4); - if (bl2) { - ++l; - } - - boolean bl3 = false; - - for (int m = 0; m < l; ++m) { - Direction direction = Direction.Type.HORIZONTAL.random(random); - BlockPos blockPos2 = pos.offset(direction); - if (world.isAir(blockPos2) && world.isAir(blockPos2.down()) && isSurroundedByAir(world, blockPos2, direction.getOpposite())) { - this.grow(world, blockPos2, i + 1); - bl3 = true; - } - } - - if (bl3) { - world.setBlockState(pos, this.plantBlock.withConnectionProperties(world, pos), 2); - } else { - this.die(world, pos); - } - } else { - this.die(world, pos); - } - - } - } - } - - -} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809SugarCaneBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809SugarCaneBlockMixin.java deleted file mode 100644 index 62b08b6..0000000 --- a/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809SugarCaneBlockMixin.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.keuin.ohmyvanillamc.mixin; - -import com.keuin.ohmyvanillamc.OhMyVanillaMinecraft; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.SugarCaneBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.state.property.IntProperty; -import net.minecraft.util.math.BlockPos; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.Random; - -@Mixin(SugarCaneBlock.class) -public abstract class Mc113809SugarCaneBlockMixin extends Block { - - public Mc113809SugarCaneBlockMixin(Settings settings) { - super(settings); - } - - @Shadow - @Final - public static IntProperty AGE; - - /** - * Revert to base class (Block) implementation of randomTick: just simply call scheduledTick. - * (both 1.15.2 and 1.16.4 are the same) - * - * @author trueKeuin - * @reason revert to the base class `Block` implementation. - */ - @Overwrite - public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (OhMyVanillaMinecraft.getConfiguration().isReintroduceZeroTickFarm() && OhMyVanillaMinecraft.getConfiguration().isEnableSugarCaneForceRipening()) { - scheduledTick(state, world, pos, random); - } else if (world.isAir(pos.up())) { // here goes 1.16.4 version randomTick impl. - realGrow(state, world, pos); - } - - } - - /** - * Reintroduce the MC-113809 glitch for sugar cane. The implementation is identical to Minecraft 1.15.2. - * - * @author trueKeuin - * @reason reintroduce MC-113809 for sugar cane. - */ - @Overwrite - public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (!state.canPlaceAt(world, pos)) { - world.breakBlock(pos, true); - } else if (world.isAir(pos.up()) && OhMyVanillaMinecraft.getConfiguration().isReintroduceZeroTickFarm() && OhMyVanillaMinecraft.getConfiguration().isEnableSugarCaneForceRipening()) { - realGrow(state, world, pos); - } - } - - private void realGrow(BlockState state, ServerWorld world, BlockPos pos) { - int i; - for (i = 1; world.getBlockState(pos.down(i)).isOf((SugarCaneBlock) (Object) this); ++i) { - } - - if (i < 3) { - int j = state.get(AGE); - if (j == 15) { - world.setBlockState(pos.up(), this.getDefaultState()); - world.setBlockState(pos, state.with(AGE, 0), 4); - } else { - world.setBlockState(pos, state.with(AGE, j + 1), 4); - } - } - } -} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixin/ReintroduceLlamaItemDuping.java b/src/main/java/com/keuin/ohmyvanillamc/mixin/ReintroduceLlamaItemDuping.java deleted file mode 100644 index fff7aff..0000000 --- a/src/main/java/com/keuin/ohmyvanillamc/mixin/ReintroduceLlamaItemDuping.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.keuin.ohmyvanillamc.mixin; - -import com.keuin.ohmyvanillamc.OhMyVanillaMinecraft; -import net.minecraft.advancement.PlayerAdvancementTracker; -import net.minecraft.entity.Entity; -import net.minecraft.network.Packet; -import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.stat.ServerStatHandler; -import net.minecraft.stat.Stats; -import org.apache.logging.log4j.Logger; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -/** - * Reintroduce MC-161754 glitch - */ -@Mixin(PlayerManager.class) -public abstract class ReintroduceLlamaItemDuping { - - @Shadow - protected abstract void savePlayerData(ServerPlayerEntity player); - - @Shadow - @Final - private static Logger LOGGER; - - @Shadow - @Final - private List players; - - @Shadow - @Final - private MinecraftServer server; - - @Shadow - @Final - private Map playerMap; - - @Shadow - @Final - private Map statisticsMap; - - @Shadow - @Final - private Map advancementTrackers; - - @Shadow - public abstract void sendToAll(Packet packet); - - /** - * @reason re-introduce llama item duplicating glitch. - * @author trueKeuin - */ - @Overwrite - public void remove(ServerPlayerEntity player) { - ServerWorld serverWorld = player.getServerWorld(); - player.incrementStat(Stats.LEAVE_GAME); - this.savePlayerData(player); - if (player.hasVehicle()) { - Entity entity = player.getRootVehicle(); - if (entity.hasPlayerRider()) { - LOGGER.debug("Removing player mount"); - player.stopRiding(); - serverWorld.removeEntity(entity); - // entity.removed = true - entity.removed = !OhMyVanillaMinecraft.getConfiguration().isReintroduceLlamaItemDuplicating() || entity.removed; - - Entity entity2; - for (Iterator var4 = entity.getPassengersDeep().iterator(); var4.hasNext(); // entity2.removed = true - entity2.removed = !OhMyVanillaMinecraft.getConfiguration().isReintroduceLlamaItemDuplicating() || entity2.removed) { - entity2 = (Entity) var4.next(); - serverWorld.removeEntity(entity2); - } - - serverWorld.getChunk(player.chunkX, player.chunkZ).markDirty(); - } - } - - player.detach(); - serverWorld.removePlayer(player); - player.getAdvancementTracker().clearCriteria(); - this.players.remove(player); - this.server.getBossBarManager().onPlayerDisconnect(player); - UUID uUID = player.getUuid(); - ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity) this.playerMap.get(uUID); - if (serverPlayerEntity == player) { - this.playerMap.remove(uUID); - this.statisticsMap.remove(uUID); - this.advancementTrackers.remove(uUID); - } - - this.sendToAll(new PlayerListS2CPacket(PlayerListS2CPacket.Action.REMOVE_PLAYER, player)); - } -} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixins/fix/disableEntityTrackerEntrySpamming/EntityTrackerEntryMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixins/fix/disableEntityTrackerEntrySpamming/EntityTrackerEntryMixin.java new file mode 100644 index 0000000..5b885a0 --- /dev/null +++ b/src/main/java/com/keuin/ohmyvanillamc/mixins/fix/disableEntityTrackerEntrySpamming/EntityTrackerEntryMixin.java @@ -0,0 +1,32 @@ +package com.keuin.ohmyvanillamc.mixins.fix.disableEntityTrackerEntrySpamming; + +import com.keuin.ohmyvanillamc.DummyLogger; +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) +public class EntityTrackerEntryMixin { + + static { + setLOGGER(new DummyLogger()); + } + + @Shadow + @Final + private static Logger LOGGER; + + @Accessor("LOGGER") + private static Logger getLOGGER() { + throw new AssertionError(); + } + + @Accessor("LOGGER") + private static void setLOGGER(Logger logger) { + throw new AssertionError(); + } + +} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/disableFishSchooling/SchoolingFishEntityMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/disableFishSchooling/SchoolingFishEntityMixin.java new file mode 100644 index 0000000..9e82f09 --- /dev/null +++ b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/disableFishSchooling/SchoolingFishEntityMixin.java @@ -0,0 +1,50 @@ +package com.keuin.ohmyvanillamc.mixins.rule.disableFishSchooling; + +import com.keuin.ohmyvanillamc.OmvmSettings; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.ai.goal.FollowGroupLeaderGoal; +import net.minecraft.entity.passive.FishEntity; +import net.minecraft.entity.passive.SchoolingFishEntity; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(SchoolingFishEntity.class) +public abstract class SchoolingFishEntityMixin extends FishEntity { + + public SchoolingFishEntityMixin(EntityType type, World world) { + super(type, world); + } + + @Shadow + public abstract boolean hasLeader(); + + @Shadow + private SchoolingFishEntity leader; + + /** + * @reason To disable SchoolingFish schooling. + * @author trueKeuin + */ + @Overwrite + public void moveTowardLeader() { + if (!OmvmSettings.disableFishSchooling) { + if (this.hasLeader()) { + this.getNavigation().startMovingTo(this.leader, 1.0D); + } + } + } + + /** + * @reason To disable SchoolingFish schooling. + * @author trueKeuin + */ + @Overwrite + public void initGoals() { + super.initGoals(); + if (!OmvmSettings.disableFishSchooling) { + this.goalSelector.add(5, new FollowGroupLeaderGoal((SchoolingFishEntity) (Object) this)); + } + } +} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/AbstractPlantStemBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/AbstractPlantStemBlockMixin.java new file mode 100644 index 0000000..1092816 --- /dev/null +++ b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/AbstractPlantStemBlockMixin.java @@ -0,0 +1,86 @@ +package com.keuin.ohmyvanillamc.mixins.rule.forceRipening; + +import com.keuin.ohmyvanillamc.OmvmSettings; +import net.minecraft.block.AbstractPlantPartBlock; +import net.minecraft.block.AbstractPlantStemBlock; +import net.minecraft.block.BlockState; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.state.property.IntProperty; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.shape.VoxelShape; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.Random; + +@Mixin(AbstractPlantStemBlock.class) +public abstract class AbstractPlantStemBlockMixin extends AbstractPlantPartBlock { + + protected AbstractPlantStemBlockMixin(Settings settings, Direction growthDirection, VoxelShape outlineShape, boolean tickWater) { + super(settings, growthDirection, outlineShape, tickWater); + } + + @Shadow + @Final + public static IntProperty AGE; + + @Shadow + @Final + private double growthChance; + + @Shadow + protected abstract boolean chooseStemState(BlockState state); + + /** + * @reason Revert to the super class's impl (Block's). + * @author trueKeuin + */ + @Overwrite + public boolean hasRandomTicks(BlockState state) { + return super.hasRandomTicks(state); + } + + /** + * Reintroduce the MC-113809 glitch for kelp, twisted vine and weeping vine. The implementation is identical to Minecraft 1.15.2. + * + * @author trueKeuin + * @reason reintroduce MC-113809 for kelp, twisted vine and weeping vine. + */ + @Override + public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { + if (!state.canPlaceAt(world, pos)) { + world.breakBlock(pos, true); + } else if (OmvmSettings.enableStemForceRipening) { + realGrow(state, world, pos, random); + } + } + + /** + * Revert to base class (Block) implementation of randomTick: just simply call scheduledTick. + * (both 1.15.2 and 1.16.4 are the same) + * + * @author trueKeuin + * @reason revert to the base class `Block` implementation. + */ + @Overwrite + public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { + if (OmvmSettings.enableStemForceRipening) { + scheduledTick(state, world, pos, random); + } else { + realGrow(state, world, pos, random); + } + } + + private void realGrow(BlockState state, ServerWorld world, BlockPos pos, Random random) { + if (state.get(AGE) < 25 && random.nextDouble() < this.growthChance) { + BlockPos blockPos = pos.offset(this.growthDirection); + if (this.chooseStemState(world.getBlockState(blockPos))) { + world.setBlockState(blockPos, state.cycle(AGE)); + } + } + } + +} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/BambooBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/BambooBlockMixin.java new file mode 100644 index 0000000..0dd9be6 --- /dev/null +++ b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/BambooBlockMixin.java @@ -0,0 +1,90 @@ +package com.keuin.ohmyvanillamc.mixins.rule.forceRipening; + +import com.keuin.ohmyvanillamc.OmvmSettings; +import net.minecraft.block.BambooBlock; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.state.property.IntProperty; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.Random; + +@Mixin(BambooBlock.class) +public abstract class BambooBlockMixin extends Block { + + public BambooBlockMixin(Settings settings) { + super(settings); + } + + @Shadow + @Final + public static IntProperty STAGE; + + @Shadow + protected abstract int countBambooBelow(BlockView world, BlockPos pos); + + @Shadow + protected abstract void updateLeaves(BlockState state, World world, BlockPos pos, Random random, int height); + + /** + * Reintroduce the base class's implementation. + * + * @reason reintroduce base class's implementation. + * @author trueKeuin + */ + @Overwrite + public boolean hasRandomTicks(BlockState state) { + boolean zf = OmvmSettings.enableBambooForceRipening; + return ((state.get(STAGE) == 0) && !zf) || (randomTicks && zf); + } + + /** + * Revert to base class (Block) implementation of randomTick: just simply call scheduledTick. + * (both 1.15.2 and 1.16.4 are the same) + * + * @author trueKeuin + * @reason revert to the base class `Block` implementation. + */ + @Overwrite + public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { + if (OmvmSettings.enableBambooForceRipening) { + scheduledTick(state, world, pos, random); + } else { + realGrow(state, world, pos, random); + } + } + + /** + * Reintroduce the MC-113809 glitch for bamboo. The implementation is identical to Minecraft 1.15.2. + * + * @author trueKeuin + * @reason reintroduce MC-113809 for bamboo. + */ + @Overwrite + public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { + if (!state.canPlaceAt(world, pos)) { + world.breakBlock(pos, true); + } else if (OmvmSettings.enableBambooForceRipening) { + realGrow(state, world, pos, random); + } + } + + private void realGrow(BlockState state, ServerWorld world, BlockPos pos, Random random) { + if (state.get(STAGE) == 0) { + if (random.nextInt(3) == 0 && world.isAir(pos.up()) && world.getBaseLightLevel(pos.up(), 0) >= 9) { + int i = this.countBambooBelow(world, pos) + 1; + if (i < 16) { + this.updateLeaves(state, world, pos, random, i); + } + } + } + } + +} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/CactusBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/CactusBlockMixin.java new file mode 100644 index 0000000..d5feaf9 --- /dev/null +++ b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/CactusBlockMixin.java @@ -0,0 +1,81 @@ +package com.keuin.ohmyvanillamc.mixins.rule.forceRipening; + +import com.keuin.ohmyvanillamc.OmvmSettings; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.CactusBlock; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.state.property.IntProperty; +import net.minecraft.util.math.BlockPos; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.Random; + +@Mixin(CactusBlock.class) +public abstract class CactusBlockMixin extends Block { + + public CactusBlockMixin(Settings settings) { + super(settings); + } + + @Shadow + @Final + public static IntProperty AGE; + + /** + * Revert to base class (Block) implementation of randomTick: just simply call scheduledTick. + * (both 1.15.2 and 1.16.4 are the same) + * + * @author trueKeuin + * @reason revert to the base class `Block` implementation. + */ + @Overwrite + public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { + if (OmvmSettings.enableCactusForceRipening) { + scheduledTick(state, world, pos, random); + } else { + // here goes 1.16.4 version randomTick impl. + realGrow(state, world, pos); + } + } + + /** + * Reintroduce the MC-113809 glitch for cactus. The implementation is identical to Minecraft 1.15.2. + * + * @author trueKeuin + * @reason reintroduce MC-113809 for cactus. + */ + @Overwrite + public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { + if (!state.canPlaceAt(world, pos)) { + world.breakBlock(pos, true); + } else if (OmvmSettings.enableCactusForceRipening) { + realGrow(state, world, pos); + } + } + + private void realGrow(BlockState state, ServerWorld world, BlockPos pos) { + BlockPos blockPos = pos.up(); + if (world.isAir(blockPos)) { + int i; + for (i = 1; world.getBlockState(pos.down(i)).isOf(this); ++i) { + } + + if (i < 3) { + int j = state.get(AGE); + if (j == 15) { + world.setBlockState(blockPos, this.getDefaultState()); + BlockState blockState = state.with(AGE, 0); + world.setBlockState(pos, blockState, 4); + blockState.neighborUpdate(world, blockPos, this, pos, false); + } else { + world.setBlockState(pos, state.with(AGE, j + 1), 4); + } + + } + } + } +} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/ChorusFlowerBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/ChorusFlowerBlockMixin.java new file mode 100644 index 0000000..fb79848 --- /dev/null +++ b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/ChorusFlowerBlockMixin.java @@ -0,0 +1,162 @@ +package com.keuin.ohmyvanillamc.mixins.rule.forceRipening; + +import com.keuin.ohmyvanillamc.OmvmSettings; +import net.minecraft.block.*; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.state.property.IntProperty; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; +import net.minecraft.world.WorldView; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.Random; + +@Mixin(ChorusFlowerBlock.class) +public abstract class ChorusFlowerBlockMixin extends Block { + + public ChorusFlowerBlockMixin(Settings settings) { + super(settings); + } + + @Shadow + @Final + public static IntProperty AGE; + + @Shadow + @Final + private ChorusPlantBlock plantBlock; + + @Shadow + private static boolean isSurroundedByAir(WorldView world, BlockPos pos, @Nullable Direction exceptDirection) { + throw new RuntimeException("Mixin error. Program should not go here."); + } + + @Shadow + private void grow(World world, BlockPos pos, int age) { + throw new RuntimeException("Mixin error. Program should not go here."); + } + + @Shadow + private void die(World world, BlockPos pos) { + throw new RuntimeException("Mixin error. Program should not go here."); + } + + /** + * Reintroduce the MC-113809 glitch for chorus flower. The implementation is identical to Minecraft 1.15.2. + * + * @author trueKeuin + * @reason reintroduce MC-113809 for chorus flower. + */ + @Overwrite + public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { + if (!state.canPlaceAt(world, pos)) { + world.breakBlock(pos, true); + } else if (OmvmSettings.enableChorusFlowerForceRipening) { + realGrow(state, world, pos, random); + } + + } + + /** + * Reintroduce the base class's implementation. + * + * @reason reintroduce base class's implementation. + * @author trueKeuin + */ + @Overwrite + public boolean hasRandomTicks(BlockState state) { + boolean zf = OmvmSettings.enableChorusFlowerForceRipening; + return ((state.get(AGE) < 5) && !zf) || (randomTicks && zf); + } + + /** + * Revert to base class (Block) implementation of randomTick: just simply call scheduledTick. + * (both 1.15.2 and 1.16.4 are the same) + * + * @author trueKeuin + * @reason revert to the base class `Block` implementation. + */ + @Overwrite + public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { + if (OmvmSettings.enableChorusFlowerForceRipening) { + scheduledTick(state, world, pos, random); + } else { + realGrow(state, world, pos, random); + } + + } + + private void realGrow(BlockState state, ServerWorld world, BlockPos pos, Random random) { + BlockPos blockPos = pos.up(); + if (world.isAir(blockPos) && blockPos.getY() < 256) { + int i = state.get(AGE); + if (i < 5) { + boolean bl = false; + boolean bl2 = false; + BlockState blockState = world.getBlockState(pos.down()); + Block block = blockState.getBlock(); + int l; + if (block == Blocks.END_STONE) { + bl = true; + } else if (block == this.plantBlock) { + l = 1; + + for (int k = 0; k < 4; ++k) { + Block block2 = world.getBlockState(pos.down(l + 1)).getBlock(); + if (block2 != this.plantBlock) { + if (block2 == Blocks.END_STONE) { + bl2 = true; + } + break; + } + + ++l; + } + + if (l < 2 || l <= random.nextInt(bl2 ? 5 : 4)) { + bl = true; + } + } else if (blockState.isAir()) { + bl = true; + } + + if (bl && isSurroundedByAir(world, blockPos, (Direction) null) && world.isAir(pos.up(2))) { + world.setBlockState(pos, this.plantBlock.withConnectionProperties(world, pos), 2); + this.grow(world, blockPos, i); + } else if (i < 4) { + l = random.nextInt(4); + if (bl2) { + ++l; + } + + boolean bl3 = false; + + for (int m = 0; m < l; ++m) { + Direction direction = Direction.Type.HORIZONTAL.random(random); + BlockPos blockPos2 = pos.offset(direction); + if (world.isAir(blockPos2) && world.isAir(blockPos2.down()) && isSurroundedByAir(world, blockPos2, direction.getOpposite())) { + this.grow(world, blockPos2, i + 1); + bl3 = true; + } + } + + if (bl3) { + world.setBlockState(pos, this.plantBlock.withConnectionProperties(world, pos), 2); + } else { + this.die(world, pos); + } + } else { + this.die(world, pos); + } + + } + } + } + + +} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/SugarCaneBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/SugarCaneBlockMixin.java new file mode 100644 index 0000000..6cce2a3 --- /dev/null +++ b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/SugarCaneBlockMixin.java @@ -0,0 +1,75 @@ +package com.keuin.ohmyvanillamc.mixins.rule.forceRipening; + +import com.keuin.ohmyvanillamc.OmvmSettings; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.SugarCaneBlock; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.state.property.IntProperty; +import net.minecraft.util.math.BlockPos; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.Random; + +@Mixin(SugarCaneBlock.class) +public abstract class SugarCaneBlockMixin extends Block { + + public SugarCaneBlockMixin(Settings settings) { + super(settings); + } + + @Shadow + @Final + public static IntProperty AGE; + + /** + * Revert to base class (Block) implementation of randomTick: just simply call scheduledTick. + * (both 1.15.2 and 1.16.4 are the same) + * + * @author trueKeuin + * @reason revert to the base class `Block` implementation. + */ + @Overwrite + public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { + if (OmvmSettings.enableSugarCaneForceRipening) { + scheduledTick(state, world, pos, random); + } else if (world.isAir(pos.up())) { // here goes 1.16.4 version randomTick impl. + realGrow(state, world, pos); + } + + } + + /** + * Reintroduce the MC-113809 glitch for sugar cane. The implementation is identical to Minecraft 1.15.2. + * + * @author trueKeuin + * @reason reintroduce MC-113809 for sugar cane. + */ + @Overwrite + public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { + if (!state.canPlaceAt(world, pos)) { + world.breakBlock(pos, true); + } else if (world.isAir(pos.up()) && OmvmSettings.enableSugarCaneForceRipening) { + realGrow(state, world, pos); + } + } + + private void realGrow(BlockState state, ServerWorld world, BlockPos pos) { + int i; + for (i = 1; world.getBlockState(pos.down(i)).isOf((SugarCaneBlock) (Object) this); ++i) { + } + + if (i < 3) { + int j = state.get(AGE); + if (j == 15) { + world.setBlockState(pos.up(), this.getDefaultState()); + world.setBlockState(pos, state.with(AGE, 0), 4); + } else { + world.setBlockState(pos, state.with(AGE, j + 1), 4); + } + } + } +} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/reintroduceLlamaItemDuping/PlayerManagerMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/reintroduceLlamaItemDuping/PlayerManagerMixin.java new file mode 100644 index 0000000..f4f8bec --- /dev/null +++ b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/reintroduceLlamaItemDuping/PlayerManagerMixin.java @@ -0,0 +1,105 @@ +package com.keuin.ohmyvanillamc.mixins.rule.reintroduceLlamaItemDuping; + +import com.keuin.ohmyvanillamc.OmvmSettings; +import net.minecraft.advancement.PlayerAdvancementTracker; +import net.minecraft.entity.Entity; +import net.minecraft.network.Packet; +import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.PlayerManager; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.stat.ServerStatHandler; +import net.minecraft.stat.Stats; +import org.apache.logging.log4j.Logger; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +/** + * Reintroduce MC-161754 glitch + */ +@Mixin(PlayerManager.class) +public abstract class PlayerManagerMixin { + + @Shadow + protected abstract void savePlayerData(ServerPlayerEntity player); + + @Shadow + @Final + private static Logger LOGGER; + + @Shadow + @Final + private List players; + + @Shadow + @Final + private MinecraftServer server; + + @Shadow + @Final + private Map playerMap; + + @Shadow + @Final + private Map statisticsMap; + + @Shadow + @Final + private Map advancementTrackers; + + @Shadow + public abstract void sendToAll(Packet packet); + + /** + * @reason re-introduce llama item duplicating glitch. + * @author trueKeuin + */ + @Overwrite + public void remove(ServerPlayerEntity player) { + ServerWorld serverWorld = player.getServerWorld(); + player.incrementStat(Stats.LEAVE_GAME); + this.savePlayerData(player); + if (player.hasVehicle()) { + Entity entity = player.getRootVehicle(); + if (entity.hasPlayerRider()) { + LOGGER.debug("Removing player mount"); + player.stopRiding(); + serverWorld.removeEntity(entity); + // entity.removed = true + entity.removed = !OmvmSettings.reintroduceLlamaItemDuplicating || entity.removed; + + Entity entity2; + for (Iterator var4 = entity.getPassengersDeep().iterator(); var4.hasNext(); // entity2.removed = true + entity2.removed = !OmvmSettings.reintroduceLlamaItemDuplicating || entity2.removed) { + entity2 = (Entity) var4.next(); + serverWorld.removeEntity(entity2); + } + + serverWorld.getChunk(player.chunkX, player.chunkZ).markDirty(); + } + } + + player.detach(); + serverWorld.removePlayer(player); + player.getAdvancementTracker().clearCriteria(); + this.players.remove(player); + this.server.getBossBarManager().onPlayerDisconnect(player); + UUID uUID = player.getUuid(); + ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity) this.playerMap.get(uUID); + if (serverPlayerEntity == player) { + this.playerMap.remove(uUID); + this.statisticsMap.remove(uUID); + this.advancementTrackers.remove(uUID); + } + + this.sendToAll(new PlayerListS2CPacket(PlayerListS2CPacket.Action.REMOVE_PLAYER, player)); + } +} -- cgit v1.2.3