Add an option to fix MC-3304 (projectile looting)

This commit is contained in:
MelnCat
2025-01-12 16:47:29 -08:00
committed by granny
parent d72e7f1930
commit b3994f8939
6 changed files with 61 additions and 90 deletions

View File

@@ -1,5 +1,13 @@
--- a/net/minecraft/world/entity/projectile/AbstractArrow.java
+++ b/net/minecraft/world/entity/projectile/AbstractArrow.java
@@ -74,6 +_,7 @@
public ItemStack pickupItemStack = this.getDefaultPickupItem(); // Paper - private -> public
@Nullable
public ItemStack firedFromWeapon = null; // Paper - private -> public
+ public net.minecraft.world.item.enchantment.ItemEnchantments actualEnchantments = net.minecraft.world.item.enchantment.ItemEnchantments.EMPTY; // Purpur - Add an option to fix MC-3304 projectile looting
protected AbstractArrow(EntityType<? extends AbstractArrow> entityType, Level level) {
super(entityType, level);
@@ -347,7 +_,7 @@
this.setInGround(false);
Vec3 deltaMovement = this.getDeltaMovement();
@@ -9,3 +17,16 @@
}
public boolean isInGround() { // Paper - protected -> public
@@ -559,6 +_,12 @@
public ItemStack getWeaponItem() {
return this.firedFromWeapon;
}
+
+ // Purpur start - Add an option to fix MC-3304 projectile looting
+ public void setActualEnchantments(net.minecraft.world.item.enchantment.ItemEnchantments actualEnchantments) {
+ this.actualEnchantments = actualEnchantments;
+ }
+ // Purpur end - Add an option to fix MC-3304 projectile looting
protected SoundEvent getDefaultHitGroundSoundEvent() {
return SoundEvents.ARROW_HIT;

View File

@@ -0,0 +1,11 @@
--- a/net/minecraft/world/item/ProjectileWeaponItem.java
+++ b/net/minecraft/world/item/ProjectileWeaponItem.java
@@ -108,6 +_,8 @@
abstractArrow.setCritArrow(true);
}
+ abstractArrow.setActualEnchantments(weapon.getEnchantments()); // Purpur - Add an option to fix MC-3304 projectile looting
+
return abstractArrow;
}

View File

@@ -9,3 +9,13 @@
);
// Paper start - PlayerLaunchProjectileEvent
com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) player.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(stack), (org.bukkit.entity.Projectile) tridentDelayed.projectile().getBukkitEntity());
@@ -101,6 +_,9 @@
return false;
}
ThrownTrident thrownTrident = tridentDelayed.projectile(); // Paper - PlayerLaunchProjectileEvent
+
+ thrownTrident.setActualEnchantments(stack.getEnchantments()); // Purpur - Add an option to fix MC-3304 projectile looting
+
if (event.shouldConsume()) stack.hurtWithoutBreaking(1, player); // Paper - PlayerLaunchProjectileEvent
thrownTrident.pickupItemStack = stack.copy(); // SPIGOT-4511 update since damage call moved
// CraftBukkit end

View File

@@ -0,0 +1,14 @@
--- a/net/minecraft/world/level/storage/loot/functions/EnchantedCountIncreaseFunction.java
+++ b/net/minecraft/world/level/storage/loot/functions/EnchantedCountIncreaseFunction.java
@@ -66,6 +_,11 @@
Entity entity = context.getOptionalParameter(LootContextParams.ATTACKING_ENTITY);
if (entity instanceof LivingEntity livingEntity) {
int enchantmentLevel = EnchantmentHelper.getEnchantmentLevel(this.enchantment, livingEntity);
+ // Purpur start - Add an option to fix MC-3304 projectile looting
+ if (org.purpurmc.purpur.PurpurConfig.fixProjectileLootingTransfer && context.getOptionalParameter(LootContextParams.DIRECT_ATTACKING_ENTITY) instanceof net.minecraft.world.entity.projectile.AbstractArrow arrow) {
+ enchantmentLevel = arrow.actualEnchantments.getLevel(this.enchantment);
+ }
+ // Purpur end - Add an option to fix MC-3304 projectile looting
if (enchantmentLevel == 0) {
return stack;
}

View File

@@ -498,6 +498,11 @@ public class PurpurConfig {
usernameValidCharactersPattern = Pattern.compile(setPattern == null || setPattern.isBlank() ? defaultPattern : setPattern);
}
public static boolean fixProjectileLootingTransfer = false;
private static void fixProjectileLootingTransfer() {
fixProjectileLootingTransfer = getBoolean("settings.fix-projectile-looting-transfer", fixProjectileLootingTransfer);
}
private static void blastResistanceSettings() {
getMap("settings.blast-resistance-overrides", Collections.emptyMap()).forEach((blockId, value) -> {
Block block = BuiltInRegistries.BLOCK.getValue(ResourceLocation.parse(blockId));