I'm working on creating a mine system that uses packets for placing and when the player breaks the block. Everything works as it's supposed to aside from the fact that sometimes when you go to break the block it doesn't actually break it like normal. It acts as if you just hit the block once even though there's enough efficiency to instantly break it, because of how I have it setup it still removes the block but it creates this weird interaction where it doesn't look like you broke the block.
This is what it looks like:
I'm listening to PacketType.Play.Client.BLOCK_DIG to handle the block breaking and then setting the block to air with the BlockUpdate packet. Any advice is helpful, thank you.
This is what it looks like:
I'm listening to PacketType.Play.Client.BLOCK_DIG to handle the block breaking and then setting the block to air with the BlockUpdate packet. Any advice is helpful, thank you.
Java:
protocolManager.addPacketListener(new PacketAdapter(plugin, PacketType.Play.Client.BLOCK_DIG) {
@Override
public void onPacketReceiving (PacketEvent event){
PacketContainer packet = event.getPacket();
Player p = event.getPlayer();
BlockPosition pos = packet.getBlockPositionModifier().read(0);
Location loc = pos.toLocation(p.getWorld());
if (loc != null && blockLocs.get(p).containsKey(loc)) {
if (p.getEquipment().getItemInMainHand().getType() == Material.DIAMOND_PICKAXE) {
breakPacket(p, loc);
Map<Location, Material> blocks = blockLocs.get(p);
blocks.remove(loc);
blockLocs.put(p, blocks);
Mine m = MineSystem.getInstance().getMineByPlayer(p);
if (m.getBlocksLeftPercentage() < m.getResetPercent()) {
m.reset();
}
//enchants
}
}
}
});
Java:
public void breakPacket(Player p, Location loc) {
BlockPos pos = new BlockPos(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
((CraftPlayer) p).getHandle().connection.send(
new ClientboundBlockUpdatePacket(
pos,
materialToBlockState(Material.AIR)
)
);
}