Jump to content

NetworkDispatcher exception io.netty.handler.codec.EncoderException: java.lang.NullPointerException


Recommended Posts

Posted

I need to trigger a player's attack action.
I copied the net.minecraft.client.Minecraft.clickMouse() method from the sources and changed it a bit, removing everything about the leftClickCounter private property:
image.thumb.png.3322c502d24a9ed4955af426f4d55355.png 

public static void callAttackAction() {
        Minecraft instance = Minecraft.getMinecraft();
        if (!instance.player.isRowingBoat())
        {
            switch (instance.objectMouseOver.typeOfHit)
            {
                case ENTITY:
                    if (instance.objectMouseOver.entityHit != null && instance.playerController != null) {
                        try {
                            instance.playerController.attackEntity(instance.player, instance.objectMouseOver.entityHit);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                    break;
                case BLOCK:
                    BlockPos blockpos = instance.objectMouseOver.getBlockPos();

                    if (!instance.world.isAirBlock(blockpos))
                    {
                        instance.playerController.clickBlock(blockpos, instance.objectMouseOver.sideHit);
                        break;
                    }

                case MISS:
                    instance.player.resetCooldown();
                    net.minecraftforge.common.ForgeHooks.onEmptyLeftClick(instance.player);
            }

            instance.player.swingArm(EnumHand.MAIN_HAND);
        }
    }

It works, but sometimes times this error occurs on line 168 in the attackEntity method:
[Netty Client IO #1/ERROR] [FML]: NetworkDispatcher exception
io.netty.handler.codec.EncoderException: java.lang.NullPointerException
at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:125) ~[MessageToByteEncoder.class:4.1.9.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:730) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:816) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:723) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.write(NetworkDispatcher.java:548) ~[NetworkDispatcher.class:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:801) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:814) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:794) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:831) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1032) ~[DefaultChannelPipeline.class:4.1.9.Final]
at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:296) ~[AbstractChannel.class:4.1.9.Final]
at net.minecraft.network.NetworkManager$4.run(NetworkManager.java:245) [NetworkManager$4.class:?]
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) [AbstractEventExecutor.class:4.1.9.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403) [SingleThreadEventExecutor.class:4.1.9.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:442) [NioEventLoop.class:4.1.9.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) [SingleThreadEventExecutor$5.class:4.1.9.Final]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_281]
Caused by: java.lang.NullPointerException
at net.minecraft.network.play.client.CPacketPlayerDigging.writePacketData(CPacketPlayerDigging.java:41) ~[CPacketPlayerDigging.class:?]
at net.minecraft.network.NettyPacketEncoder.encode(NettyPacketEncoder.java:51) ~[NettyPacketEncoder.class:?]
at net.minecraft.network.NettyPacketEncoder.encode(NettyPacketEncoder.java:12) ~[NettyPacketEncoder.class:?]
at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107) ~[MessageToByteEncoder.class:4.1.9.Final]

How can I fix it?

Posted

Why do you need to trigger the attack action?

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

  Reveal hidden contents

 

Posted
  On 5/17/2021 at 4:54 AM, DaemonUmbra said:

Why do you need to trigger the attack action?

Expand  

I am creating a modification for one RPG server, which should, when holding down a certain key, continuously force the player to attack, like he would press the left mouse button many times. This is not a cheat! Clickers are allowed on this server. Only I want to trigger the attack itself, and not a click of the left mouse button. Sorry for my English.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

  Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

  Your link has been automatically embedded.   Display as a link instead

  Your previous content has been restored.   Clear editor

  You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Create New...

Important Information

By using this site, you agree to our Terms of Use.