mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-17 05:31:23 +01:00
Allow for separate blocks in PlayerBlockBreakEvent
This commit is contained in:
parent
f588d1103f
commit
c50030cd6b
@ -7,32 +7,36 @@ public class PlayerBlockBreakEvent extends CancellableEvent {
|
|||||||
|
|
||||||
private BlockPosition blockPosition;
|
private BlockPosition blockPosition;
|
||||||
|
|
||||||
private short blockId;
|
private short resultBlockId;
|
||||||
private boolean customBlock;
|
private short resultCustomBlockId;
|
||||||
|
|
||||||
public PlayerBlockBreakEvent(BlockPosition blockPosition) {
|
public PlayerBlockBreakEvent(BlockPosition blockPosition, short resultBlockId, short resultCustomBlockId) {
|
||||||
this.blockPosition = blockPosition;
|
this.blockPosition = blockPosition;
|
||||||
|
this.resultBlockId = resultBlockId;
|
||||||
|
this.resultCustomBlockId = resultCustomBlockId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockPosition getBlockPosition() {
|
public BlockPosition getBlockPosition() {
|
||||||
return blockPosition;
|
return blockPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public short getResultBlock() {
|
public short getResultBlockId() {
|
||||||
return blockId;
|
return resultBlockId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setResultBlock(short blockId) {
|
public void setResultBlockId(short resultBlockId) {
|
||||||
this.blockId = blockId;
|
this.resultBlockId = resultBlockId;
|
||||||
this.customBlock = false;
|
}
|
||||||
|
|
||||||
|
public short getResultCustomBlockId() {
|
||||||
|
return resultCustomBlockId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResultCustomBlockId(short resultCustomBlockId) {
|
||||||
|
this.resultCustomBlockId = resultCustomBlockId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isResultCustomBlock() {
|
public boolean isResultCustomBlock() {
|
||||||
return customBlock;
|
return resultCustomBlockId != 0;
|
||||||
}
|
|
||||||
|
|
||||||
public void setResultCustomBlock(short customBlockId) {
|
|
||||||
this.blockId = customBlockId;
|
|
||||||
this.customBlock = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,23 +213,19 @@ public class InstanceContainer extends Instance {
|
|||||||
int z = blockPosition.getZ();
|
int z = blockPosition.getZ();
|
||||||
|
|
||||||
short blockId = chunk.getBlockId(x, y, z);
|
short blockId = chunk.getBlockId(x, y, z);
|
||||||
|
|
||||||
|
// The player probably have a wrong version of this chunk section, send it
|
||||||
if (blockId == 0) {
|
if (blockId == 0) {
|
||||||
sendChunkSectionUpdate(chunk, ChunkUtils.getSectionAt(y), player);
|
sendChunkSectionUpdate(chunk, ChunkUtils.getSectionAt(y), player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerBlockBreakEvent blockBreakEvent = new PlayerBlockBreakEvent(blockPosition);
|
PlayerBlockBreakEvent blockBreakEvent = new PlayerBlockBreakEvent(blockPosition, (short) 0, (short) 0);
|
||||||
player.callEvent(PlayerBlockBreakEvent.class, blockBreakEvent);
|
player.callEvent(PlayerBlockBreakEvent.class, blockBreakEvent);
|
||||||
if (!blockBreakEvent.isCancelled()) {
|
if (!blockBreakEvent.isCancelled()) {
|
||||||
|
|
||||||
// Break or change the broken block based on event result
|
// Break or change the broken block based on event result
|
||||||
short resultBlockId = blockBreakEvent.getResultBlock();
|
setSeparateBlocks(x, y, z, blockBreakEvent.getResultBlockId(), blockBreakEvent.getResultCustomBlockId());
|
||||||
boolean custom = blockBreakEvent.isResultCustomBlock();
|
|
||||||
if (custom) {
|
|
||||||
setCustomBlock(x, y, z, resultBlockId);
|
|
||||||
} else {
|
|
||||||
setBlock(x, y, z, resultBlockId);
|
|
||||||
}
|
|
||||||
|
|
||||||
ParticlePacket particlePacket = ParticleCreator.createParticlePacket(Particle.BLOCK, false,
|
ParticlePacket particlePacket = ParticleCreator.createParticlePacket(Particle.BLOCK, false,
|
||||||
x + 0.5f, y, z + 0.5f,
|
x + 0.5f, y, z + 0.5f,
|
||||||
@ -240,6 +236,7 @@ public class InstanceContainer extends Instance {
|
|||||||
|
|
||||||
chunk.sendPacketToViewers(particlePacket);
|
chunk.sendPacketToViewers(particlePacket);
|
||||||
} else {
|
} else {
|
||||||
|
// Cancelled so we need to refresh player chunk section
|
||||||
sendChunkSectionUpdate(chunk, ChunkUtils.getSectionAt(blockPosition.getY()), player);
|
sendChunkSectionUpdate(chunk, ChunkUtils.getSectionAt(blockPosition.getY()), player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -395,8 +395,6 @@ public class RegistryMain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static JsonObject parse(String path, String key) {
|
private static JsonObject parse(String path, String key) {
|
||||||
List<RegistryStat> registryStats = new ArrayList<>();
|
|
||||||
|
|
||||||
BufferedReader bufferedReader = null;
|
BufferedReader bufferedReader = null;
|
||||||
try {
|
try {
|
||||||
bufferedReader = new BufferedReader(new FileReader(path));
|
bufferedReader = new BufferedReader(new FileReader(path));
|
||||||
|
Loading…
Reference in New Issue
Block a user