#702: Add Block#applyBoneMeal()

This commit is contained in:
Parker Hawke 2020-08-27 11:27:13 +10:00 committed by md_5
parent 8408de02d2
commit 8c6115604b
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
3 changed files with 40 additions and 2 deletions

View File

@ -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;

View File

@ -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());

View File

@ -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<ItemStack> getDrops() {
return getDrops(null);