Search in sources :

Example 1 with CustomPayloadS2CPacket

use of net.minecraft.client.network.packet.CustomPayloadS2CPacket in project ImmersivePortalsMod by qouteall.

the class MyNetwork method createStcSpawnEntity.

// NOTE my packet is redirected but I cannot get the packet handler info here
public static CustomPayloadS2CPacket createStcSpawnEntity(Entity entity) {
    EntityType entityType = entity.getType();
    PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
    buf.writeString(EntityType.getId(entityType).toString());
    buf.writeInt(entity.getEntityId());
    buf.writeInt(entity.dimension.getRawId());
    CompoundTag tag = new CompoundTag();
    entity.toTag(tag);
    buf.writeCompoundTag(tag);
    return new CustomPayloadS2CPacket(id_stcSpawnEntity, buf);
}
Also used : EntityType(net.minecraft.entity.EntityType) CustomPayloadS2CPacket(net.minecraft.client.network.packet.CustomPayloadS2CPacket) PacketByteBuf(net.minecraft.util.PacketByteBuf) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 2 with CustomPayloadS2CPacket

use of net.minecraft.client.network.packet.CustomPayloadS2CPacket in project ImmersivePortalsMod by qouteall.

the class MyNetwork method createSpawnLoadingIndicator.

public static CustomPayloadS2CPacket createSpawnLoadingIndicator(DimensionType dimensionType, Vec3d pos) {
    PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
    buf.writeInt(dimensionType.getRawId());
    buf.writeDouble(pos.x);
    buf.writeDouble(pos.y);
    buf.writeDouble(pos.z);
    return new CustomPayloadS2CPacket(id_stcSpawnLoadingIndicator, buf);
}
Also used : CustomPayloadS2CPacket(net.minecraft.client.network.packet.CustomPayloadS2CPacket) PacketByteBuf(net.minecraft.util.PacketByteBuf)

Example 3 with CustomPayloadS2CPacket

use of net.minecraft.client.network.packet.CustomPayloadS2CPacket in project ImmersivePortalsMod by qouteall.

the class ServerTeleportationManager method sendPositionConfirmMessage.

private void sendPositionConfirmMessage(ServerPlayerEntity player) {
    CustomPayloadS2CPacket packet = MyNetwork.createStcDimensionConfirm(player.dimension, player.getPos());
    player.networkHandler.sendPacket(packet);
}
Also used : CustomPayloadS2CPacket(net.minecraft.client.network.packet.CustomPayloadS2CPacket)

Example 4 with CustomPayloadS2CPacket

use of net.minecraft.client.network.packet.CustomPayloadS2CPacket in project ImmersivePortalsMod by qouteall.

the class MyNetwork method createCustomPacketStc.

// you can input a lambda expression and it will be invoked remotely
// but java serialization is not stable
@Deprecated
public static CustomPayloadS2CPacket createCustomPacketStc(ICustomStcPacket serializable) {
    // it copies the data twice but as the packet is small it's of no problem
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    ObjectOutputStream stream = null;
    try {
        stream = new ObjectOutputStream(byteArrayOutputStream);
        stream.writeObject(serializable);
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
    ByteBuf buffer = Unpooled.buffer();
    buffer.writeBytes(byteArrayOutputStream.toByteArray());
    PacketByteBuf buf = new PacketByteBuf(buffer);
    return new CustomPayloadS2CPacket(id_stcCustom, buf);
}
Also used : CustomPayloadS2CPacket(net.minecraft.client.network.packet.CustomPayloadS2CPacket) PacketByteBuf(net.minecraft.util.PacketByteBuf) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) ByteBuf(io.netty.buffer.ByteBuf) PacketByteBuf(net.minecraft.util.PacketByteBuf)

Example 5 with CustomPayloadS2CPacket

use of net.minecraft.client.network.packet.CustomPayloadS2CPacket in project ImmersivePortalsMod by qouteall.

the class MyNetwork method createStcDimensionConfirm.

public static CustomPayloadS2CPacket createStcDimensionConfirm(DimensionType dimensionType, Vec3d pos) {
    PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
    buf.writeInt(dimensionType.getRawId());
    buf.writeDouble(pos.x);
    buf.writeDouble(pos.y);
    buf.writeDouble(pos.z);
    return new CustomPayloadS2CPacket(id_stcDimensionConfirm, buf);
}
Also used : CustomPayloadS2CPacket(net.minecraft.client.network.packet.CustomPayloadS2CPacket) PacketByteBuf(net.minecraft.util.PacketByteBuf)

Aggregations

CustomPayloadS2CPacket (net.minecraft.client.network.packet.CustomPayloadS2CPacket)10 PacketByteBuf (net.minecraft.util.PacketByteBuf)7 IOException (java.io.IOException)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 IntegerAABBInclusive (com.qouteall.immersive_portals.my_util.IntegerAABBInclusive)1 ByteBuf (io.netty.buffer.ByteBuf)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 ServerPlayerEntityAccessor (net.fabricmc.fabric.mixin.container.ServerPlayerEntityAccessor)1 Container (net.minecraft.container.Container)1 EntityType (net.minecraft.entity.EntityType)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1 Vec3d (net.minecraft.util.math.Vec3d)1