Allow for separate blocks in PlayerBlockBreakEvent

This commit is contained in:
Felix Cravic 2020-05-17 15:52:49 +02:00
parent f588d1103f
commit c50030cd6b
3 changed files with 23 additions and 24 deletions

View File

@ -7,32 +7,36 @@ public class PlayerBlockBreakEvent extends CancellableEvent {
private BlockPosition blockPosition;
private short blockId;
private boolean customBlock;
private short resultBlockId;
private short resultCustomBlockId;
public PlayerBlockBreakEvent(BlockPosition blockPosition) {
public PlayerBlockBreakEvent(BlockPosition blockPosition, short resultBlockId, short resultCustomBlockId) {
this.blockPosition = blockPosition;
this.resultBlockId = resultBlockId;
this.resultCustomBlockId = resultCustomBlockId;
}
public BlockPosition getBlockPosition() {
return blockPosition;
}
public short getResultBlock() {
return blockId;
public short getResultBlockId() {
return resultBlockId;
}
public void setResultBlock(short blockId) {
this.blockId = blockId;
this.customBlock = false;
public void setResultBlockId(short resultBlockId) {
this.resultBlockId = resultBlockId;
}
public short getResultCustomBlockId() {
return resultCustomBlockId;
}
public void setResultCustomBlockId(short resultCustomBlockId) {
this.resultCustomBlockId = resultCustomBlockId;
}
public boolean isResultCustomBlock() {
return customBlock;
}
public void setResultCustomBlock(short customBlockId) {
this.blockId = customBlockId;
this.customBlock = true;
return resultCustomBlockId != 0;
}
}

View File

@ -213,23 +213,19 @@ public class InstanceContainer extends Instance {
int z = blockPosition.getZ();
short blockId = chunk.getBlockId(x, y, z);
// The player probably have a wrong version of this chunk section, send it
if (blockId == 0) {
sendChunkSectionUpdate(chunk, ChunkUtils.getSectionAt(y), player);
return;
}
PlayerBlockBreakEvent blockBreakEvent = new PlayerBlockBreakEvent(blockPosition);
PlayerBlockBreakEvent blockBreakEvent = new PlayerBlockBreakEvent(blockPosition, (short) 0, (short) 0);
player.callEvent(PlayerBlockBreakEvent.class, blockBreakEvent);
if (!blockBreakEvent.isCancelled()) {
// Break or change the broken block based on event result
short resultBlockId = blockBreakEvent.getResultBlock();
boolean custom = blockBreakEvent.isResultCustomBlock();
if (custom) {
setCustomBlock(x, y, z, resultBlockId);
} else {
setBlock(x, y, z, resultBlockId);
}
setSeparateBlocks(x, y, z, blockBreakEvent.getResultBlockId(), blockBreakEvent.getResultCustomBlockId());
ParticlePacket particlePacket = ParticleCreator.createParticlePacket(Particle.BLOCK, false,
x + 0.5f, y, z + 0.5f,
@ -240,6 +236,7 @@ public class InstanceContainer extends Instance {
chunk.sendPacketToViewers(particlePacket);
} else {
// Cancelled so we need to refresh player chunk section
sendChunkSectionUpdate(chunk, ChunkUtils.getSectionAt(blockPosition.getY()), player);
}
}

View File

@ -395,8 +395,6 @@ public class RegistryMain {
}
private static JsonObject parse(String path, String key) {
List<RegistryStat> registryStats = new ArrayList<>();
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new FileReader(path));