|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: MelnCat <melncatuwu@gmail.com> |
| 3 | +Date: Sat, 1 Oct 2022 11:33:15 -0700 |
| 4 | +Subject: [PATCH] Add an option to fix MC-3304 (projectile looting) |
| 5 | + |
| 6 | + |
| 7 | +diff --git a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java |
| 8 | +index e292589e015c6691be65285b041f5b4f0d0afeb1..4c6b015532a033ec3d11a96e5758d9dcaad8827c 100644 |
| 9 | +--- a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java |
| 10 | ++++ b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java |
| 11 | +@@ -71,6 +71,7 @@ public abstract class AbstractArrow extends Projectile { |
| 12 | + private IntOpenHashSet piercingIgnoreEntityIds; |
| 13 | + @Nullable |
| 14 | + private List<Entity> piercedAndKilledEntities; |
| 15 | ++ public int lootingLevel; // Purpur |
| 16 | + |
| 17 | + // Spigot Start |
| 18 | + @Override |
| 19 | +@@ -622,6 +623,12 @@ public abstract class AbstractArrow extends Projectile { |
| 20 | + this.knockback = punch; |
| 21 | + } |
| 22 | + |
| 23 | ++ // Purpur start |
| 24 | ++ public void setLootingLevel(int looting) { |
| 25 | ++ this.lootingLevel = looting; |
| 26 | ++ } |
| 27 | ++ // Purpur end |
| 28 | ++ |
| 29 | + public int getKnockback() { |
| 30 | + return this.knockback; |
| 31 | + } |
| 32 | +diff --git a/src/main/java/net/minecraft/world/item/BowItem.java b/src/main/java/net/minecraft/world/item/BowItem.java |
| 33 | +index 220513d3fd5645322886522ea4f6b8c55d043b3c..d45a2f49c82d00801578c34e5f5277fc5e82be87 100644 |
| 34 | +--- a/src/main/java/net/minecraft/world/item/BowItem.java |
| 35 | ++++ b/src/main/java/net/minecraft/world/item/BowItem.java |
| 36 | +@@ -64,6 +64,13 @@ public class BowItem extends ProjectileWeaponItem implements Vanishable { |
| 37 | + if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FLAMING_ARROWS, stack) > 0) { |
| 38 | + entityarrow.setSecondsOnFire(100); |
| 39 | + } |
| 40 | ++ // Purpur start |
| 41 | ++ int lootingLevel = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.MOB_LOOTING, stack); |
| 42 | ++ |
| 43 | ++ if (lootingLevel > 0) { |
| 44 | ++ entityarrow.setLootingLevel(lootingLevel); |
| 45 | ++ } |
| 46 | ++ // Purpur end |
| 47 | + // CraftBukkit start |
| 48 | + org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(entityhuman, stack, itemstack1, entityarrow, entityhuman.getUsedItemHand(), f, !flag1); |
| 49 | + if (event.isCancelled()) { |
| 50 | +diff --git a/src/main/java/net/minecraft/world/item/CrossbowItem.java b/src/main/java/net/minecraft/world/item/CrossbowItem.java |
| 51 | +index 2d30300de78de957358cfddac12294b308062e2a..37cbd0d95f3232ed399c6ef19f714c547b9fd8e5 100644 |
| 52 | +--- a/src/main/java/net/minecraft/world/item/CrossbowItem.java |
| 53 | ++++ b/src/main/java/net/minecraft/world/item/CrossbowItem.java |
| 54 | +@@ -294,6 +294,14 @@ public class CrossbowItem extends ProjectileWeaponItem implements Vanishable { |
| 55 | + entityarrow.setPierceLevel((byte) i); |
| 56 | + } |
| 57 | + |
| 58 | ++ // Purpur start |
| 59 | ++ int lootingLevel = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.MOB_LOOTING, crossbow); |
| 60 | ++ |
| 61 | ++ if (lootingLevel > 0) { |
| 62 | ++ entityarrow.setLootingLevel(lootingLevel); |
| 63 | ++ } |
| 64 | ++ // Purpur end |
| 65 | ++ |
| 66 | + return entityarrow; |
| 67 | + } |
| 68 | + |
| 69 | +diff --git a/src/main/java/net/minecraft/world/item/TridentItem.java b/src/main/java/net/minecraft/world/item/TridentItem.java |
| 70 | +index 086f746cc632a90c67a6c30ea9197c5bb5485b22..ccf1ae6d7b8bf1177526c95a62814f507221da58 100644 |
| 71 | +--- a/src/main/java/net/minecraft/world/item/TridentItem.java |
| 72 | ++++ b/src/main/java/net/minecraft/world/item/TridentItem.java |
| 73 | +@@ -82,6 +82,14 @@ public class TridentItem extends Item implements Vanishable { |
| 74 | + entitythrowntrident.pickup = AbstractArrow.Pickup.CREATIVE_ONLY; |
| 75 | + } |
| 76 | + |
| 77 | ++ // Purpur start |
| 78 | ++ int lootingLevel = EnchantmentHelper.getItemEnchantmentLevel(net.minecraft.world.item.enchantment.Enchantments.MOB_LOOTING, stack); |
| 79 | ++ |
| 80 | ++ if (lootingLevel > 0) { |
| 81 | ++ entitythrowntrident.setLootingLevel(lootingLevel); |
| 82 | ++ } |
| 83 | ++ // Purpur end |
| 84 | ++ |
| 85 | + // CraftBukkit start |
| 86 | + if (!world.addFreshEntity(entitythrowntrident)) { |
| 87 | + if (entityhuman instanceof net.minecraft.server.level.ServerPlayer) { |
| 88 | +diff --git a/src/main/java/net/minecraft/world/level/storage/loot/functions/LootingEnchantFunction.java b/src/main/java/net/minecraft/world/level/storage/loot/functions/LootingEnchantFunction.java |
| 89 | +index 31918fa2eb38e42a5ea5366e559f25ea9d7d59ae..15d8e9261a89da30529ac347462c520920ca4e7d 100644 |
| 90 | +--- a/src/main/java/net/minecraft/world/level/storage/loot/functions/LootingEnchantFunction.java |
| 91 | ++++ b/src/main/java/net/minecraft/world/level/storage/loot/functions/LootingEnchantFunction.java |
| 92 | +@@ -49,6 +49,13 @@ public class LootingEnchantFunction extends LootItemConditionalFunction { |
| 93 | + |
| 94 | + if (entity instanceof LivingEntity) { |
| 95 | + int i = EnchantmentHelper.getMobLooting((LivingEntity) entity); |
| 96 | ++ // Purpur start |
| 97 | ++ if (org.purpurmc.purpur.PurpurConfig.fixProjectileLootingTransfer && |
| 98 | ++ context.getParamOrNull(LootContextParams.DIRECT_KILLER_ENTITY) |
| 99 | ++ instanceof net.minecraft.world.entity.projectile.AbstractArrow arrow) { |
| 100 | ++ i = arrow.lootingLevel; |
| 101 | ++ } |
| 102 | ++ // Purpur end |
| 103 | + // CraftBukkit start - use lootingModifier if set by plugin |
| 104 | + if (context.hasParam(LootContextParams.LOOTING_MOD)) { |
| 105 | + i = context.getParamOrNull(LootContextParams.LOOTING_MOD); |
| 106 | +diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java |
| 107 | +index 8d12ba33da62b58f6390a812fd025ede6032ed88..7efdb3d71c065435dc365207bfc42a82ec36a8b1 100644 |
| 108 | +--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java |
| 109 | ++++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java |
| 110 | +@@ -566,4 +566,9 @@ public class PurpurConfig { |
| 111 | + } |
| 112 | + }); |
| 113 | + } |
| 114 | ++ |
| 115 | ++ public static boolean fixProjectileLootingTransfer = false; |
| 116 | ++ private static void fixProjectileLootingTransfer() { |
| 117 | ++ fixProjectileLootingTransfer = getBoolean("settings.fix-projectile-looting-transfer", fixProjectileLootingTransfer); |
| 118 | ++ } |
| 119 | + } |
0 commit comments