Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I'm getting a null error when I try to get the player's custom capability, I dont know why.... I must have missed something but I dont know where.... if someone could tell where's the problem i would be grateful.

 

Quote

java.lang.NullPointerException: null
    at com.xanderindalzone.customgunsmod.events.client.ClientKeyEvents.AimGun(ClientKeyEvents.java:92) ~[main/:?] {re:classloading}
    at net.minecraftforge.eventbus.ASMEventHandler_8_ClientKeyEvents_AimGun_ClientTickEvent.invoke(.dynamic) ~[?:?] {}
    at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:80) ~[eventbus-2.2.0-service.jar:?] {}
    at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258) ~[eventbus-2.2.0-service.jar:?] {}
    at net.minecraftforge.fml.hooks.BasicEventHooks.onPreClientTick(BasicEventHooks.java:104) ~[forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-recomp.jar:?] {re:classloading}
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:1387) ~[forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:941) ~[forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.run(Minecraft.java:558) ~[forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.main.Main.main(Main.java:177) ~[forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_251] {}
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_251] {}
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_251] {}
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_251] {}
    at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55) ~[forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-recomp.jar:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-5.1.0.jar:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-5.1.0.jar:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-5.1.0.jar:?] {}
    at cpw.mods.modlauncher.Launcher.run(Launcher.java:81) [modlauncher-5.1.0.jar:?] {}
    at cpw.mods.modlauncher.Launcher.main(Launcher.java:65) [modlauncher-5.1.0.jar:?] {}
    at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:102) [forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-recomp.jar:?] {}

 

Event Handler where I call the capability

Quote

 

Do something like this for AimGun:

Change event to TickEvent.PlayerTickEvent

Use event.player to get player

and get capability like this:

@SubscribeEvent
public static void tick(TickEvent.PlayerTickEvent event) {
   [YourIinterface] data = event.player.getCapability(ProviderGunActions.GUN_ACTIONS_CAP).orElseThrow(IllegalStateException::new);
    
}

That's not the problem. That's just a different way to access a capability and ifPresent is perfectly acceptable (and indeed, preferred).

 

I suspect the issue is that ClientTickEvent runs in the main menu before there is a world. Before there is a player and there is no null-check on line 92:

 

Minecraft.getInstance().player.[...]

 

player, there, may be null!

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

Now I'm getting this null exception when I join the world :V (CODE UPDATED on Github)

Quote

java.lang.NullPointerException
    at com.xanderindalzone.customgunsmod.capabilities.providers.ProviderGunActions.<init>(ProviderGunActions.java:19)
    at com.xanderindalzone.customgunsmod.events.GunCapabilityHandler.attachCapability(GunCapabilityHandler.java:71)
    at net.minecraftforge.eventbus.ASMEventHandler_10_GunCapabilityHandler_attachCapability_AttachCapabilitiesEvent.invoke(.dynamic)
    at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:80)
    at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258)
    at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:564)
    at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:558)
    at net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:48)
    at net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:44)
    at net.minecraft.entity.Entity.<init>(Entity.java:224)
    at net.minecraft.entity.LivingEntity.<init>(LivingEntity.java:200)
    at net.minecraft.entity.player.PlayerEntity.<init>(PlayerEntity.java:164)
    at net.minecraft.entity.player.ServerPlayerEntity.<init>(ServerPlayerEntity.java:161)
    at net.minecraft.server.management.PlayerList.createPlayerForUser(PlayerList.java:395)
    at net.minecraft.network.login.ServerLoginNetHandler.tryAcceptPlayer(ServerLoginNetHandler.java:120)
    at net.minecraft.network.login.ServerLoginNetHandler.tick(ServerLoginNetHandler.java:64)
    at net.minecraft.network.NetworkManager.tick(NetworkManager.java:246)
    at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:152)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:903)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:821)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:662)
    at java.lang.Thread.run(Unknown Source)
 

 

 

Isnt this the way it has to be implemented?

Quote

    @CapabilityInject(IGunActions.class)
    public static final Capability<IGunActions> GUN_ACTIONS_CAP = null;

    private LazyOptional<IGunActions> instance = LazyOptional.of(GUN_ACTIONS_CAP::getDefaultInstance);

 

PD: I think I got this line from another post.

  • Author
29 minutes ago, diesieben07 said:

This method is never called (you don't register it as an event handler) and thus your capability is never registered. Therefor your @CapabilityInject field stays null.

Oh yeah, I'm dumb, I copypasted the code and forgot to change the method name in the parameter :P, thx XD

I sometimes change code too fast that I dont realize of these silly mistakes XD

Its now joining the world without crashes :) thx

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.