mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-01 21:11:33 +01:00
More inline packets
This commit is contained in:
parent
ff9ca60a58
commit
081266775c
@ -271,19 +271,8 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
|
||||
*/
|
||||
public void setView(float yaw, float pitch) {
|
||||
this.position = position.withView(yaw, pitch);
|
||||
|
||||
EntityRotationPacket entityRotationPacket = new EntityRotationPacket();
|
||||
entityRotationPacket.entityId = getEntityId();
|
||||
entityRotationPacket.yaw = yaw;
|
||||
entityRotationPacket.pitch = pitch;
|
||||
entityRotationPacket.onGround = onGround;
|
||||
|
||||
EntityHeadLookPacket entityHeadLookPacket = new EntityHeadLookPacket();
|
||||
entityHeadLookPacket.entityId = getEntityId();
|
||||
entityHeadLookPacket.yaw = yaw;
|
||||
|
||||
sendPacketToViewersAndSelf(entityHeadLookPacket);
|
||||
sendPacketToViewersAndSelf(entityRotationPacket);
|
||||
sendPacketToViewersAndSelf(new EntityHeadLookPacket(getEntityId(), yaw));
|
||||
sendPacketToViewersAndSelf(new EntityRotationPacket(getEntityId(), yaw, pitch, onGround));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -330,20 +319,12 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
|
||||
playerConnection.sendPacket(getVelocityPacket());
|
||||
}
|
||||
playerConnection.sendPacket(getMetadataPacket());
|
||||
|
||||
// Passenger
|
||||
if (hasPassenger()) {
|
||||
playerConnection.sendPacket(getPassengersPacket());
|
||||
}
|
||||
|
||||
// Head position
|
||||
{
|
||||
EntityHeadLookPacket entityHeadLookPacket = new EntityHeadLookPacket();
|
||||
entityHeadLookPacket.entityId = getEntityId();
|
||||
entityHeadLookPacket.yaw = position.yaw();
|
||||
playerConnection.sendPacket(entityHeadLookPacket);
|
||||
}
|
||||
|
||||
playerConnection.sendPacket(new EntityHeadLookPacket(getEntityId(), position.yaw()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -948,10 +929,7 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
|
||||
* @param status the status to trigger
|
||||
*/
|
||||
public void triggerStatus(byte status) {
|
||||
EntityStatusPacket statusPacket = new EntityStatusPacket();
|
||||
statusPacket.entityId = getEntityId();
|
||||
statusPacket.status = status;
|
||||
sendPacketToViewersAndSelf(statusPacket);
|
||||
sendPacketToViewersAndSelf(new EntityStatusPacket(getEntityId(), status));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1381,13 +1359,7 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
|
||||
}
|
||||
|
||||
protected @NotNull EntityVelocityPacket getVelocityPacket() {
|
||||
EntityVelocityPacket velocityPacket = new EntityVelocityPacket();
|
||||
velocityPacket.entityId = getEntityId();
|
||||
Vec velocity = getVelocityForPacket();
|
||||
velocityPacket.velocityX = (short) velocity.x();
|
||||
velocityPacket.velocityY = (short) velocity.y();
|
||||
velocityPacket.velocityZ = (short) velocity.z();
|
||||
return velocityPacket;
|
||||
return new EntityVelocityPacket(getEntityId(), getVelocityForPacket());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,11 +48,7 @@ public enum EntitySpawnType {
|
||||
PLAYER {
|
||||
@Override
|
||||
public ServerPacket getSpawnPacket(Entity entity) {
|
||||
SpawnPlayerPacket packet = new SpawnPlayerPacket();
|
||||
packet.entityId = entity.getEntityId();
|
||||
packet.playerUuid = entity.getUuid();
|
||||
packet.position = entity.getPosition();
|
||||
return packet;
|
||||
return new SpawnPlayerPacket(entity.getEntityId(), entity.getUuid(), entity.getPosition());
|
||||
}
|
||||
},
|
||||
EXPERIENCE_ORB {
|
||||
|
@ -206,8 +206,7 @@ public class LivingEntity extends Entity implements EquipmentHandler {
|
||||
final Set<Entity> entities = instance.getChunkEntities(chunk);
|
||||
for (Entity entity : entities) {
|
||||
if (entity instanceof ItemEntity) {
|
||||
|
||||
// Do not pickup if not visible
|
||||
// Do not pick up if not visible
|
||||
if (this instanceof Player && !entity.isViewer((Player) this))
|
||||
continue;
|
||||
|
||||
@ -222,12 +221,7 @@ public class LivingEntity extends Entity implements EquipmentHandler {
|
||||
PickupItemEvent pickupItemEvent = new PickupItemEvent(this, itemEntity);
|
||||
EventDispatcher.callCancellable(pickupItemEvent, () -> {
|
||||
final ItemStack item = itemEntity.getItemStack();
|
||||
|
||||
CollectItemPacket collectItemPacket = new CollectItemPacket();
|
||||
collectItemPacket.collectedEntityId = itemEntity.getEntityId();
|
||||
collectItemPacket.collectorEntityId = getEntityId();
|
||||
collectItemPacket.pickupItemCount = item.getAmount();
|
||||
sendPacketToViewersAndSelf(collectItemPacket);
|
||||
sendPacketToViewersAndSelf(new CollectItemPacket(itemEntity.getEntityId(), getEntityId(), item.getAmount()));
|
||||
entity.remove();
|
||||
});
|
||||
}
|
||||
@ -358,10 +352,7 @@ public class LivingEntity extends Entity implements EquipmentHandler {
|
||||
|
||||
float remainingDamage = entityDamageEvent.getDamage();
|
||||
|
||||
EntityAnimationPacket entityAnimationPacket = new EntityAnimationPacket();
|
||||
entityAnimationPacket.entityId = getEntityId();
|
||||
entityAnimationPacket.animation = EntityAnimationPacket.Animation.TAKE_DAMAGE;
|
||||
sendPacketToViewersAndSelf(entityAnimationPacket);
|
||||
sendPacketToViewersAndSelf(new EntityAnimationPacket(getEntityId(), EntityAnimationPacket.Animation.TAKE_DAMAGE));
|
||||
|
||||
// Additional hearts support
|
||||
if (this instanceof Player) {
|
||||
@ -546,11 +537,9 @@ public class LivingEntity extends Entity implements EquipmentHandler {
|
||||
final PlayerConnection playerConnection = player.getPlayerConnection();
|
||||
playerConnection.sendPacket(getEquipmentsPacket());
|
||||
playerConnection.sendPacket(getPropertiesPacket());
|
||||
|
||||
if (getTeam() != null) {
|
||||
playerConnection.sendPacket(getTeam().createTeamsCreationPacket());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -565,10 +554,7 @@ public class LivingEntity extends Entity implements EquipmentHandler {
|
||||
* (can be used for attack animation).
|
||||
*/
|
||||
public void swingMainHand() {
|
||||
EntityAnimationPacket animationPacket = new EntityAnimationPacket();
|
||||
animationPacket.entityId = getEntityId();
|
||||
animationPacket.animation = EntityAnimationPacket.Animation.SWING_MAIN_ARM;
|
||||
sendPacketToViewers(animationPacket);
|
||||
sendPacketToViewers(new EntityAnimationPacket(getEntityId(), EntityAnimationPacket.Animation.SWING_MAIN_ARM));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -576,10 +562,7 @@ public class LivingEntity extends Entity implements EquipmentHandler {
|
||||
* (can be used for attack animation).
|
||||
*/
|
||||
public void swingOffHand() {
|
||||
EntityAnimationPacket animationPacket = new EntityAnimationPacket();
|
||||
animationPacket.entityId = getEntityId();
|
||||
animationPacket.animation = EntityAnimationPacket.Animation.SWING_OFF_HAND;
|
||||
sendPacketToViewers(animationPacket);
|
||||
sendPacketToViewers(new EntityAnimationPacket(getEntityId(), EntityAnimationPacket.Animation.SWING_OFF_HAND));
|
||||
}
|
||||
|
||||
public void refreshActiveHand(boolean isHandActive, boolean offHand, boolean riptideSpinAttack) {
|
||||
|
@ -12,7 +12,15 @@ public class CollectItemPacket implements ServerPacket {
|
||||
public int collectorEntityId;
|
||||
public int pickupItemCount;
|
||||
|
||||
public CollectItemPacket() {}
|
||||
public CollectItemPacket(int collectedEntityId, int collectorEntityId, int pickupItemCount) {
|
||||
this.collectedEntityId = collectedEntityId;
|
||||
this.collectorEntityId = collectorEntityId;
|
||||
this.pickupItemCount = pickupItemCount;
|
||||
}
|
||||
|
||||
public CollectItemPacket() {
|
||||
this(0, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
|
@ -11,8 +11,13 @@ public class EntityAnimationPacket implements ServerPacket {
|
||||
public int entityId;
|
||||
public Animation animation;
|
||||
|
||||
public EntityAnimationPacket(int entityId, Animation animation) {
|
||||
this.entityId = entityId;
|
||||
this.animation = animation;
|
||||
}
|
||||
|
||||
public EntityAnimationPacket() {
|
||||
animation = Animation.SWING_MAIN_ARM;
|
||||
this(0, Animation.SWING_MAIN_ARM);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,7 +11,14 @@ public class EntityStatusPacket implements ServerPacket {
|
||||
public int entityId;
|
||||
public byte status;
|
||||
|
||||
public EntityStatusPacket() {}
|
||||
public EntityStatusPacket(int entityId, byte status) {
|
||||
this.entityId = entityId;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public EntityStatusPacket() {
|
||||
this(0, (byte) 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
@ -11,7 +12,20 @@ public class EntityVelocityPacket implements ServerPacket {
|
||||
public int entityId;
|
||||
public short velocityX, velocityY, velocityZ;
|
||||
|
||||
public EntityVelocityPacket() {}
|
||||
public EntityVelocityPacket(int entityId, short velocityX, short velocityY, short velocityZ) {
|
||||
this.entityId = entityId;
|
||||
this.velocityX = velocityX;
|
||||
this.velocityY = velocityY;
|
||||
this.velocityZ = velocityZ;
|
||||
}
|
||||
|
||||
public EntityVelocityPacket(int entityId, Point velocity) {
|
||||
this(entityId, (short) velocity.x(), (short) velocity.y(), (short) velocity.z());
|
||||
}
|
||||
|
||||
public EntityVelocityPacket() {
|
||||
this(0, (short) 0, (short) 0, (short) 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
|
@ -1,10 +1,10 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
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 net.minestom.server.coordinate.Pos;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -15,9 +15,14 @@ public class SpawnPlayerPacket implements ServerPacket {
|
||||
public UUID playerUuid;
|
||||
public Pos position;
|
||||
|
||||
public SpawnPlayerPacket(int entityId, UUID playerUuid, Pos position) {
|
||||
this.entityId = entityId;
|
||||
this.playerUuid = playerUuid;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public SpawnPlayerPacket() {
|
||||
playerUuid = new UUID(0, 0);
|
||||
position = Pos.ZERO;
|
||||
this(0, new UUID(0, 0), Pos.ZERO);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user