mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-27 13:06:02 +01:00
Added getBlockReplacedState to BlockPlaceEvent, in case one wants to see what type of block was there previously.
This commit is contained in:
parent
0675ead169
commit
3477a86995
@ -2,8 +2,9 @@ package net.minecraft.server;
|
|||||||
|
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.craftbukkit.CraftServer;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||||
|
import org.bukkit.craftbukkit.block.CraftBlockState;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event.Type;
|
import org.bukkit.event.Event.Type;
|
||||||
@ -59,9 +60,12 @@ public class ItemBlock extends Item {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// CraftBukkit start - store the old data so we can undo it
|
// CraftBukkit start
|
||||||
int oldMaterial = world.a(i, j, k);
|
/* We store the old data so we can undo it. Snow(78) and half-steps(44) are special in that they replace the block itself,
|
||||||
int oldData = world.b(i, j, k);
|
* rather than the block touching the face we clicked on.
|
||||||
|
*/
|
||||||
|
org.bukkit.block.Block replacedBlock = (blockClicked.getTypeId() == 78 || blockClicked.getTypeId() == 44) ? blockClicked:blockClicked.getFace(faceClicked);
|
||||||
|
final BlockState replacedBlockState = new CraftBlockState(replacedBlock);
|
||||||
|
|
||||||
if (world.a(a, i, j, k, false)) {
|
if (world.a(a, i, j, k, false)) {
|
||||||
Block block = Block.m[a];
|
Block block = Block.m[a];
|
||||||
@ -88,7 +92,7 @@ public class ItemBlock extends Item {
|
|||||||
// TODO make spawn size configurable
|
// TODO make spawn size configurable
|
||||||
boolean canBuild = distanceFromSpawn > 16 || thePlayer.isOp();
|
boolean canBuild = distanceFromSpawn > 16 || thePlayer.isOp();
|
||||||
|
|
||||||
BlockPlaceEvent bpe = new BlockPlaceEvent(eventType, placedBlock, blockClicked, itemInHand, thePlayer, canBuild);
|
BlockPlaceEvent bpe = new BlockPlaceEvent(eventType, placedBlock, replacedBlockState, blockClicked, itemInHand, thePlayer, canBuild);
|
||||||
server.getPluginManager().callEvent(bpe);
|
server.getPluginManager().callEvent(bpe);
|
||||||
|
|
||||||
if (bpe.isCancelled() || !bpe.canBuild()) {
|
if (bpe.isCancelled() || !bpe.canBuild()) {
|
||||||
@ -102,7 +106,7 @@ public class ItemBlock extends Item {
|
|||||||
world.b(i, j - 1, k, 44);
|
world.b(i, j - 1, k, 44);
|
||||||
}
|
}
|
||||||
|
|
||||||
world.a(i, j, k, oldMaterial, oldData);
|
world.a(i, j, k, replacedBlockState.getTypeId(), replacedBlockState.getData().getData());
|
||||||
} else {
|
} else {
|
||||||
world.f(i, j, k, a); // <-- world.b does this on success (tell the world)
|
world.f(i, j, k, a); // <-- world.b does this on success (tell the world)
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ public class CraftBlockState implements BlockState {
|
|||||||
|
|
||||||
private void createData(final byte data) {
|
private void createData(final byte data) {
|
||||||
Material mat = Material.getMaterial(type);
|
Material mat = Material.getMaterial(type);
|
||||||
if (mat == null) {
|
if (mat == null || mat.getData() == null) {
|
||||||
this.data = new MaterialData(type, data);
|
this.data = new MaterialData(type, data);
|
||||||
} else {
|
} else {
|
||||||
this.data = mat.getNewData(data);
|
this.data = mat.getNewData(data);
|
||||||
|
Loading…
Reference in New Issue
Block a user