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/src/main/java/net/minecraft/world/inventory/GrindstoneMenu.java b/src/main/java/net/minecraft/world/inventory/GrindstoneMenu.java index db9444dda248260372d96ce239a590e88a4c1142..5824636332eb35ae6bee9cc0661ee95901bb8c4b 100644 --- a/src/main/java/net/minecraft/world/inventory/GrindstoneMenu.java +++ b/src/main/java/net/minecraft/world/inventory/GrindstoneMenu.java @@ -130,7 +130,7 @@ public class GrindstoneMenu extends AbstractContainerMenu { Enchantment enchantment = (Enchantment) ((Holder) entry.getKey()).value(); int k = entry.getIntValue(); - if (!enchantment.isCurse()) { + if (!org.purpurmc.purpur.PurpurConfig.grindstoneIgnoredEnchants.contains(enchantment)) { // Purpur j += enchantment.getMinCost(k); } } @@ -229,7 +229,7 @@ public class GrindstoneMenu extends AbstractContainerMenu { Entry> entry = (Entry) iterator.next(); Enchantment enchantment = (Enchantment) ((Holder) entry.getKey()).value(); - if (!enchantment.isCurse() || itemenchantments_a.getLevel(enchantment) == 0) { + if (!org.purpurmc.purpur.PurpurConfig.grindstoneIgnoredEnchants.contains(enchantment) || itemenchantments_a.getLevel(enchantment) == 0) { // Purpur itemenchantments_a.upgrade(enchantment, entry.getIntValue()); } } @@ -237,10 +237,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 !((Enchantment) holder.value()).isCurse(); + return !org.purpurmc.purpur.PurpurConfig.grindstoneIgnoredEnchants.contains(holder.value()); }); }); @@ -255,6 +315,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 b56afa30c04350b5e9ca4ea2d33f9e7c58559380..7f0a9a239791cfb1d721d24f907b89ae2dd4c64a 100644 --- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java +++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java @@ -309,6 +309,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); @@ -343,6 +346,19 @@ 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 -> { + Enchantment enchantment = BuiltInRegistries.ENCHANTMENT.get(new ResourceLocation(key.toString())); + grindstoneIgnoredEnchants.add(enchantment); + }); + grindstoneRemoveAttributes = getBoolean("settings.blocks.grindstone.remove-attributes", grindstoneRemoveAttributes); + grindstoneRemoveDisplay = getBoolean("settings.blocks.grindstone.remove-name-and-lore", grindstoneRemoveDisplay); } public static boolean allowInfinityMending = false;