Files
Purpur/patches/server/0240-Add-toggle-for-enchant-level-clamping.patch
granny 201e928fa6 Updated Upstream (Pufferfish) (#1575)
Upstream has released updates that appear to apply and compile correctly

Pufferfish Changes:
pufferfish-gg/Pufferfish@c9f4e20 Final 1.20.4 Update
pufferfish-gg/Pufferfish@1f3ad02 Final 1.20.4 update, for realzies
pufferfish-gg/Pufferfish@b1ab664 Enable SIMD on java 21
pufferfish-gg/Pufferfish@0674c2b 1.21 compiles
pufferfish-gg/Pufferfish@98ea973 Fix 1.21 version checkers
pufferfish-gg/Pufferfish@68f859c Fix lambda/tick guard patch
pufferfish-gg/Pufferfish@eaa18d5 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@1d72eea Updated Upstream (Paper)
pufferfish-gg/Pufferfish@1d3c743 Update pufferfish version detector stuff
pufferfish-gg/Pufferfish@5e30963 Fix crash bug
pufferfish-gg/Pufferfish@12571eb Use mojmapped paperclip jar instead (CI only)
pufferfish-gg/Pufferfish@4d16ae0 Drop a patch - moonrise includes it
pufferfish-gg/Pufferfish@52c2d05 Revert "Drop a patch - moonrise includes it"
pufferfish-gg/Pufferfish@bdb56f1 Fix entity interactions with fluids
pufferfish-gg/Pufferfish@469e5c1 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@d75961f 1.21.1 Update (Updated Upstream (Paper))
2024-08-15 14:07:11 -07:00

81 lines
5.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: 12emin34 <macanovic.emin@gmail.com>
Date: Sat, 30 Apr 2022 10:32:40 +0200
Subject: [PATCH] Add toggle for enchant level clamping
diff --git a/src/main/java/net/minecraft/server/Main.java b/src/main/java/net/minecraft/server/Main.java
index 581bd217304e0f9e0b2113c335694805dfb4e2a1..85a0a07707a2b4029879b8caea79ded4bd849dab 100644
--- a/src/main/java/net/minecraft/server/Main.java
+++ b/src/main/java/net/minecraft/server/Main.java
@@ -120,6 +120,11 @@ public class Main {
JvmProfiler.INSTANCE.start(Environment.SERVER);
}
+ // Purpur start - load config files early
+ org.bukkit.configuration.file.YamlConfiguration purpurConfiguration = io.papermc.paper.configuration.PaperConfigurations.loadLegacyConfigFile((File) optionset.valueOf("purpur-settings"));
+ org.purpurmc.purpur.PurpurConfig.clampEnchantLevels = purpurConfiguration.getBoolean("settings.enchantment.clamp-levels");
+ // Purpur end - load config files early
+
io.papermc.paper.plugin.PluginInitializerManager.load(optionset); // Paper
Bootstrap.bootStrap();
Bootstrap.validate();
diff --git a/src/main/java/net/minecraft/world/item/enchantment/ItemEnchantments.java b/src/main/java/net/minecraft/world/item/enchantment/ItemEnchantments.java
index 8ac485d82c2d2b32f4d54e02c18c2cb2c3df4fa4..9ebe6a5f31ceacd33d9c111966ad941b535b4e67 100644
--- a/src/main/java/net/minecraft/world/item/enchantment/ItemEnchantments.java
+++ b/src/main/java/net/minecraft/world/item/enchantment/ItemEnchantments.java
@@ -35,7 +35,7 @@ public class ItemEnchantments implements TooltipProvider {
private static final java.util.Comparator<Holder<Enchantment>> ENCHANTMENT_ORDER = java.util.Comparator.comparing(Holder::getRegisteredName);
public static final ItemEnchantments EMPTY = new ItemEnchantments(new Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER), true);
// Paper end
- private static final Codec<Integer> LEVEL_CODEC = Codec.intRange(0, 255);
+ private static final Codec<Integer> LEVEL_CODEC = Codec.intRange(0, (org.purpurmc.purpur.PurpurConfig.clampEnchantLevels ? 255 : 32767)); // Purpur
private static final Codec<Object2IntAVLTreeMap<Holder<Enchantment>>> LEVELS_CODEC = Codec.unboundedMap(
Enchantment.CODEC, LEVEL_CODEC
)// Paper start - sort enchantments
@@ -69,7 +69,7 @@ public class ItemEnchantments implements TooltipProvider {
for (Entry<Holder<Enchantment>> entry : enchantments.object2IntEntrySet()) {
int i = entry.getIntValue();
- if (i < 0 || i > 255) {
+ if (i < 0 || i > (org.purpurmc.purpur.PurpurConfig.clampEnchantLevels ? 255 : 32767)) { // Purpur
throw new IllegalArgumentException("Enchantment " + entry.getKey() + " has invalid level " + i);
}
}
@@ -166,13 +166,13 @@ public class ItemEnchantments implements TooltipProvider {
if (level <= 0) {
this.enchantments.removeInt(enchantment);
} else {
- this.enchantments.put(enchantment, Math.min(level, 255));
+ this.enchantments.put(enchantment, Math.min(level, (org.purpurmc.purpur.PurpurConfig.clampEnchantLevels ? 255 : 32767))); // Purpur
}
}
public void upgrade(Holder<Enchantment> enchantment, int level) {
if (level > 0) {
- this.enchantments.merge(enchantment, Math.min(level, 255), Integer::max);
+ this.enchantments.merge(enchantment, Math.min(level, (org.purpurmc.purpur.PurpurConfig.clampEnchantLevels ? 255 : 32767)), Integer::max); // Purpur
}
}
diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
index da1be83cec7c92a75f345a8879520503c563d280..8569054673f43a339694dec3bc02eb05019a5571 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
@@ -400,6 +400,7 @@ public class PurpurConfig {
public static boolean allowHigherEnchantsLevels = true;
public static boolean allowUnsafeEnchantCommand = false;
public static boolean replaceIncompatibleEnchants = false;
+ public static boolean clampEnchantLevels = true;
private static void enchantmentSettings() {
if (version < 30) {
boolean oldValue = getBoolean("settings.enchantment.allow-unsafe-enchants", false);
@@ -416,6 +417,7 @@ public class PurpurConfig {
allowHigherEnchantsLevels = getBoolean("settings.enchantment.anvil.allow-higher-enchants-levels", allowHigherEnchantsLevels);
allowUnsafeEnchantCommand = getBoolean("settings.enchantment.allow-unsafe-enchant-command", allowUnsafeEnchants); // allowUnsafeEnchants as default for backwards compatability
replaceIncompatibleEnchants = getBoolean("settings.enchantment.anvil.replace-incompatible-enchants", replaceIncompatibleEnchants);
+ clampEnchantLevels = getBoolean("settings.enchantment.clamp-levels", clampEnchantLevels);
}
public static boolean endermanShortHeight = false;