Use player location in CraftItemStack#canPlaceOn
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: lexikiq <noellekiq@gmail.com>
|
||||
Date: Mon, 10 May 2021 01:26:38 -0400
|
||||
Date: Mon, 10 May 2021 01:39:48 -0400
|
||||
Subject: [PATCH] Add CraftItemStack#canPlaceOn
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@ index 59d52c252b2e59923b8e513dd4d2e1ec9ce34dc7..25326f1124773ca4956a72a9b2998513
|
||||
EntityHuman entityhuman = blockactioncontext.getEntity();
|
||||
VoxelShapeCollision voxelshapecollision = entityhuman == null ? VoxelShapeCollision.a() : VoxelShapeCollision.a((Entity) entityhuman);
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
||||
index 09d7a86b5f6cffdf6664ad657dd4f8dd8eabdd70..da56f0790ee5a07c0dad09082b2d58a3a2e3b702 100644
|
||||
index 09d7a86b5f6cffdf6664ad657dd4f8dd8eabdd70..9634a967e04ca405d51007b939e24557914be420 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
||||
@@ -3,18 +3,31 @@ package org.bukkit.craftbukkit.inventory;
|
||||
@@ -3,18 +3,32 @@ package org.bukkit.craftbukkit.inventory;
|
||||
import static org.bukkit.craftbukkit.inventory.CraftMetaItem.*;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.util.Map;
|
||||
@@ -37,6 +37,7 @@ index 09d7a86b5f6cffdf6664ad657dd4f8dd8eabdd70..da56f0790ee5a07c0dad09082b2d58a3
|
||||
+import net.minecraft.world.phys.MovingObjectPositionBlock;
|
||||
+import net.minecraft.world.phys.Vec3D;
|
||||
import org.apache.commons.lang.Validate;
|
||||
+import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
+import org.bukkit.block.Block;
|
||||
+import org.bukkit.block.BlockFace;
|
||||
@@ -52,13 +53,14 @@ index 09d7a86b5f6cffdf6664ad657dd4f8dd8eabdd70..da56f0790ee5a07c0dad09082b2d58a3
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.material.MaterialData;
|
||||
@@ -105,6 +118,33 @@ public final class CraftItemStack extends ItemStack {
|
||||
@@ -105,6 +119,35 @@ public final class CraftItemStack extends ItemStack {
|
||||
setItemMeta(itemMeta);
|
||||
}
|
||||
|
||||
+ // Parchment start
|
||||
+ /**
|
||||
+ * Determines if this item can be placed on a block. Must be run synchronously.
|
||||
+ * Determines if this item can be placed on a block. Must be run synchronously. Factors in player location,
|
||||
+ * nearby entities, and more.
|
||||
+ * @param _player player placing the block
|
||||
+ * @param block block to check against
|
||||
+ * @param face cardinal direction
|
||||
@@ -67,6 +69,7 @@ index 09d7a86b5f6cffdf6664ad657dd4f8dd8eabdd70..da56f0790ee5a07c0dad09082b2d58a3
|
||||
+ public boolean canPlaceOn(HasHumanEntity _player, Block block, BlockFace face) {
|
||||
+ if (block.getType().isEmpty()) return false;
|
||||
+ HumanEntity player = _player.getPlayer();
|
||||
+ Location playerLoc = player.getLocation();
|
||||
+ if (!face.isCartesian()) throw new IllegalArgumentException("Face must be cartesian");
|
||||
+ if (!(block instanceof CraftBlock)) return false;
|
||||
+ if (!(player instanceof CraftEntity)) return false;
|
||||
@@ -78,7 +81,7 @@ index 09d7a86b5f6cffdf6664ad657dd4f8dd8eabdd70..da56f0790ee5a07c0dad09082b2d58a3
|
||||
+ if (!(item instanceof ItemBlock)) return false;
|
||||
+ ItemBlock itemBlock = (ItemBlock) item;
|
||||
+
|
||||
+ BlockActionContext context = new BlockActionContext((EntityHuman) ((CraftEntity) player).getHandle(), EnumHand.MAIN_HAND, asNMSCopy(this), new MovingObjectPositionBlock(new Vec3D(relativeBlock.getX(), relativeBlock.getY(), relativeBlock.getZ()), direction, craftBlock.getPosition(), false));
|
||||
+ BlockActionContext context = new BlockActionContext((EntityHuman) ((CraftEntity) player).getHandle(), EnumHand.MAIN_HAND, asNMSCopy(this), new MovingObjectPositionBlock(new Vec3D(playerLoc.getX(), playerLoc.getY(), playerLoc.getZ()), direction, craftBlock.getPosition(), false));
|
||||
+ return itemBlock.canPlaceOn(context, itemBlock.getBlock().getPlacedState(context));
|
||||
+ }
|
||||
+ // Parchment end
|
||||
|
||||
Reference in New Issue
Block a user