Search in sources :

Example 6 with PacketByteBuf

use of net.minecraft.util.PacketByteBuf in project ImmersivePortalsMod by qouteall.

the class MyNetworkClient method processRedirectedMessage.

public static void processRedirectedMessage(PacketContext context, PacketByteBuf buf) {
    int dimensionId = buf.readInt();
    int messageType = buf.readInt();
    DimensionType dimension = DimensionType.byRawId(dimensionId);
    Packet packet = MyNetwork.createEmptyPacketByType(messageType);
    try {
        packet.read(buf);
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
    if (dimension == null) {
        Helper.err(String.format("Invalid redirected packet %s %s \nRegistered dimensions %s", dimensionId, packet, Registry.DIMENSION.stream().map(dim -> dim.toString() + " " + dim.getRawId()).collect(Collectors.joining("\n"))));
        return;
    }
    processRedirectedPacket(dimension, packet);
}
Also used : EntityType(net.minecraft.entity.EntityType) GlobalPortalStorage(com.qouteall.immersive_portals.portal.global_portals.GlobalPortalStorage) CustomPayloadC2SPacket(net.minecraft.server.network.packet.CustomPayloadC2SPacket) Environment(net.fabricmc.api.Environment) ObjectInputStream(java.io.ObjectInputStream) ByteBuffer(java.nio.ByteBuffer) Unpooled(io.netty.buffer.Unpooled) GlobalTrackedPortal(com.qouteall.immersive_portals.portal.global_portals.GlobalTrackedPortal) Vec3d(net.minecraft.util.math.Vec3d) ByteArrayInputStream(java.io.ByteArrayInputStream) EnvType(net.fabricmc.api.EnvType) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler) PacketContext(net.fabricmc.fabric.api.network.PacketContext) Entity(net.minecraft.entity.Entity) Packet(net.minecraft.network.Packet) IEClientPlayNetworkHandler(com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler) MyClientChunkManager(com.qouteall.immersive_portals.chunk_loading.MyClientChunkManager) ICustomStcPacket(com.qouteall.immersive_portals.my_util.ICustomStcPacket) IOException(java.io.IOException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Registry(net.minecraft.util.registry.Registry) ClientSidePacketRegistry(net.fabricmc.fabric.api.network.ClientSidePacketRegistry) List(java.util.List) IEClientWorld(com.qouteall.immersive_portals.ducks.IEClientWorld) CompoundTag(net.minecraft.nbt.CompoundTag) DimensionType(net.minecraft.world.dimension.DimensionType) LoadingIndicatorEntity(com.qouteall.immersive_portals.portal.LoadingIndicatorEntity) Optional(java.util.Optional) MinecraftClient(net.minecraft.client.MinecraftClient) PacketByteBuf(net.minecraft.util.PacketByteBuf) ClientWorld(net.minecraft.client.world.ClientWorld) DimensionType(net.minecraft.world.dimension.DimensionType) CustomPayloadC2SPacket(net.minecraft.server.network.packet.CustomPayloadC2SPacket) Packet(net.minecraft.network.Packet) ICustomStcPacket(com.qouteall.immersive_portals.my_util.ICustomStcPacket) IOException(java.io.IOException)

Example 7 with PacketByteBuf

use of net.minecraft.util.PacketByteBuf 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 8 with PacketByteBuf

use of net.minecraft.util.PacketByteBuf 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 9 with PacketByteBuf

use of net.minecraft.util.PacketByteBuf in project tweed-api by Siphalor.

the class TweedClothBridge method open.

public Screen open() {
    inGame = MinecraftClient.getInstance().world != null;
    parentScreen = MinecraftClient.getInstance().currentScreen;
    if (inGame) {
        boolean requiresSync = false;
        for (ConfigFileEntry entry : configFiles) {
            if (entry.configFile.getRootCategory().entryStream().anyMatch(configEntry -> configEntry.getValue().getEnvironment() != ConfigEnvironment.CLIENT)) {
                requiresSync = true;
                break;
            }
        }
        if (!requiresSync) {
            return buildScreen();
        }
        for (ConfigFileEntry entry : configFiles) {
            PacketByteBuf buffer = new PacketByteBuf(Unpooled.buffer());
            buffer.writeString(entry.configFile.getName());
            buffer.writeEnumConstant(ConfigEnvironment.UNIVERSAL);
            buffer.writeEnumConstant(ConfigScope.SMALLEST);
            buffer.writeEnumConstant(ConfigOrigin.MAIN);
            ClientSidePacketRegistry.INSTANCE.sendToServer(Tweed.REQUEST_SYNC_C2S_PACKET, buffer);
            entry.awaitSync = true;
        }
        ClientCore.scheduledClothBridge = this;
        return new NoticeScreen(() -> {
            MinecraftClient.getInstance().openScreen(parentScreen);
            ClientCore.scheduledClothBridge = null;
        }, new TranslatableText("tweed.gui.screen.syncFromServer"), new TranslatableText("tweed.gui.screen.syncFromServer.note"));
    } else {
        return buildScreen();
    }
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) NoticeScreen(net.minecraft.client.gui.screen.NoticeScreen) PacketByteBuf(net.minecraft.util.PacketByteBuf)

Example 10 with PacketByteBuf

use of net.minecraft.util.PacketByteBuf in project tweed-api by Siphalor.

the class MixinClientPlayNetworkHandler method onGameJoined.

@Inject(method = "onGameJoin", at = @At("RETURN"), require = 0)
public void onGameJoined(GameJoinS2CPacket packet, CallbackInfo callbackInfo) {
    for (ConfigFile configFile : TweedRegistry.getConfigFiles()) {
        Tweed.LOGGER.info("Requested config sync for " + configFile.getName());
        PacketByteBuf packetByteBuf = new PacketByteBuf(Unpooled.buffer());
        packetByteBuf.writeString(configFile.getName());
        packetByteBuf.writeEnumConstant(ConfigEnvironment.SYNCED);
        packetByteBuf.writeEnumConstant(ConfigScope.WORLD);
        packetByteBuf.writeEnumConstant(ConfigOrigin.DATAPACK);
        ClientSidePacketRegistry.INSTANCE.sendToServer(Tweed.REQUEST_SYNC_C2S_PACKET, packetByteBuf);
    }
}
Also used : PacketByteBuf(net.minecraft.util.PacketByteBuf) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

PacketByteBuf (net.minecraft.util.PacketByteBuf)25 CustomPayloadS2CPacket (net.minecraft.client.network.packet.CustomPayloadS2CPacket)7 IOException (java.io.IOException)4 CompoundTag (net.minecraft.nbt.CompoundTag)4 Inject (org.spongepowered.asm.mixin.injection.Inject)4 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)3 Identifier (net.minecraft.util.Identifier)3 IServerPlayerEntity (de.siphalor.nbtcrafting.util.duck.IServerPlayerEntity)2 Unpooled (io.netty.buffer.Unpooled)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 EntityType (net.minecraft.entity.EntityType)2 Registry (net.minecraft.util.registry.Registry)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1 LoadingCache (com.google.common.cache.LoadingCache)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Pair (com.mojang.datafixers.util.Pair)1 MyClientChunkManager (com.qouteall.immersive_portals.chunk_loading.MyClientChunkManager)1 IEClientPlayNetworkHandler (com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler)1