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

Why this gives me NullPointer?

 

TileEntity tile = world.getTileEntity(x, y, z);

 

I intend to check null the next line, but then it crashed at that line.

We cant help you if you dont show us anyhing. Just saiing. The chance that you get a NPE bc of forge isnt updated is really small.

  • Author

K, here are more info:

 

Problematic function:

 

("world" is set to "worldObj", to make life easier)

(MultipleControllerException is a self-made Exception class. But I cant test its functionality because this code fails... and the Exception appear later in the code (which is not shown))

 

private void checkBound() throws MultipleControllerException {

for (int i=0; i<6; i++) {

ForgeDirection dir = ForgeDirection.getOrientation(i);

int x = dir.offsetX + xCoord;

int y = dir.offsetY + yCoord;

int z = dir.offsetZ + zCoord;

TileEntity tile;

// DEBUG

if (world.isRemote) {

Minecraft.getMinecraft().thePlayer.sendChatMessage("X: " + x);

Minecraft.getMinecraft().thePlayer.sendChatMessage("Y: " + y);

Minecraft.getMinecraft().thePlayer.sendChatMessage("Z: " + z);

Minecraft.getMinecraft().thePlayer.sendChatMessage("World: " + world);

}

tile = world.getTileEntity(x, y, z);

}

 

What the game printed:

(What the game gave me:)

can't even print anything.

 

Conclusion:

somehow the "world" variable failed.

 

(BTW, nice Forge loading GUI!!!)

  • Author

WEIRD, now that it gave me some more info now:

 

[server thread/INFO]: <Player860> X: -225

[server thread/INFO]: <Player860> Y: 105

[server thread/INFO]: <Player860> Z: 237

[server thread/INFO]: <Player860> World: net.minecraft.client.multiplayer.WorldClient@59027d30

 

but still it crashed.

 

K, even more info:

 

public TEMCGController() {

this.world = this.worldObj;

}

 

It is getting more crazy.

So it may be just a program code-writing style issue...

 

No, that is not a "coding style" issue, it is a coding error: you are trying to assign something at a time when the assignment is either bad or at least unpredictable. That is a logical mistake and therefore wrong no matter what your coding style is.

 

Now it is understandable to make such a mistake -- when modding, the nuanced behavior of the Minecraft implementation is not always obvious.

 

It reminds me of someone who was trying to use the entity position in the constructor. Similarly, the position is not asssigned at that point, so using it would be wrong.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.