Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

This code is not working anything i did wrong?


Recommended Posts

1 minute ago, Saksham4106 said:

that's way too less info... where are you writing this if statement?

 

@SubscribeEvent
public void OnRightClick(PlayerInteractEvent.RightClickItem RightClick) {
    LivingEntity player = RightClick.getEntityLiving();
    if (player.getHeldItemMainhand().getItem() == RegistryHandler.BACKPACK.get()) {
        player.setHealth(0);
    }
}
Link to post
Share on other sites
3 minutes ago, Saksham4106 said:

   @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
        playerIn.setHealth(0);
        return super.onItemRightClick(worldIn, playerIn, handIn);
    }

 

gave me a bunch of errors

Link to post
Share on other sites

1. That method triggers on both the client and the server side. You will need to check the side with World#isRemote.

2. Your overriding method does not have the correct signatures (please learn Java before attempting to write a mod).

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to post
Share on other sites
11 hours ago, DavidM said:

1. That method triggers on both the client and the server side. You will need to check the side with World#isRemote.

2. Your overriding method does not have the correct signatures (please learn Java before attempting to write a mod).

I jsut wanna know why its broken

Link to post
Share on other sites
3 hours ago, Turnrp said:

I jsut wanna know why its broken

Learning java is the best way of knowing why your code is broken

Learn Java

 

"keep in mind that this is not a Java school. You are expected to have basic knowledge of Java before posting here." - this is literally right below the forum title

Link to post
Share on other sites
9 hours ago, Turnrp said:

I jsut wanna know why its broken

I just told you.

20 hours ago, DavidM said:

Your overriding method does not have the correct signatures

and

20 hours ago, DavidM said:

That method triggers on both the client and the server side. You will need to check the side with World#isRemote.

 

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
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.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • I fixed the problem! It was just a simple mod that I added that was 1.12 and not 1.16 lol, I removed it and now its working like a charm. Thanks for the help btw!
    • 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:   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?
    • I just realized you are using a non-supported version of Forge based on the parameters of the render method as they are pre-1.15. The only versions supported are those in the blue banner at the top of the screen. Please update to one of the above versions to receive more support.
    • Should be able to search for class names or find a type hierarchy for MonsterEntity. I don't use IntelliJ so I'm not familiar with the keybinds.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.