From 73687795b8fb8047f65bf75bc425f1c2187546fd Mon Sep 17 00:00:00 2001 From: FX Date: Mon, 24 May 2021 09:30:33 -0400 Subject: [PATCH] Full Preset System Done Fixed blockCollisionCheckFix affecting other entities causing things such as falling sand not duping xD --- .../java/carpetfixes/CarpetFixesServer.java | 22 +++++++- .../java/carpetfixes/CarpetFixesSettings.java | 54 ++---------------- .../java/carpetfixes/helpers/RulePresets.java | 56 ++++++++++++------- .../Entity_blockCollisionMixin.java | 3 +- 4 files changed, 63 insertions(+), 72 deletions(-) diff --git a/src/main/java/carpetfixes/CarpetFixesServer.java b/src/main/java/carpetfixes/CarpetFixesServer.java index 235c465a..26a03deb 100644 --- a/src/main/java/carpetfixes/CarpetFixesServer.java +++ b/src/main/java/carpetfixes/CarpetFixesServer.java @@ -2,10 +2,14 @@ import carpet.CarpetExtension; import carpet.CarpetServer; +import carpetfixes.helpers.RulePresets; import net.fabricmc.api.ModInitializer; +import net.minecraft.server.MinecraftServer; public class CarpetFixesServer implements CarpetExtension, ModInitializer { + public static boolean initialPreset = true; + @Override public String version() { @@ -18,9 +22,23 @@ public String version() @Override public void onGameStarted() { CarpetServer.settingsManager.parseSettingsClass(CarpetFixesSettings.class); + } + + @Override + public void onServerLoaded(MinecraftServer server) { + if (initialPreset) { + initialPreset = false; + RulePresets.runChangePresetRule(CarpetServer.minecraft_server.getCommandSource(), (CarpetFixesSettings.PresetSettings) CarpetServer.settingsManager.getRule("carpetFixesPreset").get()); + } + } + + @Override + public void onServerLoadedWorlds(MinecraftServer minecraftServer) { CarpetServer.settingsManager.addRuleObserver(((source, rule, s) -> { - if (!rule.name.equals("carpetFixesPreset") && rule.categories.contains("carpet-fixes") && !CarpetServer.settingsManager.getRule("carpetFixesPreset").equals(CarpetFixesSettings.PresetSettings.CUSTOM)) { - CarpetServer.settingsManager.getRule("carpetFixesPreset").set(source,"custom"); + if (rule.name.equals("carpetFixesPreset")) { + RulePresets.runChangePresetRule(CarpetServer.minecraft_server.getCommandSource(), (CarpetFixesSettings.PresetSettings) rule.get()); + } else if (!source.getName().equals("Server") && rule.categories.contains("carpet-fixes") && !CarpetServer.settingsManager.getRule("carpetFixesPreset").equals(CarpetFixesSettings.PresetSettings.CUSTOM)) { + CarpetServer.settingsManager.getRule("carpetFixesPreset").set(source, "custom"); } })); } diff --git a/src/main/java/carpetfixes/CarpetFixesSettings.java b/src/main/java/carpetfixes/CarpetFixesSettings.java index 0b7b73c3..692382e6 100644 --- a/src/main/java/carpetfixes/CarpetFixesSettings.java +++ b/src/main/java/carpetfixes/CarpetFixesSettings.java @@ -32,21 +32,15 @@ public enum PresetSettings { CUSTOM //Default (Does not get checked) } - - public CarpetFixesSettings() { - - } - //By FX - PR0CESS @Rule( desc = "This rule allows you to change all Carpet-Fixes rules at the same time!", extra = {"Vanilla: All rules set to there default value", - "CRASHFIX: Only rules that fix Crashes are enabled", - "STABILITY: Rules that make the game stable", - "ALL: Enable all rules", - "CUSTOM: Default (Does not change commands)" + "CrashFix: Only rules that fix Crashes are enabled", + "Stability: Rules that make the game stable", + "All: Enable all rules", + "Custom: Default (Does not change commands)" }, - validate = PresetValidator.class, category = {CARPETFIXES} ) public static PresetSettings carpetFixesPreset = PresetSettings.CUSTOM; @@ -267,44 +261,4 @@ public CarpetFixesSettings() { ) public static boolean pistonDupingFix = false; - /* - - VALIDATOR'S - - */ - - private static class PresetValidator extends Validator { - @Override public PresetSettings validate(ServerCommandSource source, ParsedRule currentRule, PresetSettings newValue, String string) { - switch(newValue) { - case VANILLA: - RulePresets.setVanilla(source); - break; - case BACKPORT: - RulePresets.setBackport(source); - break; - case CRASHFIX: - RulePresets.setCrashFix(source); - break; - case STABILITY: - RulePresets.setStability(source); - break; - case NOTBACKPORTS: - RulePresets.setNotBackport(source); - break; - case ALL: - RulePresets.setAll(source); - break; - case CUSTOM: - default: - } - return newValue; - } - } - - /* - - - - */ - } diff --git a/src/main/java/carpetfixes/helpers/RulePresets.java b/src/main/java/carpetfixes/helpers/RulePresets.java index 0a956f54..38d6224f 100644 --- a/src/main/java/carpetfixes/helpers/RulePresets.java +++ b/src/main/java/carpetfixes/helpers/RulePresets.java @@ -1,19 +1,45 @@ package carpetfixes.helpers; import carpet.CarpetServer; +import carpetfixes.CarpetFixesSettings; import net.minecraft.server.command.ServerCommandSource; public class RulePresets { + public static void runChangePresetRule(ServerCommandSource source, CarpetFixesSettings.PresetSettings newValue) { + switch(newValue) { + case VANILLA: + RulePresets.setVanilla(source); + break; + case BACKPORT: + RulePresets.setBackport(source); + break; + case CRASHFIX: + RulePresets.setCrashFix(source); + break; + case STABILITY: + RulePresets.setStability(source); + break; + case NOTBACKPORTS: + RulePresets.setNotBackport(source); + break; + case ALL: + RulePresets.setAll(source); + break; + case CUSTOM: + default: + } + } + public static boolean isStabilityRuleException(String name) { - //List of rules which should count as stability even tho they don't fit the rules + //List of rules which should count as stability even tho they don't fit the requirements return name.equals("drownedMemoryLeakFix"); // || ... } public static void setAll(ServerCommandSource source) { for (carpet.settings.ParsedRule rule : CarpetServer.settingsManager.getRules()) { if (rule.categories.contains("carpet-fixes") && !rule.name.equals("carpetFixesPreset") && rule.isDefault()) { - rule.set(source, rule.getBoolValue() ? "false" : "true"); + rule.set(source, Boolean.toString(!rule.getBoolValue())); } } } @@ -21,10 +47,8 @@ public static void setAll(ServerCommandSource source) { public static void setNotBackport(ServerCommandSource source) { for (carpet.settings.ParsedRule rule : CarpetServer.settingsManager.getRules()) { if (rule.categories.contains("carpet-fixes") && !rule.name.equals("carpetFixesPreset")) { - if (rule.categories.contains("backport") && !rule.isDefault()) { - rule.set(source, rule.getBoolValue() ? "false" : "true"); - } else if (rule.isDefault()) { - rule.set(source, rule.getBoolValue() ? "false" : "true"); + if ((rule.categories.contains("backport") && !rule.isDefault()) || rule.isDefault()) { + rule.set(source, Boolean.toString(!rule.getBoolValue())); } } } @@ -33,10 +57,8 @@ public static void setNotBackport(ServerCommandSource source) { public static void setCrashFix(ServerCommandSource source) { for (carpet.settings.ParsedRule rule : CarpetServer.settingsManager.getRules()) { if (rule.categories.contains("carpet-fixes") && !rule.name.equals("carpetFixesPreset")) { - if (rule.categories.contains("crashfix") && rule.isDefault()) { - rule.set(source, rule.getBoolValue() ? "false" : "true"); - } else if (!rule.isDefault()) { - rule.set(source, rule.getBoolValue() ? "false" : "true"); + if ((rule.categories.contains("crashfix") && rule.isDefault()) || !rule.isDefault()) { + rule.set(source, Boolean.toString(!rule.getBoolValue())); } } } @@ -45,10 +67,8 @@ public static void setCrashFix(ServerCommandSource source) { public static void setBackport(ServerCommandSource source) { for (carpet.settings.ParsedRule rule : CarpetServer.settingsManager.getRules()) { if (rule.categories.contains("carpet-fixes") && !rule.name.equals("carpetFixesPreset")) { - if (rule.categories.contains("backport") && rule.isDefault()) { - rule.set(source, rule.getBoolValue() ? "false" : "true"); - } else if (!rule.isDefault()) { - rule.set(source, rule.getBoolValue() ? "false" : "true"); + if ((rule.categories.contains("backport") && rule.isDefault()) || !rule.isDefault()) { + rule.set(source, Boolean.toString(!rule.getBoolValue())); } } } @@ -58,7 +78,7 @@ public static void setVanilla(ServerCommandSource source) { for (carpet.settings.ParsedRule rule : CarpetServer.settingsManager.getRules()) { if (rule.categories.contains("carpet-fixes") && !rule.name.equals("carpetFixesPreset")) { if (!rule.isDefault()) { - rule.set(source, rule.getBoolValue() ? "false" : "true"); + rule.set(source, Boolean.toString(!rule.getBoolValue())); } } } @@ -67,10 +87,8 @@ public static void setVanilla(ServerCommandSource source) { public static void setStability(ServerCommandSource source) { for (carpet.settings.ParsedRule rule : CarpetServer.settingsManager.getRules()) { if (rule.categories.contains("carpet-fixes") && !rule.name.equals("carpetFixesPreset")) { - if (rule.isDefault() && rule.categories.contains("crashfix") || (!rule.categories.contains("backport") && !rule.categories.contains("experimental")) || isStabilityRuleException(rule.name)) { - rule.set(source, rule.getBoolValue() ? "false" : "true"); - } else if (!rule.isDefault()) { - rule.set(source, rule.getBoolValue() ? "false" : "true"); + if (rule.isDefault() && rule.categories.contains("crashfix") || (!rule.categories.contains("backport") && !rule.categories.contains("experimental")) || isStabilityRuleException(rule.name) || !rule.isDefault()) { + rule.set(source, Boolean.toString(!rule.getBoolValue())); } } } diff --git a/src/main/java/carpetfixes/mixins/entityFixes/Entity_blockCollisionMixin.java b/src/main/java/carpetfixes/mixins/entityFixes/Entity_blockCollisionMixin.java index 67ed1b05..08460c62 100644 --- a/src/main/java/carpetfixes/mixins/entityFixes/Entity_blockCollisionMixin.java +++ b/src/main/java/carpetfixes/mixins/entityFixes/Entity_blockCollisionMixin.java @@ -6,6 +6,7 @@ import net.minecraft.block.Blocks; import net.minecraft.entity.Entity; import net.minecraft.entity.MovementType; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; @@ -55,7 +56,7 @@ public boolean shouldCheckCollision(Block block) { ) public void checkBlockCollisionBetter(BlockState blockState, World world, BlockPos pos, Entity entity) { boolean pass = shouldCheckCollision(blockState.getBlock()); - if (!CarpetFixesSettings.blockCollisionCheckFix || (first && pass) || (!first && !pass)) { + if (entity instanceof PlayerEntity && (!CarpetFixesSettings.blockCollisionCheckFix || (first && pass) || (!first && !pass))) { blockState.onEntityCollision(world, pos, entity); } }