From b38a3c338c5e74bcfaf08064a548859b919a162b Mon Sep 17 00:00:00 2001 From: nathat890 Date: Tue, 7 May 2019 16:50:57 +0100 Subject: [PATCH] Add BlockShearEntityEvent for Dispensers shearing Sheep --- nms-patches/IDispenseBehavior.patch | 47 ++++++++++++------- .../craftbukkit/event/CraftEventFactory.java | 13 +++-- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/nms-patches/IDispenseBehavior.patch b/nms-patches/IDispenseBehavior.patch index b5417291cd..439bdd61c3 100644 --- a/nms-patches/IDispenseBehavior.patch +++ b/nms-patches/IDispenseBehavior.patch @@ -1,12 +1,13 @@ --- a/net/minecraft/server/IDispenseBehavior.java +++ b/net/minecraft/server/IDispenseBehavior.java -@@ -3,6 +3,14 @@ +@@ -3,6 +3,15 @@ import java.util.Iterator; import java.util.List; import java.util.Random; +// CraftBukkit start +import org.bukkit.Location; +import org.bukkit.TreeType; ++import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.craftbukkit.util.DummyGeneratorAccess; +import org.bukkit.event.block.BlockDispenseEvent; @@ -15,7 +16,7 @@ public interface IDispenseBehavior { -@@ -44,7 +52,7 @@ +@@ -44,7 +53,7 @@ BlockDispenser.a((IMaterial) Items.EGG, (IDispenseBehavior) (new DispenseBehaviorProjectile() { @Override protected IProjectile a(World world, IPosition iposition, ItemStack itemstack) { @@ -24,7 +25,7 @@ entityegg.setItem(itemstack); }); } -@@ -52,7 +60,7 @@ +@@ -52,7 +61,7 @@ BlockDispenser.a((IMaterial) Items.SNOWBALL, (IDispenseBehavior) (new DispenseBehaviorProjectile() { @Override protected IProjectile a(World world, IPosition iposition, ItemStack itemstack) { @@ -33,7 +34,7 @@ entitysnowball.setItem(itemstack); }); } -@@ -60,7 +68,7 @@ +@@ -60,7 +69,7 @@ BlockDispenser.a((IMaterial) Items.EXPERIENCE_BOTTLE, (IDispenseBehavior) (new DispenseBehaviorProjectile() { @Override protected IProjectile a(World world, IPosition iposition, ItemStack itemstack) { @@ -42,7 +43,7 @@ entitythrownexpbottle.setItem(itemstack); }); } -@@ -81,7 +89,7 @@ +@@ -81,7 +90,7 @@ return (new DispenseBehaviorProjectile() { @Override protected IProjectile a(World world, IPosition iposition, ItemStack itemstack1) { @@ -51,7 +52,7 @@ entitypotion.setItem(itemstack1); }); } -@@ -104,7 +112,7 @@ +@@ -104,7 +113,7 @@ return (new DispenseBehaviorProjectile() { @Override protected IProjectile a(World world, IPosition iposition, ItemStack itemstack1) { @@ -60,7 +61,7 @@ entitypotion.setItem(itemstack1); }); } -@@ -127,8 +135,36 @@ +@@ -127,8 +136,36 @@ EnumDirection enumdirection = (EnumDirection) isourceblock.e().get(BlockDispenser.FACING); EntityTypes entitytypes = ((ItemMonsterEgg) itemstack.getItem()).b(itemstack.getTag()); @@ -98,7 +99,7 @@ return itemstack; } }; -@@ -147,9 +183,37 @@ +@@ -147,9 +184,37 @@ double d0 = isourceblock.getX() + (double) enumdirection.getAdjacentX(); double d1 = (double) ((float) isourceblock.getBlockPosition().getY() + 0.2F); double d2 = isourceblock.getZ() + (double) enumdirection.getAdjacentZ(); @@ -138,7 +139,7 @@ return itemstack; } -@@ -172,10 +236,39 @@ +@@ -172,10 +237,39 @@ double d4 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentY(); double d5 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentZ(); @@ -182,7 +183,7 @@ return itemstack; } -@@ -199,9 +292,52 @@ +@@ -199,9 +293,52 @@ BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.e().get(BlockDispenser.FACING)); World world = isourceblock.getWorld(); @@ -236,7 +237,7 @@ } else { return this.b.dispense(isourceblock, itemstack); } -@@ -225,13 +361,39 @@ +@@ -225,13 +362,39 @@ Block block = iblockdata.getBlock(); if (block instanceof IFluidSource) { @@ -277,7 +278,7 @@ itemstack.subtract(1); if (itemstack.isEmpty()) { return new ItemStack(item); -@@ -253,12 +415,40 @@ +@@ -253,12 +416,40 @@ protected ItemStack a(ISourceBlock isourceblock, ItemStack itemstack) { World world = isourceblock.getWorld(); @@ -319,7 +320,7 @@ } else if (ItemFlintAndSteel.a(iblockdata)) { world.setTypeUpdate(blockposition, (IBlockData) iblockdata.set(BlockProperties.r, true)); } else if (iblockdata.getBlock() instanceof BlockTNT) { -@@ -281,12 +471,57 @@ +@@ -281,12 +472,57 @@ this.dispensed = true; World world = isourceblock.getWorld(); BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.e().get(BlockDispenser.FACING)); @@ -377,7 +378,7 @@ return itemstack; } -@@ -296,11 +531,40 @@ +@@ -296,11 +532,40 @@ protected ItemStack a(ISourceBlock isourceblock, ItemStack itemstack) { World world = isourceblock.getWorld(); BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.e().get(BlockDispenser.FACING)); @@ -420,7 +421,7 @@ return itemstack; } })); -@@ -324,6 +588,30 @@ +@@ -324,6 +589,30 @@ EnumDirection enumdirection = (EnumDirection) isourceblock.e().get(BlockDispenser.FACING); BlockPosition blockposition = isourceblock.getBlockPosition().shift(enumdirection); @@ -451,7 +452,7 @@ this.dispensed = true; if (world.isEmpty(blockposition) && BlockWitherSkull.b(world, blockposition, itemstack)) { world.setTypeAndData(blockposition, (IBlockData) Blocks.WITHER_SKELETON_SKULL.getBlockData().set(BlockSkull.a, enumdirection.k() == EnumDirection.EnumAxis.Y ? 0 : enumdirection.opposite().get2DRotationValue() * 4), 3); -@@ -348,6 +636,30 @@ +@@ -348,6 +637,30 @@ BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.e().get(BlockDispenser.FACING)); BlockPumpkinCarved blockpumpkincarved = (BlockPumpkinCarved) Blocks.CARVED_PUMPKIN; @@ -482,7 +483,7 @@ this.dispensed = true; if (world.isEmpty(blockposition) && blockpumpkincarved.a((IWorldReader) world, blockposition)) { if (!world.isClientSide) { -@@ -380,6 +692,29 @@ +@@ -380,6 +693,29 @@ @Override protected ItemStack a(ISourceBlock isourceblock, ItemStack itemstack) { World world = isourceblock.getWorld(); @@ -512,3 +513,15 @@ if (!world.e()) { this.dispensed = false; +@@ -391,6 +727,11 @@ + EntitySheep entitysheep = (EntitySheep) iterator1.next(); + + if (entitysheep.isAlive() && !entitysheep.isSheared() && !entitysheep.isBaby()) { ++ // CraftBukkit start ++ if (CraftEventFactory.callBlockShearEntityEvent(entitysheep, bukkitBlock, craftItem).isCancelled()) { ++ continue; ++ } ++ // CraftBukkit end + entitysheep.shear(); + if (itemstack.isDamaged(1, world.random, (EntityPlayer) null)) { + itemstack.setCount(0); diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index f64c63b1dd..70e29386bd 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -2,7 +2,6 @@ package org.bukkit.craftbukkit.event; import com.google.common.base.Function; import com.google.common.base.Functions; -import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.mojang.datafixers.util.Either; import java.net.InetAddress; @@ -38,6 +37,7 @@ import net.minecraft.server.EntityLiving; import net.minecraft.server.EntityMonster; import net.minecraft.server.EntityPlayer; import net.minecraft.server.EntityPotion; +import net.minecraft.server.EntitySheep; import net.minecraft.server.EntitySlime; import net.minecraft.server.EntityTypes; import net.minecraft.server.EntityWaterAnimal; @@ -98,6 +98,7 @@ import org.bukkit.entity.Pig; import org.bukkit.entity.PigZombie; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; +import org.bukkit.entity.Sheep; import org.bukkit.entity.ThrownExpBottle; import org.bukkit.entity.ThrownPotion; import org.bukkit.entity.Vehicle; @@ -116,6 +117,7 @@ import org.bukkit.event.block.BlockMultiPlaceEvent; import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockRedstoneEvent; +import org.bukkit.event.block.BlockShearEntityEvent; import org.bukkit.event.block.BlockSpreadEvent; import org.bukkit.event.block.EntityBlockFormEvent; import org.bukkit.event.block.FluidLevelChangeEvent; @@ -182,8 +184,6 @@ import org.bukkit.event.server.ServerListPingEvent; import org.bukkit.event.vehicle.VehicleCreateEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.InventoryView; -import org.bukkit.inventory.Merchant; -import org.bukkit.inventory.MerchantInventory; import org.bukkit.inventory.meta.BookMeta; import org.bukkit.potion.PotionEffect; @@ -1241,6 +1241,13 @@ public class CraftEventFactory { return event; } + public static BlockShearEntityEvent callBlockShearEntityEvent(EntitySheep animal, org.bukkit.block.Block dispenser, CraftItemStack is) { + Sheep sheep = (Sheep) animal.getBukkitEntity(); + BlockShearEntityEvent bse = new BlockShearEntityEvent(dispenser, sheep, is); + Bukkit.getPluginManager().callEvent(bse); + return bse; + } + public static Cancellable handleStatisticsIncrease(EntityHuman entityHuman, net.minecraft.server.Statistic statistic, int current, int incrementation) { Player player = ((EntityPlayer) entityHuman).getBukkitEntity(); Event event;