Files
CatServer/patches/net/minecraft/block/BlockButton.java.patch
2019-02-24 22:29:41 +08:00

109 lines
4.6 KiB
Diff

--- ../src-base/minecraft/net/minecraft/block/BlockButton.java
+++ ../src-work/minecraft/net/minecraft/block/BlockButton.java
@@ -23,6 +23,8 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
+import org.bukkit.event.block.BlockRedstoneEvent;
+import org.bukkit.event.entity.EntityInteractEvent;
public abstract class BlockButton extends BlockDirectional
{
@@ -98,7 +100,7 @@
if (direction == EnumFacing.UP)
{
- return block == Blocks.HOPPER || !isExceptionBlockForAttaching(block) && flag;
+ return iblockstate.isTopSolid() || !isExceptionBlockForAttaching(block) && flag;
}
else
{
@@ -165,6 +167,17 @@
}
else
{
+ boolean powered = ((Boolean) state.getValue(POWERED));
+ org.bukkit.block.Block block = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
+ int old = (powered) ? 15 : 0;
+ int current = (!powered) ? 15 : 0;
+
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, old, current);
+ worldIn.getServer().getPluginManager().callEvent(eventRedstone);
+
+ if ((eventRedstone.getNewCurrent() > 0) != (!powered)) {
+ return true;
+ }
worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(true)), 3);
worldIn.markBlockRangeForRenderUpdate(pos, pos);
this.playClickSound(playerIn, worldIn, pos);
@@ -226,6 +239,14 @@
}
else
{
+ org.bukkit.block.Block block = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
+
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, 15, 0);
+ worldIn.getServer().getPluginManager().callEvent(eventRedstone);
+
+ if (eventRedstone.getNewCurrent() > 0) {
+ return;
+ }
worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(false)));
this.notifyNeighbors(worldIn, pos, (EnumFacing)state.getValue(FACING));
this.playReleaseSound(worldIn, pos);
@@ -255,8 +276,39 @@
boolean flag = !list.isEmpty();
boolean flag1 = ((Boolean)state.getValue(POWERED)).booleanValue();
+ // CraftBukkit start - Call interact event when arrows turn on wooden buttons
+ if (flag1 != flag && flag) {
+ org.bukkit.block.Block block = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
+ boolean allowed = false;
+
+ // If all of the events are cancelled block the button press, else allow
+ for (Object object : list) {
+ if (object != null) {
+ EntityInteractEvent event = new EntityInteractEvent(((Entity) object).getBukkitEntity(), block);
+ worldIn.getServer().getPluginManager().callEvent(event);
+
+ if (!event.isCancelled()) {
+ allowed = true;
+ break;
+ }
+ }
+ }
+
+ if (!allowed) {
+ return;
+ }
+ }
+
if (flag && !flag1)
{
+ org.bukkit.block.Block block = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
+
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, 0, 15);
+ worldIn.getServer().getPluginManager().callEvent(eventRedstone);
+
+ if (eventRedstone.getNewCurrent() <= 0) {
+ return;
+ }
worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(true)));
this.notifyNeighbors(worldIn, pos, (EnumFacing)state.getValue(FACING));
worldIn.markBlockRangeForRenderUpdate(pos, pos);
@@ -265,6 +317,14 @@
if (!flag && flag1)
{
+ org.bukkit.block.Block block = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
+
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, 15, 0);
+ worldIn.getServer().getPluginManager().callEvent(eventRedstone);
+
+ if (eventRedstone.getNewCurrent() > 0) {
+ return;
+ }
worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(false)));
this.notifyNeighbors(worldIn, pos, (EnumFacing)state.getValue(FACING));
worldIn.markBlockRangeForRenderUpdate(pos, pos);