mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-27 13:06:02 +01:00
Re-Implement BlockDamage
This commit is contained in:
parent
f33de669fb
commit
49043a8aff
@ -2,6 +2,7 @@ package net.minecraft.server;
|
||||
|
||||
// CraftBukkit start
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockDamageEvent;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||
import org.bukkit.event.Event;
|
||||
@ -66,9 +67,21 @@ public class ItemInWorldManager {
|
||||
if (event.useInteractedBlock() != Event.Result.DENY) {
|
||||
Block.byId[l].b(this.b, i, j, k, this.a);
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
if (l > 0 && Block.byId[l].a(this.a) >= 1.0F) {
|
||||
// Handle hitting a block
|
||||
float toolDamage = Block.byId[l].a(this.a);
|
||||
BlockDamageEvent blockEvent = CraftEventFactory.callBlockDamageEvent(this.a, i, j, k, this.a.inventory.b(), toolDamage >= 1.0f);
|
||||
|
||||
if (blockEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (blockEvent.getInstaBreak()) {
|
||||
toolDamage = 2.0f;
|
||||
}
|
||||
|
||||
if (toolDamage >= 1.0F) {
|
||||
// CraftBukkit end
|
||||
this.d(i, j, k);
|
||||
} else {
|
||||
this.g = i;
|
||||
|
@ -9,7 +9,6 @@ import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockDamageLevel;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
@ -54,10 +53,6 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
|
||||
private final CraftServer server;
|
||||
|
||||
// Get position of last block hit for BlockDamageLevel.STOPPED
|
||||
private int lastX;
|
||||
private int lastY;
|
||||
private int lastZ;
|
||||
|
||||
private double lastPosX = Double.MIN_VALUE;
|
||||
private double lastPosY = Double.MIN_VALUE;
|
||||
private double lastPosZ = Double.MIN_VALUE;
|
||||
@ -330,48 +325,13 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
|
||||
i1 = l;
|
||||
}
|
||||
|
||||
// CraftBukkit start
|
||||
CraftPlayer player = getPlayer();
|
||||
CraftBlock block = (CraftBlock) player.getWorld().getBlockAt(i, j, k);
|
||||
int blockId = block.getTypeId();
|
||||
float damage = 0;
|
||||
if (Block.byId[blockId] != null) {
|
||||
damage = Block.byId[blockId].a(player.getHandle()); // Get amount of damage going to block
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
if (packet14blockdig.e == 0) {
|
||||
// CraftBukkit start
|
||||
// CraftBukkit
|
||||
if (i1 > this.d.spawnProtection || flag) {
|
||||
BlockDamageEvent event;
|
||||
// If the amount of damage that the player is going to do to the block
|
||||
// is >= 1, then the block is going to break (eg, flowers, torches)
|
||||
if (damage >= 1.0F) {
|
||||
// if we are destroying either a redstone wire with a current greater than 0 or
|
||||
// a redstone torch that is on, then we should notify plugins that this block has
|
||||
// returned to a current value of 0 (since it will once the redstone is destroyed)
|
||||
if ((blockId == Block.REDSTONE_WIRE.id && block.getData() > 0) || blockId == Block.REDSTONE_TORCH_ON.id) {
|
||||
server.getPluginManager().callEvent( new BlockRedstoneEvent(block, (blockId == Block.REDSTONE_WIRE.id ? block.getData() : 15), 0));
|
||||
}
|
||||
event = new BlockDamageEvent(Type.BLOCK_DAMAGE, block, BlockDamageLevel.BROKEN, player);
|
||||
} else {
|
||||
event = new BlockDamageEvent(Type.BLOCK_DAMAGE, block, BlockDamageLevel.STARTED, player);
|
||||
}
|
||||
server.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
this.e.c.a(i, j, k);
|
||||
}
|
||||
this.e.c.a(i, j, k);
|
||||
}
|
||||
} else if (packet14blockdig.e == 2) {
|
||||
// CraftBukkit start - Get last block that the player hit
|
||||
// Otherwise the block is a Bedrock @(0,0,0)
|
||||
block = (CraftBlock) player.getWorld().getBlockAt(lastX, lastY, lastZ);
|
||||
BlockDamageEvent event = new BlockDamageEvent(Type.BLOCK_DAMAGE, block, BlockDamageLevel.STOPPED, player);
|
||||
server.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
this.e.c.b(i, j, k);
|
||||
}
|
||||
// CraftBukkit end
|
||||
this.e.c.b(i, j, k);
|
||||
} else if (packet14blockdig.e == 3) {
|
||||
double d4 = this.e.locX - ((double) i + 0.5D);
|
||||
double d5 = this.e.locY - ((double) j + 0.5D);
|
||||
@ -384,20 +344,15 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
|
||||
}
|
||||
}
|
||||
|
||||
// CraftBukkit start
|
||||
lastX = i;
|
||||
lastY = j;
|
||||
lastZ = k;
|
||||
|
||||
// CraftBukkit
|
||||
((WorldServer) this.e.world).v = false;
|
||||
// CraftBukkit end
|
||||
}
|
||||
}
|
||||
|
||||
public void a(Packet15Place packet15place) {
|
||||
ItemStack itemstack = this.e.inventory.b();
|
||||
// CraftBukkit start
|
||||
boolean flag = ((WorldServer) this.e.world).v = this.d.f.h(this.e.name);
|
||||
// CraftBukkit start - spawn protection moved to ItemBlock!!!
|
||||
//boolean flag = this.d.e.v = this.d.f.h(this.e.name);
|
||||
|
||||
CraftBlock blockClicked = null;
|
||||
BlockFace blockFace = BlockFace.SELF;
|
||||
|
@ -18,6 +18,7 @@ import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Type;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockDamageEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||
@ -144,4 +145,19 @@ public class CraftEventFactory {
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
public static BlockDamageEvent callBlockDamageEvent(EntityHuman who, int x, int y, int z, ItemStack itemstack, boolean instaBreak) {
|
||||
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
|
||||
CraftItemStack itemInHand = new CraftItemStack(itemstack);
|
||||
|
||||
CraftWorld craftWorld = (CraftWorld) player.getWorld();
|
||||
CraftServer craftServer = (CraftServer) player.getServer();
|
||||
|
||||
Block blockClicked = craftWorld.getBlockAt(x, y, z);
|
||||
|
||||
BlockDamageEvent event = new BlockDamageEvent(player, blockClicked, itemInHand, instaBreak);
|
||||
craftServer.getPluginManager().callEvent(event);
|
||||
|
||||
return event;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user