net.minecraft.client.network.play.ClientPlayNetHandler Java Examples

The following examples show how to use net.minecraft.client.network.play.ClientPlayNetHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PacketCustomChannelBuilder.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public void onClientPayload(NetworkEvent.ServerCustomPayloadEvent event) {
    if (event instanceof NetworkEvent.ServerCustomPayloadLoginEvent) {
        return;
    }
    PacketCustom packet = new PacketCustom(event.getPayload());
    NetworkEvent.Context ctx = event.getSource().get();
    INetHandler netHandler = ctx.getNetworkManager().getNetHandler();
    ctx.setPacketHandled(true);
    if (netHandler instanceof ClientPlayNetHandler) {
        ClientPlayNetHandler nh = (ClientPlayNetHandler) netHandler;
        ctx.enqueueWork(() -> packetHandler.handlePacket(packet, Minecraft.getInstance(), nh));
    }
}
 
Example #2
Source File: ClientInterop.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
public static boolean interceptChatMessage(String message) {
    if (message.startsWith("/bbor:")) {
        ClientPlayNetHandler connection = Minecraft.getInstance().getConnection();
        if (connection != null) {
            CommandDispatcher<ISuggestionProvider> commandDispatcher = connection.func_195515_i();
            CommandSource commandSource = Minecraft.getInstance().player.getCommandSource();
            try {
                commandDispatcher.execute(message.substring(1), commandSource);
            } catch (CommandSyntaxException exception) {
                commandSource.sendErrorMessage(TextComponentUtils.toTextComponent(exception.getRawMessage()));
                if (exception.getInput() != null && exception.getCursor() >= 0) {
                    ITextComponent suggestion = new StringTextComponent("")
                            .applyTextStyle(TextFormatting.GRAY)
                            .applyTextStyle(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, message)));
                    int textLength = Math.min(exception.getInput().length(), exception.getCursor());
                    if (textLength > 10) {
                        suggestion.appendText("...");
                    }

                    suggestion.appendText(exception.getInput().substring(Math.max(0, textLength - 10), textLength));
                    if (textLength < exception.getInput().length()) {
                        suggestion.appendSibling(new StringTextComponent(exception.getInput().substring(textLength))
                                .applyTextStyles(TextFormatting.RED, TextFormatting.UNDERLINE));
                    }

                    suggestion.appendSibling(new TranslationTextComponent("command.context.here")
                            .applyTextStyles(TextFormatting.RED, TextFormatting.ITALIC));
                    commandSource.sendErrorMessage(suggestion);
                }
            }
        }
        return true;
    }
    return false;
}
 
Example #3
Source File: MixinSCustomPayloadPlayPacket.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
@Redirect(method = "processPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/play/IClientPlayNetHandler;handleCustomPayload(Lnet/minecraft/network/play/server/SCustomPayloadPlayPacket;)V"))
private void processPacket(IClientPlayNetHandler netHandlerPlayClient, SCustomPayloadPlayPacket packet) {
    String channelName = channel.toString();
    if (channelName.startsWith("bbor:")) {
        PacketBuffer data = null;
        try {
            data = packet.getBufferData();
            PayloadReader reader = new PayloadReader(data);
            switch (channelName) {
                case InitializeClient.NAME: {
                    EventBus.publish(InitializeClient.getEvent(reader));
                    ((ClientPlayNetHandler) netHandlerPlayClient).sendPacket(SubscribeToServer.getPayload().build());
                    break;
                }
                case AddBoundingBox.NAME:
                case AddBoundingBox.LEGACY: {
                    EventBus.publish(AddBoundingBox.getEvent(reader, channelName));
                    break;
                }
            }
        } finally {
            if (data != null)
                data.release();
        }
    } else {
        netHandlerPlayClient.handleCustomPayload(packet);
    }
}
 
Example #4
Source File: ForgeClientSparkPlugin.java    From spark with GNU General Public License v3.0 4 votes vote down vote up
private CommandDispatcher<ISuggestionProvider> getPlayerCommandDispatcher() {
    return Optional.ofNullable(this.minecraft.player)
            .map(player -> player.connection)
            .map(ClientPlayNetHandler::getCommandDispatcher)
            .orElse(null);
}
 
Example #5
Source File: MixinSCommandListPacket.java    From BoundingBoxOutlineReloaded with MIT License 4 votes vote down vote up
@Inject(method = "processPacket", at = @At("RETURN"))
private void processPacket(IClientPlayNetHandler netHandlerPlayClient, CallbackInfo ci) {
    TypeHelper.doIfType(netHandlerPlayClient, ClientPlayNetHandler.class, handler ->
            ClientInterop.registerClientCommands(handler.func_195515_i()));
}