Jump to content

Recommended Posts

Posted

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.

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

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

  • Like 1

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.

Posted

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.

  • Like 1

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.

Posted

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?

Posted (edited)
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 by Jay Avery
  • Like 1
Posted

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;
Posted
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>?

Posted (edited)

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 by Allskill
Posted (edited)
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 by Jay Avery
  • Like 1
Posted (edited)

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 by Allskill
Posted (edited)

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 by Jay Avery

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.