use of net.sistr.littlemaidmodelloader.network.util.CustomPacketEntity in project LittleMaidModelLoader-Fabric by SistrScarlet.
the class CustomMobSpawnPacket method spawn.
@Environment(EnvType.CLIENT)
private static void spawn(int id, UUID uuid, int entityTypeId, double x, double y, double z, float yaw, float pitch, float headYaw, float velocityX, float velocityY, float velocityZ, PacketByteBuf additional) {
MinecraftClient client = MinecraftClient.getInstance();
ClientWorld world = client.world;
if (world == null) {
return;
}
LivingEntity livingEntity = (LivingEntity) EntityType.createInstanceFromId(entityTypeId, world);
if (livingEntity instanceof CustomPacketEntity) {
livingEntity.updateTrackedPosition(x, y, z);
livingEntity.bodyYaw = headYaw;
livingEntity.headYaw = headYaw;
livingEntity.setEntityId(id);
livingEntity.setUuid(uuid);
livingEntity.updatePositionAndAngles(x, y, z, yaw, pitch);
livingEntity.setVelocity(velocityX, velocityY, velocityZ);
((CustomPacketEntity) livingEntity).readCustomPacket(additional);
world.addEntity(id, livingEntity);
} else {
LOGGER.warn("Skipping Entity with id {}", entityTypeId);
}
if (additional.refCnt() > 0) {
additional.release();
}
}
use of net.sistr.littlemaidmodelloader.network.util.CustomPacketEntity in project LittleMaidModelLoader-Architectury by SistrScarlet.
the class CustomMobSpawnPacket method createPacket.
public static Packet<?> createPacket(LivingEntity entity) {
if (!(entity instanceof CustomPacketEntity)) {
throw new IllegalStateException("CustomPacketEntityを実装していません。");
}
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeVarInt(entity.getEntityId());
buf.writeUuid(entity.getUuid());
buf.writeVarInt(Registry.ENTITY_TYPE.getRawId(entity.getType()));
buf.writeDouble(entity.getX());
buf.writeDouble(entity.getY());
buf.writeDouble(entity.getZ());
buf.writeByte((int) (entity.yaw * 256.0F / 360.0F));
buf.writeByte((int) (entity.pitch * 256.0F / 360.0F));
buf.writeByte((int) (entity.headYaw * 256.0F / 360.0F));
Vec3d vec3d = entity.getVelocity();
int velocityX = (int) (MathHelper.clamp(vec3d.x, -3.9D, 3.9D) * 8000D);
int velocityY = (int) (MathHelper.clamp(vec3d.y, -3.9D, 3.9D) * 8000D);
int velocityZ = (int) (MathHelper.clamp(vec3d.z, -3.9D, 3.9D) * 8000D);
buf.writeShort(velocityX);
buf.writeShort(velocityY);
buf.writeShort(velocityZ);
((CustomPacketEntity) entity).writeCustomPacket(buf);
return ServerPlayNetworking.createS2CPacket(ID, buf);
}
use of net.sistr.littlemaidmodelloader.network.util.CustomPacketEntity in project LittleMaidModelLoader-Architectury by SistrScarlet.
the class CustomMobSpawnPacket method spawn.
@Environment(EnvType.CLIENT)
private static void spawn(int id, UUID uuid, int entityTypeId, double x, double y, double z, float yaw, float pitch, float headYaw, float velocityX, float velocityY, float velocityZ, PacketByteBuf additional) {
MinecraftClient client = MinecraftClient.getInstance();
ClientWorld world = client.world;
if (world == null) {
return;
}
LivingEntity livingEntity = (LivingEntity) EntityType.createInstanceFromId(entityTypeId, world);
if (livingEntity instanceof CustomPacketEntity) {
livingEntity.updateTrackedPosition(x, y, z);
livingEntity.bodyYaw = headYaw;
livingEntity.headYaw = headYaw;
livingEntity.setEntityId(id);
livingEntity.setUuid(uuid);
livingEntity.updatePositionAndAngles(x, y, z, yaw, pitch);
livingEntity.setVelocity(velocityX, velocityY, velocityZ);
((CustomPacketEntity) livingEntity).readCustomPacket(additional);
world.addEntity(id, livingEntity);
} else {
LOGGER.warn("Skipping Entity with id {}", entityTypeId);
}
if (additional.refCnt() > 0) {
additional.release();
}
}
use of net.sistr.littlemaidmodelloader.network.util.CustomPacketEntity in project LittleMaidModelLoader-Fabric by SistrScarlet.
the class CustomMobSpawnPacket method createPacket.
public static Packet<?> createPacket(LivingEntity entity) {
if (!(entity instanceof CustomPacketEntity)) {
throw new IllegalStateException("CustomPacketEntityを実装していません。");
}
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeVarInt(entity.getEntityId());
buf.writeUuid(entity.getUuid());
buf.writeVarInt(Registry.ENTITY_TYPE.getRawId(entity.getType()));
buf.writeDouble(entity.getX());
buf.writeDouble(entity.getY());
buf.writeDouble(entity.getZ());
buf.writeByte((int) (entity.yaw * 256.0F / 360.0F));
buf.writeByte((int) (entity.pitch * 256.0F / 360.0F));
buf.writeByte((int) (entity.headYaw * 256.0F / 360.0F));
Vec3d vec3d = entity.getVelocity();
int velocityX = (int) (MathHelper.clamp(vec3d.x, -3.9D, 3.9D) * 8000D);
int velocityY = (int) (MathHelper.clamp(vec3d.y, -3.9D, 3.9D) * 8000D);
int velocityZ = (int) (MathHelper.clamp(vec3d.z, -3.9D, 3.9D) * 8000D);
buf.writeShort(velocityX);
buf.writeShort(velocityY);
buf.writeShort(velocityZ);
((CustomPacketEntity) entity).writeCustomPacket(buf);
return ServerPlayNetworking.createS2CPacket(ID, buf);
}
Aggregations