mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-07 00:48:28 +01:00
Add some inline packet initialization
This commit is contained in:
parent
e635e29a16
commit
1f2dc0cd9f
@ -1379,9 +1379,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
* @param entity the entity to spectate
|
||||
*/
|
||||
public void spectate(@NotNull Entity entity) {
|
||||
CameraPacket cameraPacket = new CameraPacket();
|
||||
cameraPacket.cameraId = entity.getEntityId();
|
||||
playerConnection.sendPacket(cameraPacket);
|
||||
playerConnection.sendPacket(new CameraPacket(entity));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -750,10 +750,7 @@ public class InstanceContainer extends Instance {
|
||||
* @param blockStateId the new state of the block
|
||||
*/
|
||||
private void sendBlockChange(@NotNull Chunk chunk, @NotNull BlockPosition blockPosition, short blockStateId) {
|
||||
BlockChangePacket blockChangePacket = new BlockChangePacket();
|
||||
blockChangePacket.blockPosition = blockPosition;
|
||||
blockChangePacket.blockStateId = blockStateId;
|
||||
chunk.sendPacketToViewers(blockChangePacket);
|
||||
chunk.sendPacketToViewers(new BlockChangePacket(blockPosition, blockStateId));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -104,10 +104,7 @@ public class BlockPlacementListener {
|
||||
//Send a block change with AIR as block to keep the client in sync,
|
||||
//using refreshChunk results in the client not being in sync
|
||||
//after rapid invalid block placements
|
||||
BlockChangePacket blockChangePacket = new BlockChangePacket();
|
||||
blockChangePacket.blockPosition = blockPosition;
|
||||
blockChangePacket.blockStateId = Block.AIR.getBlockId();
|
||||
player.getPlayerConnection().sendPacket(blockChangePacket);
|
||||
player.getPlayerConnection().sendPacket(new BlockChangePacket(blockPosition, Block.AIR.getBlockId()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -263,13 +263,6 @@ public class PlayerDiggingListener {
|
||||
*/
|
||||
private static void sendAcknowledgePacket(@NotNull Player player, @NotNull BlockPosition blockPosition, int blockStateId,
|
||||
@NotNull ClientPlayerDiggingPacket.Status status, boolean success) {
|
||||
AcknowledgePlayerDiggingPacket acknowledgePlayerDiggingPacket = new AcknowledgePlayerDiggingPacket();
|
||||
acknowledgePlayerDiggingPacket.blockPosition = blockPosition;
|
||||
acknowledgePlayerDiggingPacket.blockStateId = blockStateId;
|
||||
acknowledgePlayerDiggingPacket.status = status;
|
||||
acknowledgePlayerDiggingPacket.successful = success;
|
||||
|
||||
player.getPlayerConnection().sendPacket(acknowledgePlayerDiggingPacket);
|
||||
player.getPlayerConnection().sendPacket(new AcknowledgePlayerDiggingPacket(blockPosition, blockStateId, status, success));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,12 +10,22 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AcknowledgePlayerDiggingPacket implements ServerPacket {
|
||||
|
||||
public BlockPosition blockPosition = new BlockPosition(0,0,0);
|
||||
public BlockPosition blockPosition;
|
||||
public int blockStateId;
|
||||
public ClientPlayerDiggingPacket.Status status = ClientPlayerDiggingPacket.Status.STARTED_DIGGING;
|
||||
public ClientPlayerDiggingPacket.Status status;
|
||||
public boolean successful;
|
||||
|
||||
public AcknowledgePlayerDiggingPacket() {}
|
||||
public AcknowledgePlayerDiggingPacket(@NotNull BlockPosition blockPosition, int blockStateId,
|
||||
@NotNull ClientPlayerDiggingPacket.Status status, boolean success) {
|
||||
this.blockPosition = blockPosition;
|
||||
this.blockStateId = blockStateId;
|
||||
this.status = status;
|
||||
this.successful = success;
|
||||
}
|
||||
|
||||
public AcknowledgePlayerDiggingPacket() {
|
||||
this(new BlockPosition(0, 0, 0), 0, ClientPlayerDiggingPacket.Status.STARTED_DIGGING, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
|
@ -9,13 +9,14 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionBarPacket implements ServerPacket {
|
||||
|
||||
public Component actionBarText = Component.empty();
|
||||
public Component actionBarText;
|
||||
|
||||
public ActionBarPacket() {
|
||||
public ActionBarPacket(@NotNull Component actionBarText) {
|
||||
this.actionBarText = actionBarText;
|
||||
}
|
||||
|
||||
public ActionBarPacket(Component actionBarText) {
|
||||
this.actionBarText = actionBarText;
|
||||
public ActionBarPacket() {
|
||||
this(Component.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,17 +1,30 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class AttachEntityPacket implements ServerPacket {
|
||||
|
||||
public int attachedEntityId;
|
||||
public int holdingEntityId; // Or -1 to detach
|
||||
|
||||
public AttachEntityPacket() {}
|
||||
public AttachEntityPacket(int attachedEntityId, int holdingEntityId) {
|
||||
this.attachedEntityId = attachedEntityId;
|
||||
this.holdingEntityId = holdingEntityId;
|
||||
}
|
||||
|
||||
public AttachEntityPacket(@NotNull Entity attachedEntity, @Nullable Entity holdingEntity) {
|
||||
this(attachedEntity.getEntityId(), holdingEntity != null ? holdingEntity.getEntityId() : -1);
|
||||
}
|
||||
|
||||
public AttachEntityPacket() {
|
||||
this(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
|
@ -12,8 +12,13 @@ public class BlockChangePacket implements ServerPacket {
|
||||
public BlockPosition blockPosition;
|
||||
public int blockStateId;
|
||||
|
||||
public BlockChangePacket(BlockPosition blockPosition, int blockStateId) {
|
||||
this.blockPosition = blockPosition;
|
||||
this.blockStateId = blockStateId;
|
||||
}
|
||||
|
||||
public BlockChangePacket() {
|
||||
blockPosition = new BlockPosition(0,0,0);
|
||||
this(new BlockPosition(0, 0, 0), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
@ -10,7 +11,17 @@ public class CameraPacket implements ServerPacket {
|
||||
|
||||
public int cameraId;
|
||||
|
||||
public CameraPacket() {}
|
||||
public CameraPacket(int cameraId) {
|
||||
this.cameraId = cameraId;
|
||||
}
|
||||
|
||||
public CameraPacket(@NotNull Entity camera) {
|
||||
this(camera.getEntityId());
|
||||
}
|
||||
|
||||
public CameraPacket() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
|
@ -26,18 +26,16 @@ public class ChatMessagePacket implements ComponentHoldingServerPacket {
|
||||
public ChatPosition position;
|
||||
public UUID uuid;
|
||||
|
||||
public ChatMessagePacket() {
|
||||
this.message = Component.empty();
|
||||
this.position = ChatPosition.SYSTEM_MESSAGE;
|
||||
this.uuid = NULL_UUID;
|
||||
}
|
||||
|
||||
public ChatMessagePacket(@NotNull Component message, @NotNull ChatPosition position, @Nullable UUID uuid) {
|
||||
this.message = message;
|
||||
this.position = position;
|
||||
this.uuid = Objects.requireNonNullElse(uuid, NULL_UUID);
|
||||
}
|
||||
|
||||
public ChatMessagePacket() {
|
||||
this(Component.empty(), ChatPosition.SYSTEM_MESSAGE, NULL_UUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeComponent(message);
|
||||
|
Loading…
Reference in New Issue
Block a user