Posted March 17, 20178 yr I'm not sure why my capability is getting an NPE on line 69 of https://hastebin.com/anadohisef.java https://hastebin.com/aviwugevav.java https://hastebin.com/imirexerap.java https://hastebin.com/gosumibeki.java
March 17, 20178 yr Capabilities only store the data Server side. You need to sync the data to the Client with packets. Also previously known as eAndPi. "Pi, is there a station coming up where we can board your train of thought?" -Kronnn Published Mods: Underworld Handy links: Vic_'s Forge events Own WIP Tutorials.
March 17, 20178 yr You shouldn't be using Minecraft.getMinecraft().player. The Minecraft class doesn't exist on the server so it will cause a crash. It also bears no relation to the event you're subscribing to - instead you should get the player from the event, event#player.
March 17, 20178 yr 34 minutes ago, Jay Avery said: You shouldn't be using Minecraft.getMinecraft().player. The Minecraft class doesn't exist on the server so it will cause a crash. It also bears no relation to the event you're subscribing to - instead you should get the player from the event, event#player. The relevant events here, are client-side, and hopefully called/registered in the ClientProxy. As such, Minecraft::thePlayer & event#player would reference the exact same object. Also previously known as eAndPi. "Pi, is there a station coming up where we can board your train of thought?" -Kronnn Published Mods: Underworld Handy links: Vic_'s Forge events Own WIP Tutorials.
March 17, 20178 yr 2 minutes ago, Matryoshika said: The relevant events here, are client-side, and hopefully called/registered in the ClientProxy. As such, Minecraft::thePlayer & event#player would reference the exact same object. PlayerTickEvent is fired for all players (even on the client side), not just the client player. If you want to do something every tick on the client, use ClientTickEvent. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
March 17, 20178 yr It does exist Client side, but it is never saved there. If the player logs out, or the server restarts, the client's data will reset. If you want to reliably do things Client-Side, you will need to send packets from Server->Client with the data. Also previously known as eAndPi. "Pi, is there a station coming up where we can board your train of thought?" -Kronnn Published Mods: Underworld Handy links: Vic_'s Forge events Own WIP Tutorials.
March 17, 20178 yr Author I'm still unsure as to why I'm getting a NPE from this though. The capability has a boolean 'isAiming' should be false when a new capability is created. So why is it null?
March 18, 20178 yr 1 hour ago, Allskill said: I'm still unsure as to why I'm getting a NPE from this though. The capability has a boolean 'isAiming' should be false when a new capability is created. So why is it null? It won't be the capability that's null, it's probably getMinecraft() or player. Step through with the debugger or use printlns if you want to find out for sure. But you don't really need to, because you don't need to be using that code at all - event#player won't be null. Edited March 18, 20178 yr by Jay Avery
March 18, 20178 yr Author Thanks jay, that solved my NPE on the player object. But I'm getting another on 'isAiming' which I don't understand as by default private boolean isAiming = false;
March 18, 20178 yr 8 minutes ago, Allskill said: Thanks jay, that solved my NPE on the player object. But I'm getting another on 'isAiming' which I don't understand as by default private boolean isAiming = false; Which line is the NPE on? It can't be the isAiming field that's null (a primitive type can't be null no matter what), but it might be the capability itself or something else. Are you attaching the capability to the player with AttachCapabilitiesEvent<Entity>?
March 18, 20178 yr Author My method 'isAiming' has an NPE when called. I attach my capabilities here https://hastebin.com/dakozuzeyo.cs in my common proxy. The isaiming method just returns that boolean above. And is called in the PlayerTickEvent ICraftZData data = event.player.getCapability(CraftZDataProvider.CRAFTZ_DATA_CAP, null); boolean canZoom = data.isAiming(); Edited March 18, 20178 yr by Allskill
March 18, 20178 yr 15 minutes ago, Allskill said: My method 'isAiming' has an NPE when called. I attach my capabilities here https://hastebin.com/dakozuzeyo.cs in my common proxy. The isaiming method just returns that boolean above. And is called in the PlayerTickEvent ICraftZData data = event.player.getCapability(CraftZDataProvider.CRAFTZ_DATA_CAP, null); boolean canZoom = data.isAiming(); If the isAiming() method causes an NPE, that means it's being called on a null object - so the capability must be null there. I'm not sure why that would be though. Try adding a check with hasCapability, so the method is only called if the capability is definitely present. Does the exception happen as soon as you start a world? Possibly the first player tick happens before capabilities are attached (I'm not sure), so it may just need to skip the first tick or few until the capability is present. If the capability is still null once the world is properly started, there must be some other issue with it. Edited March 18, 20178 yr by Jay Avery
March 18, 20178 yr Author The capability is null once the world is loaded. Do u know what could cause this? I register the capability with CapabilityManager.INSTANCE.register(ICraftZData.class, new CraftZDataStorage(), new CraftZData.Factory()); in my common proxy Edited March 18, 20178 yr by Allskill
March 18, 20178 yr I can't see any obvious reason for it. I'd probably start by throwing printlns all over the place in the capability construction and attachment, to see whether it's actually being made and attached in the first place. Edited March 18, 20178 yr by Jay Avery
March 18, 20178 yr Author 13 hours ago, diesieben07 said: Please show where you register CapabilityHandler to the event bus. https://hastebin.com/lovudodego.cpp
March 19, 20178 yr Author 3 hours ago, diesieben07 said: Please show CapabilityHander and your client proxy. https://hastebin.com/bidupelatu.java client proxy https://hastebin.com/ehexiyosam.java capabilityhandler
March 19, 20178 yr 6 hours ago, Allskill said: https://hastebin.com/bidupelatu.java client proxy https://hastebin.com/ehexiyosam.java capabilityhandler Your ClientProxy#init needs to call super, otherwise it doesn't do anything in the CommonProxy#init.
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.