3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-23 14:50:08 +01:00
Paper/nms-patches/ItemBlock.patch

106 Zeilen
5.5 KiB
Diff

--- 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 {
@@ -31,6 +36,12 @@
return EnumInteractionResult.FAIL;
} else {
IBlockData iblockdata = this.c(blockactioncontext1);
+ // CraftBukkit start - special case for handling block placement with water lilies
+ org.bukkit.block.BlockState blockstate = null;
+ if (this instanceof ItemWaterLily) {
+ blockstate = org.bukkit.craftbukkit.block.CraftBlockState.getBlockState(blockactioncontext1.getWorld(), blockactioncontext1.getClickPosition());
+ }
+ // CraftBukkit end
if (iblockdata == null) {
return EnumInteractionResult.FAIL;
@@ -48,6 +59,15 @@
iblockdata1 = this.a(blockposition, world, itemstack, iblockdata1);
this.a(blockposition, world, entityhuman, itemstack, iblockdata1);
block.postPlace(world, blockposition, iblockdata1, entityhuman, itemstack);
+ // CraftBukkit start
+ if (blockstate != null) {
+ org.bukkit.event.block.BlockPlaceEvent placeEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPlaceEvent((WorldServer) world, entityhuman, blockactioncontext1.getHand(), blockstate, blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ if (placeEvent != null && (placeEvent.isCancelled() || !placeEvent.canBuild())) {
+ blockstate.update(true, false);
+ return EnumInteractionResult.FAIL;
+ }
+ }
+ // CraftBukkit end
if (entityhuman instanceof EntityPlayer) {
CriterionTriggers.y.a((EntityPlayer) entityhuman, blockposition, itemstack);
}
@@ -55,8 +75,8 @@
2020-06-25 02:00:00 +02:00
SoundEffectType soundeffecttype = iblockdata1.getStepSound();
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);
- if (entityhuman == null || !entityhuman.abilities.canInstantlyBuild) {
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);
+ if ((entityhuman == null || !entityhuman.abilities.canInstantlyBuild) && itemstack != ItemStack.b) { // CraftBukkit
2020-06-25 02:00:00 +02:00
itemstack.subtract(1);
}
@@ -92,6 +112,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();
@@ -106,11 +141,6 @@
}
}
}
-
- if (iblockdata1 != iblockdata) {
- world.setTypeAndData(blockposition, iblockdata1, 2);
- }
-
return iblockdata1;
}
@@ -123,8 +153,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
2020-06-25 02:00:00 +02:00
+ boolean defaultReturn = (!this.isCheckCollisions() || 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);
2020-06-25 02:00:00 +02:00
- return (!this.isCheckCollisions() || 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
}
2020-06-25 02:00:00 +02:00
protected boolean isCheckCollisions() {