Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 12:30:06 +01:00
5c7081fecc
* Updated Upstream (Bukkit/CraftBukkit) Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 45690fe9 SPIGOT-5047: Correct slot types for 1.14 inventories CraftBukkit Changes:4090d01f
SPIGOT-5047: Correct slot types for 1.14 inventoriese8c08362
SPIGOT-5046: World#getLoadedChunks returning inaccessible cached chunks.d445af3b
SPIGOT-5067: Add item meta for 1.14 spawn eggs * Bring Chunk load checks in-line with spigot As of the last upstream merge spigot now checks ticket level status when returning loaded chunks for a world from api. Now our checks will respect that decision. * Fix spawn ticket levels Vanilla would keep the inner chunks of spawn available for ticking, however my changes made all chunks non-ticking. Resolve by changing ticket levels for spawn chunks inside the border to respect this behavior. * Make World#getChunkIfLoadedImmediately return only entity ticking chunks Mojang appears to be using chunks with level > 33 (non-ticking chunks) as cached chunks and not actually loaded chunks. * Bring all loaded checks in line with spigot Loaded chunks must be at least border chunks, or level <= 33
93 Zeilen
4.1 KiB
Diff
93 Zeilen
4.1 KiB
Diff
From fa4cb878b8a7aedf524f2f17a1357215f99f6cb7 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Wed, 20 Dec 2017 17:36:49 -0500
|
|
Subject: [PATCH] Ability to apply mending to XP API
|
|
|
|
This allows plugins that give players the ability to apply the experience
|
|
points to the Item Mending formula, which will repair an item instead
|
|
of giving the player experience points.
|
|
|
|
Both an API To standalone mend, and apply mending logic to .giveExp has been added.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EnchantmentManager.java b/src/main/java/net/minecraft/server/EnchantmentManager.java
|
|
index 6f64b8db3a..b6a40e22a8 100644
|
|
--- a/src/main/java/net/minecraft/server/EnchantmentManager.java
|
|
+++ b/src/main/java/net/minecraft/server/EnchantmentManager.java
|
|
@@ -241,6 +241,11 @@ public class EnchantmentManager {
|
|
return getEnchantmentLevel(Enchantments.CHANNELING, itemstack) > 0;
|
|
}
|
|
|
|
+ // Paper - OBFHELPER
|
|
+ public static @Nullable ItemStack getRandomEquippedItemWithEnchant(Enchantment enchantment, EntityLiving entityliving) {
|
|
+ Entry<EnumItemSlot, ItemStack> entry = b(enchantment, entityliving);
|
|
+ return entry != null ? entry.getValue() : null;
|
|
+ }
|
|
@Nullable
|
|
public static Entry<EnumItemSlot, ItemStack> b(Enchantment enchantment, EntityLiving entityliving) {
|
|
Map<EnumItemSlot, ItemStack> map = enchantment.a(entityliving);
|
|
diff --git a/src/main/java/net/minecraft/server/EntityExperienceOrb.java b/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
|
index 704a48c8ea..64d71a9a2a 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
|
@@ -251,10 +251,12 @@ public class EntityExperienceOrb extends Entity {
|
|
}
|
|
}
|
|
|
|
+ public int durToXp(int i) { return b(i); } // Paper OBFHELPER
|
|
private int b(int i) {
|
|
return i / 2;
|
|
}
|
|
|
|
+ public int xpToDur(int i) { return c(i); } // Paper OBFHELPER
|
|
private int c(int i) {
|
|
return i * 2;
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index d4fed1a512..7f1138cbbf 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -1054,8 +1054,39 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
return GameMode.getByValue(getHandle().playerInteractManager.getGameMode().getId());
|
|
}
|
|
|
|
+ // Paper start
|
|
@Override
|
|
- public void giveExp(int exp) {
|
|
+ public int applyMending(int amount) {
|
|
+ EntityPlayer handle = getHandle();
|
|
+ // Logic copied from EntityExperienceOrb and remapped to unobfuscated methods/properties
|
|
+ net.minecraft.server.ItemStack itemstack = net.minecraft.server.EnchantmentManager.getRandomEquippedItemWithEnchant(net.minecraft.server.Enchantments.MENDING, handle);
|
|
+ if (!itemstack.isEmpty() && itemstack.getItem().usesDurability()) {
|
|
+
|
|
+ net.minecraft.server.EntityExperienceOrb orb = net.minecraft.server.EntityTypes.EXPERIENCE_ORB.create(handle.world);
|
|
+ orb.value = amount;
|
|
+ orb.spawnReason = org.bukkit.entity.ExperienceOrb.SpawnReason.CUSTOM;
|
|
+ orb.locX = handle.locX;
|
|
+ orb.locY = handle.locY;
|
|
+ orb.locZ = handle.locZ;
|
|
+
|
|
+ int i = Math.min(orb.xpToDur(amount), itemstack.getDamage());
|
|
+ org.bukkit.event.player.PlayerItemMendEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemMendEvent(handle, orb, itemstack, i);
|
|
+ i = event.getRepairAmount();
|
|
+ orb.dead = true;
|
|
+ if (!event.isCancelled()) {
|
|
+ amount -= orb.durToXp(i);
|
|
+ itemstack.setDamage(itemstack.getDamage() - i);
|
|
+ }
|
|
+ }
|
|
+ return amount;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void giveExp(int exp, boolean applyMending) {
|
|
+ if (applyMending) {
|
|
+ exp = this.applyMending(exp);
|
|
+ }
|
|
+ // Paper end
|
|
getHandle().giveExp(exp);
|
|
}
|
|
|
|
--
|
|
2.21.0
|
|
|