diff --git a/patches/server/0208-Config-for-grindstones.patch b/patches/server/0208-Config-for-grindstones.patch deleted file mode 100644 index 4d35d1355..000000000 --- a/patches/server/0208-Config-for-grindstones.patch +++ /dev/null @@ -1,160 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Encode42 -Date: Wed, 29 Sep 2021 13:37:57 -0400 -Subject: [PATCH] Config for grindstones - - -diff --git a/net/minecraft/world/inventory/GrindstoneMenu.java b/net/minecraft/world/inventory/GrindstoneMenu.java -index 5687f492fc76f699e2a388790ca5380d9b8c8d0a..cc229f3e1e9527cbedf929e326731943bb513dae 100644 ---- a/net/minecraft/world/inventory/GrindstoneMenu.java -+++ b/net/minecraft/world/inventory/GrindstoneMenu.java -@@ -135,7 +135,7 @@ public class GrindstoneMenu extends AbstractContainerMenu { - Holder holder = (Holder) entry.getKey(); - int k = entry.getIntValue(); - -- if (!holder.is(EnchantmentTags.CURSE)) { -+ if (!org.purpurmc.purpur.PurpurConfig.grindstoneIgnoredEnchants.contains(holder.value())) { // Purpur - j += ((Enchantment) holder.value()).getMinCost(k); - } - } -@@ -222,7 +222,7 @@ public class GrindstoneMenu extends AbstractContainerMenu { - Entry> entry = (Entry) iterator.next(); - Holder holder = (Holder) entry.getKey(); - -- if (!holder.is(EnchantmentTags.CURSE) || itemenchantments_a.getLevel(holder) == 0) { -+ if (!org.purpurmc.purpur.PurpurConfig.grindstoneIgnoredEnchants.contains(holder.value()) || itemenchantments_a.getLevel(holder) == 0) { // Purpur - itemenchantments_a.upgrade(holder, entry.getIntValue()); - } - } -@@ -230,10 +230,70 @@ public class GrindstoneMenu extends AbstractContainerMenu { - }); - } - -+ // Purpur start -+ private java.util.List> GRINDSTONE_REMOVE_ATTRIBUTES_REMOVAL_LIST = java.util.List.of( -+ // DataComponents.MAX_STACK_SIZE, -+ // DataComponents.DAMAGE, -+ // DataComponents.BLOCK_STATE, -+ DataComponents.CUSTOM_DATA, -+ // DataComponents.MAX_DAMAGE, -+ // DataComponents.UNBREAKABLE, -+ // DataComponents.CUSTOM_NAME, -+ // DataComponents.ITEM_NAME, -+ // DataComponents.LORE, -+ // DataComponents.RARITY, -+ // DataComponents.ENCHANTMENTS, -+ // DataComponents.CAN_PLACE_ON, -+ // DataComponents.CAN_BREAK, -+ DataComponents.ATTRIBUTE_MODIFIERS, -+ DataComponents.CUSTOM_MODEL_DATA, -+ // DataComponents.HIDE_ADDITIONAL_TOOLTIP, -+ // DataComponents.HIDE_TOOLTIP, -+ // DataComponents.REPAIR_COST, -+ // DataComponents.CREATIVE_SLOT_LOCK, -+ // DataComponents.ENCHANTMENT_GLINT_OVERRIDE, -+ // DataComponents.INTANGIBLE_PROJECTILE, -+ // DataComponents.FOOD, -+ // DataComponents.FIRE_RESISTANT, -+ // DataComponents.TOOL, -+ // DataComponents.STORED_ENCHANTMENTS, -+ DataComponents.DYED_COLOR, -+ // DataComponents.MAP_COLOR, -+ // DataComponents.MAP_ID, -+ // DataComponents.MAP_DECORATIONS, -+ // DataComponents.MAP_POST_PROCESSING, -+ // DataComponents.CHARGED_PROJECTILES, -+ // DataComponents.BUNDLE_CONTENTS, -+ // DataComponents.POTION_CONTENTS, -+ DataComponents.SUSPICIOUS_STEW_EFFECTS -+ // DataComponents.WRITABLE_BOOK_CONTENT, -+ // DataComponents.WRITTEN_BOOK_CONTENT, -+ // DataComponents.TRIM, -+ // DataComponents.DEBUG_STICK_STATE, -+ // DataComponents.ENTITY_DATA, -+ // DataComponents.BUCKET_ENTITY_DATA, -+ // DataComponents.BLOCK_ENTITY_DATA, -+ // DataComponents.INSTRUMENT, -+ // DataComponents.OMINOUS_BOTTLE_AMPLIFIER, -+ // DataComponents.RECIPES, -+ // DataComponents.LODESTONE_TRACKER, -+ // DataComponents.FIREWORK_EXPLOSION, -+ // DataComponents.FIREWORKS, -+ // DataComponents.PROFILE, -+ // DataComponents.NOTE_BLOCK_SOUND, -+ // DataComponents.BANNER_PATTERNS, -+ // DataComponents.BASE_COLOR, -+ // DataComponents.POT_DECORATIONS, -+ // DataComponents.CONTAINER, -+ // DataComponents.BEES, -+ // DataComponents.LOCK, -+ // DataComponents.CONTAINER_LOOT, -+ ); -+ // Purpur end - private ItemStack removeNonCursesFrom(ItemStack item) { - ItemEnchantments itemenchantments = EnchantmentHelper.updateEnchantments(item, (itemenchantments_a) -> { - itemenchantments_a.removeIf((holder) -> { -- return !holder.is(EnchantmentTags.CURSE); -+ return !org.purpurmc.purpur.PurpurConfig.grindstoneIgnoredEnchants.contains(holder.value()); // Purpur - }); - }); - -@@ -248,6 +308,23 @@ public class GrindstoneMenu extends AbstractContainerMenu { - } - - item.set(DataComponents.REPAIR_COST, i); -+ -+ // Purpur start -+ net.minecraft.core.component.DataComponentPatch.Builder builder = net.minecraft.core.component.DataComponentPatch.builder(); -+ if (org.purpurmc.purpur.PurpurConfig.grindstoneRemoveAttributes) { -+ item.getComponents().forEach(typedDataComponent -> { -+ if (GRINDSTONE_REMOVE_ATTRIBUTES_REMOVAL_LIST.contains(typedDataComponent.type())) { -+ builder.remove(typedDataComponent.type()); -+ } -+ }); -+ } -+ if (org.purpurmc.purpur.PurpurConfig.grindstoneRemoveDisplay) { -+ builder.remove(DataComponents.CUSTOM_NAME); -+ builder.remove(DataComponents.LORE); -+ } -+ item.applyComponents(builder.build()); -+ // Purpur end -+ - return item; - } - -diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java -index 639b534982547beede11654edc2ed719c66709b6..82903b6ce4cf30b2d95001455ee4e3a454b3ddd5 100644 ---- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java -+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java -@@ -312,6 +312,9 @@ public class PurpurConfig { - public static int beeInsideBeeHive = 3; - public static boolean anvilCumulativeCost = true; - public static int lightningRodRange = 128; -+ public static Set grindstoneIgnoredEnchants = new HashSet<>(); -+ public static boolean grindstoneRemoveAttributes = false; -+ public static boolean grindstoneRemoveDisplay = false; - private static void blockSettings() { - if (version < 3) { - boolean oldValue = getBoolean("settings.barrel.packed-barrels", true); -@@ -346,6 +349,21 @@ public class PurpurConfig { - beeInsideBeeHive = getInt("settings.blocks.beehive.max-bees-inside", beeInsideBeeHive); - anvilCumulativeCost = getBoolean("settings.blocks.anvil.cumulative-cost", anvilCumulativeCost); - lightningRodRange = getInt("settings.blocks.lightning_rod.range", lightningRodRange); -+ ArrayList defaultCurses = new ArrayList<>(){{ -+ add("minecraft:binding_curse"); -+ add("minecraft:vanishing_curse"); -+ }}; -+ if (version < 24 && !getBoolean("settings.blocks.grindstone.ignore-curses", true)) { -+ defaultCurses.clear(); -+ } -+ getList("settings.blocks.grindstone.ignored-enchants", defaultCurses).forEach(key -> { -+ Registry registry = MinecraftServer.getServer().registryAccess().lookupOrThrow(Registries.ENCHANTMENT); -+ Enchantment enchantment = registry.getValue(ResourceLocation.parse(key.toString())); -+ if (enchantment == null) return; -+ grindstoneIgnoredEnchants.add(enchantment); -+ }); -+ grindstoneRemoveAttributes = getBoolean("settings.blocks.grindstone.remove-attributes", grindstoneRemoveAttributes); -+ grindstoneRemoveDisplay = getBoolean("settings.blocks.grindstone.remove-name-and-lore", grindstoneRemoveDisplay); - } - - public static boolean allowInapplicableEnchants = false; diff --git a/purpur-server/minecraft-patches/sources/net/minecraft/world/inventory/GrindstoneMenu.java.patch b/purpur-server/minecraft-patches/sources/net/minecraft/world/inventory/GrindstoneMenu.java.patch new file mode 100644 index 000000000..378fe77cc --- /dev/null +++ b/purpur-server/minecraft-patches/sources/net/minecraft/world/inventory/GrindstoneMenu.java.patch @@ -0,0 +1,113 @@ +--- a/net/minecraft/world/inventory/GrindstoneMenu.java ++++ b/net/minecraft/world/inventory/GrindstoneMenu.java +@@ -124,7 +_,7 @@ + for (Entry> entry : enchantmentsForCrafting.entrySet()) { + Holder holder = entry.getKey(); + int intValue = entry.getIntValue(); +- if (!holder.is(EnchantmentTags.CURSE)) { ++ if (!org.purpurmc.purpur.PurpurConfig.grindstoneIgnoredEnchants.contains(holder.value())) { // Purpur - Config for grindstones + i += holder.value().getMinCost(intValue); + } + } +@@ -202,15 +_,75 @@ + + for (Entry> entry : enchantmentsForCrafting.entrySet()) { + Holder holder = entry.getKey(); +- if (!holder.is(EnchantmentTags.CURSE) || mutable.getLevel(holder) == 0) { ++ if (!org.purpurmc.purpur.PurpurConfig.grindstoneIgnoredEnchants.contains(holder.value()) || mutable.getLevel(holder) == 0) { // Purpur - Config for grindstones + mutable.upgrade(holder, entry.getIntValue()); + } + } + }); + } + ++ // Purpur start - Config for grindstones ++ private java.util.List> GRINDSTONE_REMOVE_ATTRIBUTES_REMOVAL_LIST = java.util.List.of( ++ // DataComponents.MAX_STACK_SIZE, ++ // DataComponents.DAMAGE, ++ // DataComponents.BLOCK_STATE, ++ DataComponents.CUSTOM_DATA, ++ // DataComponents.MAX_DAMAGE, ++ // DataComponents.UNBREAKABLE, ++ // DataComponents.CUSTOM_NAME, ++ // DataComponents.ITEM_NAME, ++ // DataComponents.LORE, ++ // DataComponents.RARITY, ++ // DataComponents.ENCHANTMENTS, ++ // DataComponents.CAN_PLACE_ON, ++ // DataComponents.CAN_BREAK, ++ DataComponents.ATTRIBUTE_MODIFIERS, ++ DataComponents.CUSTOM_MODEL_DATA, ++ // DataComponents.HIDE_ADDITIONAL_TOOLTIP, ++ // DataComponents.HIDE_TOOLTIP, ++ // DataComponents.REPAIR_COST, ++ // DataComponents.CREATIVE_SLOT_LOCK, ++ // DataComponents.ENCHANTMENT_GLINT_OVERRIDE, ++ // DataComponents.INTANGIBLE_PROJECTILE, ++ // DataComponents.FOOD, ++ // DataComponents.FIRE_RESISTANT, ++ // DataComponents.TOOL, ++ // DataComponents.STORED_ENCHANTMENTS, ++ DataComponents.DYED_COLOR, ++ // DataComponents.MAP_COLOR, ++ // DataComponents.MAP_ID, ++ // DataComponents.MAP_DECORATIONS, ++ // DataComponents.MAP_POST_PROCESSING, ++ // DataComponents.CHARGED_PROJECTILES, ++ // DataComponents.BUNDLE_CONTENTS, ++ // DataComponents.POTION_CONTENTS, ++ DataComponents.SUSPICIOUS_STEW_EFFECTS ++ // DataComponents.WRITABLE_BOOK_CONTENT, ++ // DataComponents.WRITTEN_BOOK_CONTENT, ++ // DataComponents.TRIM, ++ // DataComponents.DEBUG_STICK_STATE, ++ // DataComponents.ENTITY_DATA, ++ // DataComponents.BUCKET_ENTITY_DATA, ++ // DataComponents.BLOCK_ENTITY_DATA, ++ // DataComponents.INSTRUMENT, ++ // DataComponents.OMINOUS_BOTTLE_AMPLIFIER, ++ // DataComponents.RECIPES, ++ // DataComponents.LODESTONE_TRACKER, ++ // DataComponents.FIREWORK_EXPLOSION, ++ // DataComponents.FIREWORKS, ++ // DataComponents.PROFILE, ++ // DataComponents.NOTE_BLOCK_SOUND, ++ // DataComponents.BANNER_PATTERNS, ++ // DataComponents.BASE_COLOR, ++ // DataComponents.POT_DECORATIONS, ++ // DataComponents.CONTAINER, ++ // DataComponents.BEES, ++ // DataComponents.LOCK, ++ // DataComponents.CONTAINER_LOOT, ++ ); ++ // Purpur end - Config for grindstones + private ItemStack removeNonCursesFrom(ItemStack item) { +- ItemEnchantments itemEnchantments = EnchantmentHelper.updateEnchantments(item, mutable -> mutable.removeIf(holder -> !holder.is(EnchantmentTags.CURSE))); ++ ItemEnchantments itemEnchantments = EnchantmentHelper.updateEnchantments(item, mutable -> mutable.removeIf(holder -> !org.purpurmc.purpur.PurpurConfig.grindstoneIgnoredEnchants.contains(holder.value()))); // Purpur - Config for grindstones + if (item.is(Items.ENCHANTED_BOOK) && itemEnchantments.isEmpty()) { + item = item.transmuteCopy(Items.BOOK); + } +@@ -222,6 +_,23 @@ + } + + item.set(DataComponents.REPAIR_COST, i); ++ ++ // Purpur start - Config for grindstones ++ net.minecraft.core.component.DataComponentPatch.Builder builder = net.minecraft.core.component.DataComponentPatch.builder(); ++ if (org.purpurmc.purpur.PurpurConfig.grindstoneRemoveAttributes) { ++ item.getComponents().forEach(typedDataComponent -> { ++ if (GRINDSTONE_REMOVE_ATTRIBUTES_REMOVAL_LIST.contains(typedDataComponent.type())) { ++ builder.remove(typedDataComponent.type()); ++ } ++ }); ++ } ++ if (org.purpurmc.purpur.PurpurConfig.grindstoneRemoveDisplay) { ++ builder.remove(DataComponents.CUSTOM_NAME); ++ builder.remove(DataComponents.LORE); ++ } ++ item.applyComponents(builder.build()); ++ // Purpur end - Config for grindstones ++ + return item; + } + diff --git a/purpur-server/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/purpur-server/src/main/java/org/purpurmc/purpur/PurpurConfig.java index 3f67731c2..18d68e604 100644 --- a/purpur-server/src/main/java/org/purpurmc/purpur/PurpurConfig.java +++ b/purpur-server/src/main/java/org/purpurmc/purpur/PurpurConfig.java @@ -2,11 +2,18 @@ package org.purpurmc.purpur; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; import net.kyori.adventure.bossbar.BossBar; import net.kyori.adventure.text.minimessage.MiniMessage; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.world.entity.EntityDimensions; import net.minecraft.world.entity.EntityType; +import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockBehaviour; import org.bukkit.Bukkit; @@ -297,6 +304,9 @@ public class PurpurConfig { public static int beeInsideBeeHive = 3; public static boolean anvilCumulativeCost = true; public static int lightningRodRange = 128; + public static Set grindstoneIgnoredEnchants = new HashSet<>(); + public static boolean grindstoneRemoveAttributes = false; + public static boolean grindstoneRemoveDisplay = false; private static void blockSettings() { if (version < 3) { boolean oldValue = getBoolean("settings.barrel.packed-barrels", true); @@ -331,6 +341,21 @@ public class PurpurConfig { beeInsideBeeHive = getInt("settings.blocks.beehive.max-bees-inside", beeInsideBeeHive); anvilCumulativeCost = getBoolean("settings.blocks.anvil.cumulative-cost", anvilCumulativeCost); lightningRodRange = getInt("settings.blocks.lightning_rod.range", lightningRodRange); + ArrayList defaultCurses = new ArrayList<>(){{ + add("minecraft:binding_curse"); + add("minecraft:vanishing_curse"); + }}; + if (version < 24 && !getBoolean("settings.blocks.grindstone.ignore-curses", true)) { + defaultCurses.clear(); + } + getList("settings.blocks.grindstone.ignored-enchants", defaultCurses).forEach(key -> { + Registry registry = MinecraftServer.getServer().registryAccess().lookupOrThrow(Registries.ENCHANTMENT); + Enchantment enchantment = registry.getValue(ResourceLocation.parse(key.toString())); + if (enchantment == null) return; + grindstoneIgnoredEnchants.add(enchantment); + }); + grindstoneRemoveAttributes = getBoolean("settings.blocks.grindstone.remove-attributes", grindstoneRemoveAttributes); + grindstoneRemoveDisplay = getBoolean("settings.blocks.grindstone.remove-name-and-lore", grindstoneRemoveDisplay); } public static boolean allowInapplicableEnchants = false;