use of com.bergerkiller.generated.net.minecraft.network.protocol.game.PacketPlayOutSpawnEntityLivingHandle in project BKCommonLib by bergerhealer.
the class VehicleMountHandler_BaseImpl method handlePacketSend.
/**
* Call this to handle a relevant packet that was sent from the server to the client
*
* @param packet The packet sent
*/
public final void handlePacketSend(CommonPacket packet) {
synchronizeAndQueuePackets(() -> {
// Refresh player dimension if none could be set (temporary player, pre-join)
if (this._playerDimension == null) {
this._playerDimension = PlayerUtil.getPlayerDimension(this._player);
}
// Event handler for further implementations
onPacketSend(packet);
// Handle packets
PacketType type = packet.getType();
if (type == PacketType.OUT_ENTITY_DESTROY) {
PacketPlayOutEntityDestroyHandle dp = PacketPlayOutEntityDestroyHandle.createHandle(packet.getHandle());
if (dp.hasMultipleEntityIds()) {
for (int entityId : dp.getEntityIds()) {
handleDespawn(entityId);
}
} else {
handleDespawn(dp.getSingleEntityId());
}
} else if (type == PacketType.OUT_RESPAWN) {
DimensionType dimension;
try {
dimension = packet.read(PacketType.OUT_RESPAWN.dimensionType);
} catch (IllegalArgumentException ex) {
// Logging.LOGGER_NETWORK.log(Level.WARNING, "Failed to decide dimension from respawn packet", ex);
dimension = null;
}
if (dimension != null && !dimension.equals(this._playerDimension)) {
this._playerDimension = dimension;
handleReset();
}
} else if (type == PacketType.OUT_CAMERA) {
// Called when vanilla/server/Bukkit starts or stops spectating an Entity
// We remember this choice for later
this._vanillaSpectatedEntity = packet.read(PacketType.OUT_CAMERA.entityId);
// If currently spectating something already, override
int len = this._spectatorStack.length;
if (len > 0) {
packet.write(PacketType.OUT_CAMERA.entityId, this._spectatorStack[len - 1]);
}
} else {
if (this.isPositionTracked()) {
// Also decode position
if (type == PacketType.OUT_ENTITY_SPAWN) {
PacketPlayOutSpawnEntityHandle handle = PacketPlayOutSpawnEntityHandle.createHandle(packet.getHandle());
handleSpawn(handle.getEntityId(), handle.getCommonEntityType(), new Vector(handle.getPosX(), handle.getPosY(), handle.getPosZ()));
} else if (type == PacketType.OUT_ENTITY_SPAWN_LIVING) {
PacketPlayOutSpawnEntityLivingHandle handle = PacketPlayOutSpawnEntityLivingHandle.createHandle(packet.getHandle());
handleSpawn(handle.getEntityId(), handle.getCommonEntityType(), new Vector(handle.getPosX(), handle.getPosY(), handle.getPosZ()));
} else if (type == PacketType.OUT_ENTITY_SPAWN_NAMED) {
PacketPlayOutNamedEntitySpawnHandle handle = PacketPlayOutNamedEntitySpawnHandle.createHandle(packet.getHandle());
handleSpawn(handle.getEntityId(), CommonEntityType.PLAYER, new Vector(handle.getPosX(), handle.getPosY(), handle.getPosZ()));
} else if (type == PacketType.OUT_ENTITY_TELEPORT) {
PacketPlayOutEntityTeleportHandle handle = PacketPlayOutEntityTeleportHandle.createHandle(packet.getHandle());
handleMove(handle.getEntityId(), (position) -> {
position.setX(handle.getPosX());
position.setY(handle.getPosY());
position.setZ(handle.getPosZ());
});
} else if (type == PacketType.OUT_ENTITY_MOVE || type == PacketType.OUT_ENTITY_MOVE_LOOK) {
PacketPlayOutEntityHandle handle = PacketPlayOutEntityHandle.createHandle(packet.getHandle());
handleMove(handle.getEntityId(), (position) -> {
position.setX(position.getX() + handle.getDeltaX());
position.setY(position.getY() + handle.getDeltaY());
position.setZ(position.getZ() + handle.getDeltaZ());
});
}
} else {
// No decoding/tracking of position
if (type == PacketType.OUT_ENTITY_SPAWN) {
PacketPlayOutSpawnEntityHandle handle = PacketPlayOutSpawnEntityHandle.createHandle(packet.getHandle());
handleSpawn(handle.getEntityId(), handle.getCommonEntityType(), null);
} else if (type == PacketType.OUT_ENTITY_SPAWN_LIVING) {
PacketPlayOutSpawnEntityLivingHandle handle = PacketPlayOutSpawnEntityLivingHandle.createHandle(packet.getHandle());
handleSpawn(handle.getEntityId(), handle.getCommonEntityType(), null);
} else if (type == PacketType.OUT_ENTITY_SPAWN_NAMED) {
PacketPlayOutNamedEntitySpawnHandle handle = PacketPlayOutNamedEntitySpawnHandle.createHandle(packet.getHandle());
handleSpawn(handle.getEntityId(), CommonEntityType.PLAYER, null);
}
}
}
});
}
use of com.bergerkiller.generated.net.minecraft.network.protocol.game.PacketPlayOutSpawnEntityLivingHandle in project BKCommonLib by bergerhealer.
the class MapPlayerInput method updateInputInterception.
private void updateInputInterception(boolean intercept) {
if (!intercept && _fakeMountShown) {
_fakeMountShown = false;
// Despawn the mount
PacketUtil.sendPacket(player, PacketType.OUT_ENTITY_DESTROY.newInstanceSingle(this._fakeMountId));
// Resend current player position to the player
Location loc = this.player.getLocation();
PacketPlayOutPositionHandle positionPacket = PacketPlayOutPositionHandle.createAbsolute(loc);
PacketUtil.sendPacket(player, positionPacket);
return;
}
if (intercept) {
// Get expected position of the mount
Vector pos = player.getLocation().toVector();
pos.setZ(pos.getZ() + 0.1);
pos.setY(pos.getY() + 0.002);
if (!_fakeMountShown) {
_fakeMountShown = true;
// Generate unique mount Id (we can re-use it)
if (this._fakeMountId == -1) {
this._fakeMountId = EntityUtil.getUniqueEntityId();
}
// Store initial position
this._fakeMountLastPos = pos;
// Spawn the mount
{
DataWatcher data = new DataWatcher();
data.set(EntityHandle.DATA_FLAGS, (byte) (EntityHandle.DATA_FLAG_INVISIBLE));
data.set(EntityLivingHandle.DATA_HEALTH, 10.0F);
PacketPlayOutSpawnEntityLivingHandle packet = PacketPlayOutSpawnEntityLivingHandle.createNew();
packet.setEntityId(this._fakeMountId);
packet.setEntityUUID(UUID.randomUUID());
packet.setEntityType(EntityType.CHICKEN);
packet.setPosX(pos.getX());
packet.setPosY(pos.getY());
packet.setPosZ(pos.getZ());
PacketUtil.sendEntityLivingSpawnPacket(player, packet, data);
// Send attribute for max health = 0 to hide the health bar
PacketUtil.sendPacket(player, PacketPlayOutUpdateAttributesHandle.createZeroMaxHealth(this._fakeMountId));
}
sendMountPacket();
}
// When player position changes, refresh mount position with a simple teleport packet
if (this._fakeMountId != -1 && !pos.equals(this._fakeMountLastPos)) {
this._fakeMountLastPos = pos;
PacketPlayOutEntityTeleportHandle tp_packet = PacketPlayOutEntityTeleportHandle.createNew(this._fakeMountId, pos.getX(), pos.getY(), pos.getZ(), 0.0f, 0.0f, false);
PacketUtil.sendPacket(player, tp_packet);
}
}
}
Aggregations