From 8c6115604b762c1e200e88a5282218c13a6f25dd Mon Sep 17 00:00:00 2001 From: Parker Hawke Date: Thu, 27 Aug 2020 11:27:13 +1000 Subject: [PATCH] #702: Add Block#applyBoneMeal() --- nms-patches/ItemActionContext.patch | 11 +++++++++++ nms-patches/ItemBoneMeal.patch | 15 +++++++++++++++ .../org/bukkit/craftbukkit/block/CraftBlock.java | 16 ++++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 nms-patches/ItemActionContext.patch create mode 100644 nms-patches/ItemBoneMeal.patch diff --git a/nms-patches/ItemActionContext.patch b/nms-patches/ItemActionContext.patch new file mode 100644 index 0000000000..28a5640fc5 --- /dev/null +++ b/nms-patches/ItemActionContext.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/server/ItemActionContext.java ++++ b/net/minecraft/server/ItemActionContext.java +@@ -15,7 +15,7 @@ + this(entityhuman.world, entityhuman, enumhand, entityhuman.b(enumhand), movingobjectpositionblock); + } + +- protected ItemActionContext(World world, @Nullable EntityHuman entityhuman, EnumHand enumhand, ItemStack itemstack, MovingObjectPositionBlock movingobjectpositionblock) { ++ public ItemActionContext(World world, @Nullable EntityHuman entityhuman, EnumHand enumhand, ItemStack itemstack, MovingObjectPositionBlock movingobjectpositionblock) { // PAIL protected -> public + this.a = entityhuman; + this.b = enumhand; + this.c = movingobjectpositionblock; diff --git a/nms-patches/ItemBoneMeal.patch b/nms-patches/ItemBoneMeal.patch new file mode 100644 index 0000000000..cae44479a4 --- /dev/null +++ b/nms-patches/ItemBoneMeal.patch @@ -0,0 +1,15 @@ +--- a/net/minecraft/server/ItemBoneMeal.java ++++ b/net/minecraft/server/ItemBoneMeal.java +@@ -12,6 +12,12 @@ + + @Override + public EnumInteractionResult a(ItemActionContext itemactioncontext) { ++ // CraftBukkit start - extract bonemeal application logic to separate, static method ++ return applyBonemeal(itemactioncontext); ++ } ++ ++ public static EnumInteractionResult applyBonemeal(ItemActionContext itemactioncontext) { ++ // CraftBukkit end + World world = itemactioncontext.getWorld(); + BlockPosition blockposition = itemactioncontext.getClickPosition(); + BlockPosition blockposition1 = blockposition.shift(itemactioncontext.getClickedFace()); diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java index ac63b098f4..334728b191 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -12,14 +12,18 @@ import net.minecraft.server.BlockRedstoneWire; import net.minecraft.server.BlockTileEntity; import net.minecraft.server.Blocks; import net.minecraft.server.EnumDirection; +import net.minecraft.server.EnumHand; +import net.minecraft.server.EnumInteractionResult; import net.minecraft.server.EnumSkyBlock; import net.minecraft.server.GeneratorAccess; import net.minecraft.server.IBlockData; import net.minecraft.server.IRegistry; -import net.minecraft.server.MinecraftKey; +import net.minecraft.server.ItemActionContext; +import net.minecraft.server.ItemBoneMeal; +import net.minecraft.server.Items; import net.minecraft.server.MovingObjectPosition; +import net.minecraft.server.MovingObjectPositionBlock; import net.minecraft.server.RayTrace; -import net.minecraft.server.RegistryGeneration; import net.minecraft.server.TileEntity; import net.minecraft.server.Vec3D; import net.minecraft.server.VoxelShape; @@ -629,6 +633,14 @@ public class CraftBlock implements Block { return setTypeAndData(Blocks.AIR.getBlockData(), true) && result; } + @Override + public boolean applyBoneMeal(BlockFace face) { + EnumDirection direction = blockFaceToNotch(face); + ItemActionContext context = new ItemActionContext(getCraftWorld().getHandle(), null, EnumHand.MAIN_HAND, Items.BONE_MEAL.r(), new MovingObjectPositionBlock(Vec3D.a, direction, getPosition(), false)); // PAIL rename createItemStack, ZERO + + return ItemBoneMeal.applyBonemeal(context) == EnumInteractionResult.SUCCESS; + } + @Override public Collection getDrops() { return getDrops(null);