--- a/net/minecraft/world/entity/animal/EntitySheep.java +++ b/net/minecraft/world/entity/animal/EntitySheep.java @@ -64,11 +64,19 @@ import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.level.storage.loot.LootTables; +// CraftBukkit start +import net.minecraft.world.inventory.InventoryCraftResult; +import net.minecraft.world.item.Item; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.event.entity.SheepRegrowWoolEvent; +import org.bukkit.inventory.InventoryView; +// CraftBukkit end + public class EntitySheep extends EntityAnimal implements IShearable { private static final int EAT_ANIMATION_TICKS = 40; private static final DataWatcherObject DATA_WOOL_ID = DataWatcher.a(EntitySheep.class, DataWatcherRegistry.BYTE); - private static final Map ITEM_BY_DYE = (Map) SystemUtils.a((Object) Maps.newEnumMap(EnumColor.class), (enummap) -> { + private static final Map ITEM_BY_DYE = (Map) SystemUtils.a(Maps.newEnumMap(EnumColor.class), (enummap) -> { // CraftBukkit - decompile error enummap.put(EnumColor.WHITE, Blocks.WHITE_WOOL); enummap.put(EnumColor.ORANGE, Blocks.ORANGE_WOOL); enummap.put(EnumColor.MAGENTA, Blocks.MAGENTA_WOOL); @@ -223,6 +231,11 @@ if (itemstack.a(Items.SHEARS)) { if (!this.level.isClientSide && this.canShear()) { + // CraftBukkit start + if (!CraftEventFactory.handlePlayerShearEntityEvent(entityhuman, this, itemstack, enumhand)) { + return EnumInteractionResult.PASS; + } + // CraftBukkit end this.shear(SoundCategory.PLAYERS); this.a(GameEvent.SHEAR, (Entity) entityhuman); itemstack.damage(1, entityhuman, (entityhuman1) -> { @@ -244,7 +257,9 @@ int i = 1 + this.random.nextInt(3); for (int j = 0; j < i; ++j) { + this.forceDrops = true; // CraftBukkit EntityItem entityitem = this.a((IMaterial) EntitySheep.ITEM_BY_DYE.get(this.getColor()), 1); + this.forceDrops = false; // CraftBukkit if (entityitem != null) { entityitem.setMot(entityitem.getMot().add((double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F), (double) (this.random.nextFloat() * 0.05F), (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F))); @@ -334,6 +349,12 @@ @Override public void blockEaten() { + // CraftBukkit start + SheepRegrowWoolEvent event = new SheepRegrowWoolEvent((org.bukkit.entity.Sheep) this.getBukkitEntity()); + this.level.getCraftServer().getPluginManager().callEvent(event); + + if (event.isCancelled()) return; + // CraftBukkit end this.setSheared(false); if (this.isBaby()) { this.setAge(60); @@ -352,8 +373,8 @@ EnumColor enumcolor = ((EntitySheep) entityanimal).getColor(); EnumColor enumcolor1 = ((EntitySheep) entityanimal1).getColor(); InventoryCrafting inventorycrafting = a(enumcolor, enumcolor1); - Optional optional = this.level.getCraftingManager().craft(Recipes.CRAFTING, inventorycrafting, this.level).map((recipecrafting) -> { - return recipecrafting.a((IInventory) inventorycrafting); + Optional optional = this.level.getCraftingManager().craft(Recipes.CRAFTING, inventorycrafting, this.level).map((recipecrafting) -> { // Eclipse fail + return recipecrafting.a(inventorycrafting); // CraftBukkit - decompile error }).map(ItemStack::getItem); Objects.requireNonNull(ItemDye.class); @@ -370,10 +391,18 @@ public boolean canUse(EntityHuman entityhuman) { return false; } + + // CraftBukkit start + @Override + public InventoryView getBukkitView() { + return null; // TODO: O.O + } + // CraftBukkit end }, 2, 1); inventorycrafting.setItem(0, new ItemStack(ItemDye.a(enumcolor))); inventorycrafting.setItem(1, new ItemStack(ItemDye.a(enumcolor1))); + inventorycrafting.resultInventory = new InventoryCraftResult(); // CraftBukkit - add result slot for event return inventorycrafting; }