Files
Purpur/patches/server/0241-Shears-can-have-looting-enchantment.patch
Encode42 dad13788ad Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@2040c1e Player Flying Fall Damage API (#5357)
PaperMC/Paper@fa42c68 Expose pre-collision moving velocity to VehicleBlockCollisionEvent (#8457)
PaperMC/Paper@90750a6 Rework filtering spawn egg and tile entity nbt config (#6613)
2022-12-29 00:19:27 -05:00

180 lines
11 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <Blake.Galbreath@Gmail.com>
Date: Mon, 3 Jan 2022 00:06:51 -0600
Subject: [PATCH] Shears can have looting enchantment
diff --git a/src/main/java/net/minecraft/core/dispenser/ShearsDispenseItemBehavior.java b/src/main/java/net/minecraft/core/dispenser/ShearsDispenseItemBehavior.java
index d1127d93a85a837933d0d73c24cacac4adc3a5b9..d9a6d273108165f59b995b1fd7748cb5c12b8b1f 100644
--- a/src/main/java/net/minecraft/core/dispenser/ShearsDispenseItemBehavior.java
+++ b/src/main/java/net/minecraft/core/dispenser/ShearsDispenseItemBehavior.java
@@ -107,7 +107,7 @@ public class ShearsDispenseItemBehavior extends OptionalDispenseItemBehavior {
continue;
}
// CraftBukkit end
- ishearable.shear(SoundSource.BLOCKS);
+ ishearable.shear(SoundSource.BLOCKS, net.minecraft.world.item.enchantment.EnchantmentHelper.getItemEnchantmentLevel(net.minecraft.world.item.enchantment.Enchantments.MOB_LOOTING, CraftItemStack.asNMSCopy(craftItem))); // Purpur
worldserver.gameEvent((Entity) null, GameEvent.SHEAR, blockposition);
return true;
}
diff --git a/src/main/java/net/minecraft/world/entity/Shearable.java b/src/main/java/net/minecraft/world/entity/Shearable.java
index 5e8cc5cfac8888628c6d513148f41be09ca65a2c..a089fc61ec09be6b7490375489178dc6ba5a644b 100644
--- a/src/main/java/net/minecraft/world/entity/Shearable.java
+++ b/src/main/java/net/minecraft/world/entity/Shearable.java
@@ -3,7 +3,13 @@ package net.minecraft.world.entity;
import net.minecraft.sounds.SoundSource;
public interface Shearable {
- void shear(SoundSource shearedSoundCategory);
+ // Purpur start
+ default void shear(SoundSource shearedSoundCategory) {
+ shear(shearedSoundCategory, 0);
+ }
+
+ void shear(SoundSource shearedSoundCategory, int looting);
+ // Purpur end
boolean readyForShearing();
}
diff --git a/src/main/java/net/minecraft/world/entity/animal/MushroomCow.java b/src/main/java/net/minecraft/world/entity/animal/MushroomCow.java
index f517658a240a7c79889f9047e94e9afc884df78c..046e851a5c49e58fa4e84d398ffbe11baa9c4072 100644
--- a/src/main/java/net/minecraft/world/entity/animal/MushroomCow.java
+++ b/src/main/java/net/minecraft/world/entity/animal/MushroomCow.java
@@ -164,7 +164,7 @@ public class MushroomCow extends Cow implements Shearable, VariantHolder<Mushroo
return tryRide(player, hand); // Purpur
}
// CraftBukkit end
- this.shear(SoundSource.PLAYERS);
+ this.shear(SoundSource.PLAYERS, net.minecraft.world.item.enchantment.EnchantmentHelper.getMobLooting(player)); // Purpur
this.gameEvent(GameEvent.SHEAR, player);
if (!this.level.isClientSide) {
itemstack.hurtAndBreak(1, player, (entityhuman1) -> {
@@ -207,7 +207,7 @@ public class MushroomCow extends Cow implements Shearable, VariantHolder<Mushroo
}
@Override
- public void shear(SoundSource shearedSoundCategory) {
+ public void shear(SoundSource shearedSoundCategory, int looting) { // Purpur
this.level.playSound((Player) null, (Entity) this, SoundEvents.MOOSHROOM_SHEAR, shearedSoundCategory, 1.0F, 1.0F);
if (!this.level.isClientSide()) {
Cow entitycow = (Cow) EntityType.COW.create(this.level);
@@ -243,7 +243,7 @@ public class MushroomCow extends Cow implements Shearable, VariantHolder<Mushroo
this.discard(); // CraftBukkit - from above
// CraftBukkit end
- for (int i = 0; i < 5; ++i) {
+ for (int i = 0; i < 5 + (org.purpurmc.purpur.PurpurConfig.allowShearsLooting ? looting : 0); ++i) {
// CraftBukkit start
ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY(1.0D), this.getZ(), new ItemStack(this.getVariant().blockState.getBlock()));
EntityDropItemEvent event = new EntityDropItemEvent(this.getBukkitEntity(), (org.bukkit.entity.Item) entityitem.getBukkitEntity());
diff --git a/src/main/java/net/minecraft/world/entity/animal/Sheep.java b/src/main/java/net/minecraft/world/entity/animal/Sheep.java
index 99dbbe59116ae4fbdfb506a72959e3a6a0d00548..017507e7201ffc4a9486f5fb9edc9dac18e989d7 100644
--- a/src/main/java/net/minecraft/world/entity/animal/Sheep.java
+++ b/src/main/java/net/minecraft/world/entity/animal/Sheep.java
@@ -292,7 +292,7 @@ public class Sheep extends Animal implements Shearable {
return InteractionResult.PASS;
}
// CraftBukkit end
- this.shear(SoundSource.PLAYERS);
+ this.shear(SoundSource.PLAYERS, net.minecraft.world.item.enchantment.EnchantmentHelper.getMobLooting(player)); // Purpur
this.gameEvent(GameEvent.SHEAR, player);
itemstack.hurtAndBreak(1, player, (entityhuman1) -> {
entityhuman1.broadcastBreakEvent(hand);
@@ -307,10 +307,11 @@ public class Sheep extends Animal implements Shearable {
}
@Override
- public void shear(SoundSource shearedSoundCategory) {
+ public void shear(SoundSource shearedSoundCategory, int looting) { // Purpur
this.level.playSound((Player) null, (Entity) this, SoundEvents.SHEEP_SHEAR, shearedSoundCategory, 1.0F, 1.0F);
this.setSheared(true);
int i = 1 + this.random.nextInt(3);
+ if (org.purpurmc.purpur.PurpurConfig.allowShearsLooting) i += looting; // Purpur
for (int j = 0; j < i; ++j) {
this.forceDrops = true; // CraftBukkit
diff --git a/src/main/java/net/minecraft/world/entity/animal/SnowGolem.java b/src/main/java/net/minecraft/world/entity/animal/SnowGolem.java
index d5cef133b9d6551652b7429d39c593f34c794f00..00d86c57fabbb464a156dfaceadccd978f0d149c 100644
--- a/src/main/java/net/minecraft/world/entity/animal/SnowGolem.java
+++ b/src/main/java/net/minecraft/world/entity/animal/SnowGolem.java
@@ -205,7 +205,7 @@ public class SnowGolem extends AbstractGolem implements Shearable, RangedAttackM
return tryRide(player, hand); // Purpur
}
// CraftBukkit end
- this.shear(SoundSource.PLAYERS);
+ this.shear(SoundSource.PLAYERS, net.minecraft.world.item.enchantment.EnchantmentHelper.getMobLooting(player)); // Purpur
this.gameEvent(GameEvent.SHEAR, player);
if (!this.level.isClientSide) {
itemstack.hurtAndBreak(1, player, (entityhuman1) -> {
@@ -228,12 +228,13 @@ public class SnowGolem extends AbstractGolem implements Shearable, RangedAttackM
}
@Override
- public void shear(SoundSource shearedSoundCategory) {
+ public void shear(SoundSource shearedSoundCategory, int looting) { // Purpur
this.level.playSound((Player) null, (Entity) this, SoundEvents.SNOW_GOLEM_SHEAR, shearedSoundCategory, 1.0F, 1.0F);
if (!this.level.isClientSide()) {
this.setPumpkin(false);
this.forceDrops = true; // CraftBukkit
if (level.purpurConfig.snowGolemDropsPumpkin) // Purpur
+ for (int i = 0; i < 1 + (org.purpurmc.purpur.PurpurConfig.allowShearsLooting ? looting : 0); i++) // Purpur
this.spawnAtLocation(new ItemStack(Items.CARVED_PUMPKIN), 1.7F);
this.forceDrops = false; // CraftBukkit
}
diff --git a/src/main/java/net/minecraft/world/item/enchantment/EnchantmentCategory.java b/src/main/java/net/minecraft/world/item/enchantment/EnchantmentCategory.java
index d6417c1e77ac8823e18a179dc9f61757a1f339ad..a19dd0946f853193ff32b2b560db27534b8b4abf 100644
--- a/src/main/java/net/minecraft/world/item/enchantment/EnchantmentCategory.java
+++ b/src/main/java/net/minecraft/world/item/enchantment/EnchantmentCategory.java
@@ -104,6 +104,12 @@ public enum EnchantmentCategory {
public boolean canEnchant(Item item) {
return item instanceof BowItem || item instanceof CrossbowItem;
}
+ },
+ WEAPON_AND_SHEARS {
+ @Override
+ public boolean canEnchant(Item item) {
+ return WEAPON.canEnchant(item) || item instanceof net.minecraft.world.item.ShearsItem;
+ }
// Purpur end
};
diff --git a/src/main/java/net/minecraft/world/item/enchantment/LootBonusEnchantment.java b/src/main/java/net/minecraft/world/item/enchantment/LootBonusEnchantment.java
index 6b8a1535086aae7e4e3229d05615fb903188f507..60af917083de1b790b1d93d61835a669143068fb 100644
--- a/src/main/java/net/minecraft/world/item/enchantment/LootBonusEnchantment.java
+++ b/src/main/java/net/minecraft/world/item/enchantment/LootBonusEnchantment.java
@@ -7,6 +7,14 @@ public class LootBonusEnchantment extends Enchantment {
super(weight, type, slotTypes);
}
+ // Purpur start
+ @Override
+ public boolean canEnchant(net.minecraft.world.item.ItemStack stack) {
+ // we have to cheat the system because this class is loaded before purpur's config is loaded
+ return (org.purpurmc.purpur.PurpurConfig.allowShearsLooting && this.category == EnchantmentCategory.WEAPON ? EnchantmentCategory.WEAPON_AND_SHEARS : this.category).canEnchant(stack.getItem());
+ }
+ // Purpur end
+
@Override
public int getMinCost(int level) {
return 15 + (level - 1) * 9;
diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
index 0394e3150daebc8e63165faafb8362ce7a0d8641..aebd8ac1a50d88d08447b9cbc0dbed0676abfb8e 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
@@ -387,6 +387,7 @@ public class PurpurConfig {
public static boolean allowInfinityMending = false;
public static boolean allowCrossbowInfinity = false;
+ public static boolean allowShearsLooting = false;
public static boolean allowUnsafeEnchants = false;
public static boolean allowInapplicableEnchants = true;
public static boolean allowIncompatibleEnchants = true;
@@ -408,6 +409,7 @@ public class PurpurConfig {
}
allowInfinityMending = getBoolean("settings.enchantment.allow-infinity-and-mending-together", allowInfinityMending);
allowCrossbowInfinity = getBoolean("settings.enchantment.allow-infinity-on-crossbow", allowCrossbowInfinity);
+ allowShearsLooting = getBoolean("settings.enchantment.allow-looting-on-shears", allowShearsLooting);
allowUnsafeEnchants = getBoolean("settings.enchantment.anvil.allow-unsafe-enchants", allowUnsafeEnchants);
allowInapplicableEnchants = getBoolean("settings.enchantment.anvil.allow-inapplicable-enchants", allowInapplicableEnchants);
allowIncompatibleEnchants = getBoolean("settings.enchantment.anvil.allow-incompatible-enchants", allowIncompatibleEnchants);