mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-22 19:07:44 +01:00
Config to allow unsafe enchants
This commit is contained in:
@@ -64,15 +64,49 @@
|
||||
ItemStack itemStack = item.copy();
|
||||
ItemStack item1 = this.inputSlots.getItem(1);
|
||||
ItemEnchantments.Mutable mutable = new ItemEnchantments.Mutable(EnchantmentHelper.getEnchantmentsForCrafting(itemStack));
|
||||
@@ -198,7 +_,7 @@
|
||||
@@ -191,23 +_,36 @@
|
||||
int intValue = entry.getIntValue();
|
||||
intValue = level == intValue ? intValue + 1 : Math.max(intValue, level);
|
||||
Enchantment enchantment = holder.value();
|
||||
- boolean canEnchant = enchantment.canEnchant(item);
|
||||
+ // Purpur start - Config to allow unsafe enchants
|
||||
+ boolean canEnchant = this.canDoUnsafeEnchants || org.purpurmc.purpur.PurpurConfig.allowInapplicableEnchants || enchantment.canEnchant(item); // whether the enchantment can be applied on specific item type
|
||||
+ boolean canEnchant1 = true; // whether two incompatible enchantments can be applied on a single item
|
||||
+ // Purpur end - Config to allow unsafe enchants
|
||||
if (this.player.getAbilities().instabuild || item.is(Items.ENCHANTED_BOOK)) {
|
||||
canEnchant = true;
|
||||
}
|
||||
|
||||
for (Holder<Enchantment> holder1 : mutable.keySet()) {
|
||||
- for (Holder<Enchantment> holder1 : mutable.keySet()) {
|
||||
+ // Purpur start - Config to allow unsafe enchants
|
||||
+ java.util.Iterator<Holder<Enchantment>> mutableIterator = mutable.keySet().iterator();
|
||||
+ while (mutableIterator.hasNext()) {
|
||||
+ Holder<Enchantment> holder1 = mutableIterator.next();
|
||||
+ // Purpur end - Config to allow unsafe enchants
|
||||
if (!holder1.equals(holder) && !Enchantment.areCompatible(holder, holder1)) {
|
||||
- canEnchant = false;
|
||||
+ canEnchant = this.canDoUnsafeEnchants; // Purpur - Anvil API
|
||||
i++;
|
||||
- i++;
|
||||
+ canEnchant1 = this.canDoUnsafeEnchants || org.purpurmc.purpur.PurpurConfig.allowIncompatibleEnchants; // Purpur - Anvil API // Purpur - flag3 -> canEnchant1 - Config to allow unsafe enchants
|
||||
+ // Purpur start - Config to allow unsafe enchants
|
||||
+ if (!canEnchant1 && org.purpurmc.purpur.PurpurConfig.replaceIncompatibleEnchants) {
|
||||
+ mutableIterator.remove(); // replace current enchant with the incompatible one trying to be applied // TODO: is this needed?
|
||||
+ canEnchant1 = true;
|
||||
+ }
|
||||
+ // Purpur end - Config to allow unsafe enchants
|
||||
+ ++i;
|
||||
}
|
||||
}
|
||||
|
||||
- if (!canEnchant) {
|
||||
+ if (!canEnchant || !canEnchant1) { // Purpur - Config to allow unsafe enchants
|
||||
flag1 = true;
|
||||
} else {
|
||||
flag = true;
|
||||
- if (intValue > enchantment.getMaxLevel() && !this.bypassEnchantmentLevelRestriction) { // Paper - bypass anvil level restrictions
|
||||
+ if (!org.purpurmc.purpur.PurpurConfig.allowHigherEnchantsLevels && intValue > enchantment.getMaxLevel() && !this.bypassEnchantmentLevelRestriction) { // Paper - bypass anvil level restrictions // Purpur - Config to allow unsafe enchants
|
||||
intValue = enchantment.getMaxLevel();
|
||||
}
|
||||
|
||||
@@ -236,6 +_,54 @@
|
||||
if (!this.itemName.equals(item.getHoverName().getString())) {
|
||||
i1 = 1;
|
||||
@@ -147,7 +181,7 @@
|
||||
this.broadcastChanges();
|
||||
+
|
||||
+ // Purpur start - Anvil API
|
||||
+ if (this.canDoUnsafeEnchants && itemStack != ItemStack.EMPTY) {
|
||||
+ if ((this.canDoUnsafeEnchants || org.purpurmc.purpur.PurpurConfig.allowInapplicableEnchants || org.purpurmc.purpur.PurpurConfig.allowIncompatibleEnchants) && itemStack != ItemStack.EMPTY) { // Purpur - Config to allow unsafe enchants
|
||||
+ ((ServerPlayer) this.player).connection.send(new ClientboundContainerSetSlotPacket(this.containerId, this.incrementStateId(), 2, itemStack));
|
||||
+ ((ServerPlayer) this.player).connection.send(new ClientboundContainerSetDataPacket(this.containerId, 0, this.cost.get()));
|
||||
+ }
|
||||
|
||||
@@ -27,3 +27,16 @@
|
||||
public int getDamageValue() {
|
||||
return Mth.clamp(this.getOrDefault(DataComponents.DAMAGE, Integer.valueOf(0)), 0, this.getMaxDamage());
|
||||
}
|
||||
@@ -1232,6 +_,12 @@
|
||||
public boolean isEnchanted() {
|
||||
return !this.getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY).isEmpty();
|
||||
}
|
||||
+
|
||||
+ // Purpur start - Config to allow unsafe enchants
|
||||
+ public boolean hasEnchantment(Holder<Enchantment> enchantment) {
|
||||
+ return this.getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY).getLevel(enchantment) > 0;
|
||||
+ }
|
||||
+ // Purpur end - Config to allow unsafe enchants
|
||||
|
||||
public ItemEnchantments getEnchantments() {
|
||||
return this.getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY);
|
||||
|
||||
Reference in New Issue
Block a user