Paper/nms-patches/ItemBlock.patch

75 lines
3.4 KiB
Diff
Raw Normal View History

--- a/net/minecraft/server/ItemBlock.java
+++ b/net/minecraft/server/ItemBlock.java
2019-04-23 04:00:00 +02:00
@@ -3,6 +3,11 @@
import java.util.Iterator;
2018-07-15 02:00:00 +02:00
import java.util.Map;
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.craftbukkit.block.data.CraftBlockData;
+import org.bukkit.event.block.BlockCanBuildEvent;
+// CraftBukkit end
public class ItemBlock extends Item {
2019-04-23 04:00:00 +02:00
@@ -55,7 +60,7 @@
2019-04-23 04:00:00 +02:00
SoundEffectType soundeffecttype = iblockdata1.r();
2018-07-15 02:00:00 +02:00
2019-07-20 01:00:00 +02:00
- world.playSound(entityhuman, blockposition, this.a(iblockdata1), SoundCategory.BLOCKS, (soundeffecttype.a() + 1.0F) / 2.0F, soundeffecttype.b() * 0.8F);
+ // world.playSound(entityhuman, blockposition, this.a(iblockdata1), SoundCategory.BLOCKS, (soundeffecttype.a() + 1.0F) / 2.0F, soundeffecttype.b() * 0.8F);
2019-04-23 04:00:00 +02:00
itemstack.subtract(1);
return EnumInteractionResult.SUCCESS;
}
@@ -89,6 +94,21 @@
if (nbttagcompound != null) {
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompound("BlockStateTag");
+ // CraftBukkit start
+ iblockdata1 = getBlockState(iblockdata1, nbttagcompound1);
+ }
+
+ if (iblockdata1 != iblockdata) {
+ world.setTypeAndData(blockposition, iblockdata1, 2);
+ }
+
+ return iblockdata1;
+ }
+
+ public static IBlockData getBlockState(IBlockData iblockdata, NBTTagCompound nbttagcompound1) {
+ IBlockData iblockdata1 = iblockdata;
+ {
+ // CraftBukkit end
BlockStateList<Block, IBlockData> blockstatelist = iblockdata.getBlock().getStates();
Iterator iterator = nbttagcompound1.getKeys().iterator();
@@ -103,11 +123,6 @@
}
}
}
-
- if (iblockdata1 != iblockdata) {
- world.setTypeAndData(blockposition, iblockdata1, 2);
- }
-
return iblockdata1;
}
@@ -120,8 +135,15 @@
2018-07-15 02:00:00 +02:00
protected boolean b(BlockActionContext blockactioncontext, IBlockData iblockdata) {
2019-04-23 04:00:00 +02:00
EntityHuman entityhuman = blockactioncontext.getEntity();
VoxelShapeCollision voxelshapecollision = entityhuman == null ? VoxelShapeCollision.a() : VoxelShapeCollision.a((Entity) entityhuman);
2018-07-15 02:00:00 +02:00
+ // CraftBukkit start - store default return
2019-12-10 23:00:00 +01:00
+ boolean defaultReturn = (!this.T_() || iblockdata.canPlace(blockactioncontext.getWorld(), blockactioncontext.getClickPosition())) && blockactioncontext.getWorld().a(iblockdata, blockactioncontext.getClickPosition(), voxelshapecollision);
2018-11-17 23:27:46 +01:00
+ org.bukkit.entity.Player player = (blockactioncontext.getEntity() instanceof EntityPlayer) ? (org.bukkit.entity.Player) blockactioncontext.getEntity().getBukkitEntity() : null;
+
2018-11-17 23:27:46 +01:00
+ BlockCanBuildEvent event = new BlockCanBuildEvent(CraftBlock.at(blockactioncontext.getWorld(), blockactioncontext.getClickPosition()), player, CraftBlockData.fromData(iblockdata), defaultReturn);
2018-07-15 02:00:00 +02:00
+ blockactioncontext.getWorld().getServer().getPluginManager().callEvent(event);
2019-12-10 23:00:00 +01:00
- return (!this.T_() || iblockdata.canPlace(blockactioncontext.getWorld(), blockactioncontext.getClickPosition())) && blockactioncontext.getWorld().a(iblockdata, blockactioncontext.getClickPosition(), voxelshapecollision);
2018-07-15 02:00:00 +02:00
+ return event.isBuildable();
+ // CraftBukkit end
}
2019-12-10 23:00:00 +01:00
protected boolean T_() {