2024-10-12 23:10:05 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Doc <nachito94@msn.com>
|
|
|
|
Date: Sun, 6 Oct 2024 16:46:36 -0300
|
|
|
|
Subject: [PATCH] Add AnvilView#bypassEnchantmentLevelRestriction
|
|
|
|
|
|
|
|
Anvils, by default, limit applied enchantment levels to their respective
|
|
|
|
maximum level. The added API enables plugins to disable this behaviour,
|
|
|
|
allowing enchantments that are overleveled to be applied via the anvil.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/AnvilMenu.java b/src/main/java/net/minecraft/world/inventory/AnvilMenu.java
|
Rework async chunk api implementation
Firstly, the old methods all routed to the CompletableFuture method.
However, the CF method could not guarantee that if the caller
was off-main that the future would be "completed" on-main. Since
the callback methods used the CF one, this meant that the callback
methods did not guarantee that the callbacks were to be called on
the main thread.
Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb)
so that the methods with the callback are guaranteed to invoke
the callback on the main thread. The CF behavior remains unchanged;
it may still appear to complete on main if invoked off-main.
Secondly, remove the scheduleOnMain invocation in the async
chunk completion. This unnecessarily delays the callback
by 1 tick.
Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which
will load chunks within an area. This method is provided as a helper
as keeping all chunks loaded within an area can be complicated to
implement for plugins (due to the lacking ticket API), and is
already implemented internally anyways.
Fourthly, remove the ticket addition that occured with getChunkAt
and getChunkAtAsync. The ticket addition may delay the unloading
of the chunk unnecessarily. It also fixes a very rare timing bug
where the future/callback would be completed after the chunk
unloads.
2024-11-19 07:34:32 +01:00
|
|
|
index ae0ba6b0e1f0bee3c3a701b22725171e499b97a3..286ae002e1711ad9e800b7f2091988d66cd572a7 100644
|
2024-10-12 23:10:05 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/inventory/AnvilMenu.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/inventory/AnvilMenu.java
|
2024-10-25 12:28:34 +02:00
|
|
|
@@ -54,6 +54,7 @@ public class AnvilMenu extends ItemCombinerMenu {
|
2024-10-12 23:10:05 +02:00
|
|
|
public int maximumRepairCost = 40;
|
|
|
|
private CraftAnvilView bukkitEntity;
|
|
|
|
// CraftBukkit end
|
|
|
|
+ public boolean bypassEnchantmentLevelRestriction = false; // Paper - bypass anvil level restrictions
|
|
|
|
|
|
|
|
public AnvilMenu(int syncId, Inventory inventory) {
|
|
|
|
this(syncId, inventory, ContainerLevelAccess.NULL);
|
2024-10-25 12:28:34 +02:00
|
|
|
@@ -233,7 +234,7 @@ public class AnvilMenu extends ItemCombinerMenu {
|
2024-10-12 23:10:05 +02:00
|
|
|
flag2 = true;
|
|
|
|
} else {
|
|
|
|
flag1 = true;
|
|
|
|
- if (i2 > enchantment.getMaxLevel()) {
|
|
|
|
+ if (i2 > enchantment.getMaxLevel() && !this.bypassEnchantmentLevelRestriction) { // Paper - bypass anvil level restrictions
|
|
|
|
i2 = enchantment.getMaxLevel();
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/view/CraftAnvilView.java b/src/main/java/org/bukkit/craftbukkit/inventory/view/CraftAnvilView.java
|
2024-10-21 00:06:54 +02:00
|
|
|
index fdc2bd4c3ee5f762a72df39c87215e3a15f47db2..f86c95a13dff012de5db3e41ac261e9e8d44d9f3 100644
|
2024-10-12 23:10:05 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/view/CraftAnvilView.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/view/CraftAnvilView.java
|
2024-10-21 00:06:54 +02:00
|
|
|
@@ -50,6 +50,18 @@ public class CraftAnvilView extends CraftInventoryView<AnvilMenu, AnvilInventory
|
2024-10-12 23:10:05 +02:00
|
|
|
this.container.maximumRepairCost = cost;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ @Override
|
|
|
|
+ public boolean bypassesEnchantmentLevelRestriction() {
|
|
|
|
+ return this.container.bypassEnchantmentLevelRestriction;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void bypassEnchantmentLevelRestriction(final boolean bypassEnchantmentLevelRestriction) {
|
|
|
|
+ this.container.bypassEnchantmentLevelRestriction = bypassEnchantmentLevelRestriction;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
public void updateFromLegacy(CraftInventoryAnvil legacy) {
|
|
|
|
if (legacy.isRepairCostSet()) {
|
|
|
|
this.setRepairCost(legacy.getRepairCost());
|