mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-19 09:27:43 +01:00
Upstream has released updates that appears to apply and compile correctly Paper Changes: c8028d1c Fix data version check for ItemStack serialization (#3394) 9254a80a Fix race condition reintroduced in Prioritize class loader patch 6f196fe7 Add Raw Byte ItemStack Serialization df43f828 Allow server startup for those poor people running <1G Xmx 3c9b65ef Fix cases where no-tick < tick view distance 72f89a07 Workaround for Client Lag Spikes (MC-162253) 3f941c0c Add option for console having all permissions d2ae4658 Add permission for command blocks 9f8ae5cb Prioritise own classes where possible 74466412 Check portal restrictions when entering end gateways fc9cf84d Fix NPE when temp ip bans expire (#3373) 16bd420d Add missing mob goals for API (#3367) b5c4e2f6 Ensure no-tick view is not smaller than ticking VD 52564b1f Expand Pathfinding API with more options dde65481 Fix usage of vanilla goals 7797aebe Drop Leads from nether portals - Fixes #3226 511b6bc2 Reduce MutableInt and Vec3d allocations, use ArrayDeque 84673141 Optimize NibbleArray to use pooled buffers 897dd2c8 Foundational work for Future Memory usage improvements bb4002d8 Handle CraftPlayer#setSpectatorTarget better 4ae08959 Fix collision checks on spawning hanging entities and null on async chunk loads c2f8d1ef Protect Bedrock and End Portal/Frames from being destroyed 827cc632 Updated Upstream (Bukkit/CraftBukkit/Spigot) 92f680ed Fix Pathfinding and obscure glitchy buggy 0 tick farms 7a7c4292 Optimize Pathfinder - Remove Streams / Optimized collections fc917d16 Optimize Hoppers - Major performance improvement 14ad77c6 Fix PotionEffect API Ignoring Icon bug eb3ce8a2 Fix EntityRaider picking up items when they shouldn't be able 1ea9ada0 Add a TELEPORT ticket when changing dimensions 8e9459ea Fix missing flag pass for isUrgent 7befec44 Potential bed api (#3339) 27945a6b Optimize WorldBorder collision checks and air 55e17a85 Wait for Async Tasks during shutdown b5905256 Ensure Entity AABB's are never invalid a054aa6f Properly remove Entities from current chunk c894ddfd Fix teleporting onto a chunk line 57d6cc01 Send LOGIN protocol packets immediately - Fix disconnect during async prelogin cd93e54d Don't use our modified chunk checks for collision in world gen b4003ef1 Allow loading entities current chunk if needed to fix collision checks e5f64896 Add Urgent API for Async Chunks API and use it for Async Teleport ad8e59dc Ensure chunks loaded on respawn for suffocation check
111 lines
5.7 KiB
Diff
111 lines
5.7 KiB
Diff
From 650646daddf4a1af505b0dd966ccc2414b583ffd Mon Sep 17 00:00:00 2001
|
|
From: William Blake Galbreath <blake.galbreath@gmail.com>
|
|
Date: Sun, 14 Jul 2019 19:52:47 -0500
|
|
Subject: [PATCH] Mending mends most damages equipment first
|
|
|
|
---
|
|
.../minecraft/server/EnchantmentManager.java | 25 ++++++++++++++++++-
|
|
.../minecraft/server/EntityExperienceOrb.java | 2 +-
|
|
.../java/net/minecraft/server/ItemStack.java | 9 +++++++
|
|
.../net/pl3x/purpur/PurpurWorldConfig.java | 2 ++
|
|
4 files changed, 36 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EnchantmentManager.java b/src/main/java/net/minecraft/server/EnchantmentManager.java
|
|
index d96c03a1a..da1cfc1d3 100644
|
|
--- a/src/main/java/net/minecraft/server/EnchantmentManager.java
|
|
+++ b/src/main/java/net/minecraft/server/EnchantmentManager.java
|
|
@@ -246,9 +246,32 @@ public class EnchantmentManager {
|
|
return getEnchantmentLevel(Enchantments.CHANNELING, itemstack) > 0;
|
|
}
|
|
|
|
+ // Purpur start
|
|
+ @Nullable
|
|
+ public static Entry<EnumItemSlot, ItemStack> getMostDamagedEquipment(Enchantment enchantment, EntityLiving entityliving) {
|
|
+ Map<EnumItemSlot, ItemStack> map = enchantment.a(entityliving);
|
|
+ if (map.isEmpty()) {
|
|
+ return null;
|
|
+ }
|
|
+ Entry<EnumItemSlot, ItemStack> item = null;
|
|
+ float maxPercent = 0F;
|
|
+ for (Entry<EnumItemSlot, ItemStack> entry : map.entrySet()) {
|
|
+ ItemStack itemstack = entry.getValue();
|
|
+ if (!itemstack.isEmpty() && itemstack.isDamaged() && getEnchantmentLevel(enchantment, itemstack) > 0) {
|
|
+ float percent = itemstack.getDamagePercent();
|
|
+ if (item == null || percent > maxPercent) {
|
|
+ item = entry;
|
|
+ maxPercent = percent;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ return item;
|
|
+ }
|
|
+ // Purpur end
|
|
+
|
|
// Paper - OBFHELPER
|
|
public static @javax.annotation.Nonnull ItemStack getRandomEquippedItemWithEnchant(Enchantment enchantment, EntityLiving entityliving) {
|
|
- Entry<EnumItemSlot, ItemStack> entry = b(enchantment, entityliving);
|
|
+ Entry<EnumItemSlot, ItemStack> entry = enchantment == Enchantments.MENDING && entityliving.world.purpurConfig.useBetterMending ? getMostDamagedEquipment(enchantment, entityliving) : b(enchantment, entityliving); // Purpur
|
|
return entry != null ? entry.getValue() : ItemStack.NULL_ITEM;
|
|
}
|
|
@Nullable
|
|
diff --git a/src/main/java/net/minecraft/server/EntityExperienceOrb.java b/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
|
index 53c6c3389..0fae3693c 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
|
@@ -225,7 +225,7 @@ public class EntityExperienceOrb extends Entity {
|
|
if (this.d == 0 && entityhuman.bC == 0 && new com.destroystokyo.paper.event.player.PlayerPickupExperienceEvent(((EntityPlayer) entityhuman).getBukkitEntity(), (org.bukkit.entity.ExperienceOrb) this.getBukkitEntity()).callEvent()) { // Paper
|
|
entityhuman.bC = 2;
|
|
entityhuman.receive(this, 1);
|
|
- Entry<EnumItemSlot, ItemStack> entry = EnchantmentManager.b(Enchantments.MENDING, (EntityLiving) entityhuman);
|
|
+ Entry<EnumItemSlot, ItemStack> entry = world.purpurConfig.useBetterMending ? EnchantmentManager.getMostDamagedEquipment(Enchantments.MENDING, entityhuman) : EnchantmentManager.b(Enchantments.MENDING, entityhuman); // Purpur
|
|
|
|
if (entry != null) {
|
|
ItemStack itemstack = (ItemStack) entry.getValue();
|
|
diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java
|
|
index 413b888a0..ce6a46685 100644
|
|
--- a/src/main/java/net/minecraft/server/ItemStack.java
|
|
+++ b/src/main/java/net/minecraft/server/ItemStack.java
|
|
@@ -370,10 +370,19 @@ public final class ItemStack {
|
|
}
|
|
}
|
|
|
|
+ public boolean isDamaged() { return f(); } // Purpur - OBFHELPER
|
|
public boolean f() {
|
|
return this.e() && this.getDamage() > 0;
|
|
}
|
|
|
|
+ public float getDamagePercent() {
|
|
+ if (isDamaged()) {
|
|
+ return (float) getDamage() / (float) getItem().getMaxDurability();
|
|
+ } else {
|
|
+ return 0F;
|
|
+ }
|
|
+ }
|
|
+
|
|
public int getDamage() {
|
|
return this.tag == null ? 0 : this.tag.getInt("Damage");
|
|
}
|
|
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
index 7cbb1df7a..b76a8c5be 100644
|
|
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
@@ -118,6 +118,7 @@ public class PurpurWorldConfig {
|
|
public Map<Block, Double> controllableMinecartsBlockSpeeds = new HashMap<>();
|
|
public boolean disableDropsOnCrammingDeath = false;
|
|
public boolean milkCuresBadOmen = true;
|
|
+ public boolean useBetterMending = false;
|
|
private void gameplayMechanicsSettings() {
|
|
controllableMinecarts = getBoolean("gameplay-mechanics.controllable-minecarts.enabled", controllableMinecarts);
|
|
controllableMinecartsPlaceAnywhere = getBoolean("gameplay-mechanics.controllable-minecarts.place-anywhere", controllableMinecartsPlaceAnywhere);
|
|
@@ -138,6 +139,7 @@ public class PurpurWorldConfig {
|
|
}
|
|
disableDropsOnCrammingDeath = getBoolean("gameplay-mechanics.disable-drops-on-cramming-death", disableDropsOnCrammingDeath);
|
|
milkCuresBadOmen = getBoolean("gameplay-mechanics.milk-cures-bad-omen", milkCuresBadOmen);
|
|
+ useBetterMending = getBoolean("gameplay-mechanics.use-better-mending", useBetterMending);
|
|
}
|
|
|
|
public boolean idleTimeoutKick = true;
|
|
--
|
|
2.24.0
|
|
|