Search in sources :

Example 1 with CustomPacketEntity

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();
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) MinecraftClient(net.minecraft.client.MinecraftClient) ClientWorld(net.minecraft.client.world.ClientWorld) CustomPacketEntity(net.sistr.littlemaidmodelloader.network.util.CustomPacketEntity) Environment(net.fabricmc.api.Environment)

Example 2 with CustomPacketEntity

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);
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf) CustomPacketEntity(net.sistr.littlemaidmodelloader.network.util.CustomPacketEntity) Vec3d(net.minecraft.util.math.Vec3d)

Example 3 with CustomPacketEntity

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();
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) MinecraftClient(net.minecraft.client.MinecraftClient) ClientWorld(net.minecraft.client.world.ClientWorld) CustomPacketEntity(net.sistr.littlemaidmodelloader.network.util.CustomPacketEntity) Environment(net.fabricmc.api.Environment)

Example 4 with CustomPacketEntity

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);
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf) CustomPacketEntity(net.sistr.littlemaidmodelloader.network.util.CustomPacketEntity) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

CustomPacketEntity (net.sistr.littlemaidmodelloader.network.util.CustomPacketEntity)4 Environment (net.fabricmc.api.Environment)2 MinecraftClient (net.minecraft.client.MinecraftClient)2 ClientWorld (net.minecraft.client.world.ClientWorld)2 LivingEntity (net.minecraft.entity.LivingEntity)2 PacketByteBuf (net.minecraft.network.PacketByteBuf)2 Vec3d (net.minecraft.util.math.Vec3d)2