forked from Minestom/Minestom
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Closed
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershacktoberfestOnly be used during the HacktoberfestOnly be used during the Hacktoberfest
Description
Since the view engine takes into account various distances and more, the explosion should be linked to the view engine.
This means that the sound of the explosion is only played locally instead of over the whole world.
Current code:
/**
* Performs the explosion and send the corresponding packet
*
* @param instance instance to perform this explosion in
*/
public void apply(@NotNull Instance instance) {
List<Point> blocks = prepare(instance);
byte[] records = new byte[3 * blocks.size()];
for (int i = 0; i < blocks.size(); i++) {
final var pos = blocks.get(i);
instance.setBlock(pos, Block.AIR);
final byte x = (byte) (pos.x() - Math.floor(getCenterX()));
final byte y = (byte) (pos.y() - Math.floor(getCenterY()));
final byte z = (byte) (pos.z() - Math.floor(getCenterZ()));
records[i * 3 + 0] = x;
records[i * 3 + 1] = y;
records[i * 3 + 2] = z;
}
// TODO send only to close players
ExplosionPacket packet = new ExplosionPacket(centerX, centerY, centerZ, strength,
records, 0, 0, 0);
postExplosion(instance, blocks, packet);
PacketUtils.sendGroupedPacket(instance.getPlayers(), packet);
postSend(instance, blocks);
}Example Code:
/**
* Performs the explosion and send the corresponding packet
*
* @param instance instance to perform this explosion in
*/
public void apply(@NotNull Instance instance) {
List<Point> blocks = prepare(instance);
byte[] records = new byte[3 * blocks.size()];
for (int i = 0; i < blocks.size(); i++) {
final var pos = blocks.get(i);
instance.setBlock(pos, Block.AIR);
final byte x = (byte) (pos.x() - Math.floor(getCenterX()));
final byte y = (byte) (pos.y() - Math.floor(getCenterY()));
final byte z = (byte) (pos.z() - Math.floor(getCenterZ()));
records[i * 3 + 0] = x;
records[i * 3 + 1] = y;
records[i * 3 + 2] = z;
}
ExplosionPacket packet = new ExplosionPacket(centerX, centerY, centerZ, strength,
records, 0, 0, 0);
postExplosion(instance, blocks, packet);
List<Player> players = instance.getNearbyEntities(new Pos(centerX, centerY, centerZ), ServerFlag.ENTITY_VIEW_DISTANCE)
.stream()
.filter(Player.class::isInstance)
.map(Player.class::cast).toList();
PacketUtils.sendGroupedPacket(players, packet);
postSend(instance, blocks);
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershacktoberfestOnly be used during the HacktoberfestOnly be used during the Hacktoberfest
Type
Projects
Status
✅ Done