Jump to content

Recommended Posts

Posted

I have declared proper variables in my tile entity

public int px = 0;
public int py = 0;
public int pz = 0;

And minecraft returns nullpointerexception on world.destroy

	public void onBlockDestroyedByPlayer(World world, int par2, int par3, int par4, int par5)
{
	TileEntityBlockZRail tle = (TileEntityBlockZRail)world.getBlockTileEntity(par2, par3, par4);
	world.destroyBlock((int)tle.px, par3, par4, true);
}

What's wrong with that?

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Posted
  On 4/29/2013 at 11:20 AM, endershadow said:

I think the first parameter is the x coord

Don't you say! And i so idiot, that i accidentaly put it there with no point!

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Posted
  On 4/29/2013 at 11:54 AM, Senitiel said:

Either world or tle is null.

First, do an:

if(tle!=null)
{
world.destroyBlock((int)tle.px, par3, par4, true);
}

If it still shrieks about null, then world is null, which probably would mean You're calling onBlockDestroyedByPlayer some weird way.

Okay, now it doesn't crash, but it doesn't work as i want either. The thing is — i'm placing a couple of blocks at once and i want them to be broken once too, so i...

public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving, ItemStack par6ItemStack)
{
   int[][] bl = {{0,1,240},{0,2,224},{0,3,208},{0,4,192},{0,5,176},{0,6,160},
   {-1,1,241},{-1,2,225},{-1,3,209},{-1,4,193},{-1,5,177},{-1,6,161},{-1,7,145},{-1,8,129},
   {-2,2,226},{-2,3,210},{-2,4,194},{-2,5,178},{-2,6,162},{-2,7,146},{-2,8,130},{-2,9,114},
   {-3,6,163},{-3,7,147},{-3,8,131},{-3,9,115},{-3,10,99},{-3,11,83},
   {-4,8,132},{-4,9,116},{-4,10,100},{-4,11,84},{-4,12,68},
   {-5,9,117},{-5,10,101},{-5,11,85},{-5,12,69},{-5,13,53}};
   int dir = MathHelper.floor_double((double)((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
   world.setBlockMetadataWithNotify(i, j, k, dir, 0);
   for (int l = 0; l < bl.length; l++){
      int[] c = rotxybydir(bl[l][0], bl[l][1], dir);
      world.setBlock(i + c[0], j, k + c[1], RoW.Rails.blockID, dir, 0);
      TileEntityBlockZRail tl = (TileEntityBlockZRail) world.getBlockTileEntity(i + c[0], j, k + c[1]);
      tl.mid = bl[l][2];
      tl.px = i;
      tl.pz = j;
      tl.py = k;
   };
}

It places them rather well, but i want to brake them all too...

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Posted

You need to make a for loop. Also I would store all positions in a 2D array in all of your TileEntities.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

  Quote

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted
  On 4/30/2013 at 2:50 PM, SanAndreasP said:

You need to make a for loop. Also I would store all positions in a 2D array in all of your TileEntities.

Where exactly?

As i remember, nbttagcompaund doesn't save arrays...

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Posted
  On 4/30/2013 at 2:56 PM, Naitenne said:

  Quote

You need to make a for loop. Also I would store all positions in a 2D array in all of your TileEntities.

Where exactly?

As i remember, nbttagcompaund doesn't save arrays...

 

A for loop on your block break method.

An (integer) array can be saved in the NBT just fine (i think it's called set-/getIntArray()), else you can also use NBTList for storing arrays... look at the TileEntityChest NBT methods on how to use them.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

  Quote

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

Uh. I mean, i don't understand the point i should make loop for...

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Posted
  On 4/30/2013 at 8:47 PM, Naitenne said:

Uh. I mean, i don't understand the point i should make loop for...

 

You're trying to destroy multiple blocks, so you need to call the destroyBlock method for each block you're trying to destroy.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

  Quote

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

No i don't. I will destroy main block, it will update nearby blocks, they will check if main block exists, destroy themselves, update nearby and so on. But i'm getting error on world.destroyBlock((int)tle.px, par3, par4, true); line...

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Posted
  On 5/1/2013 at 2:39 AM, Naitenne said:

No i don't. I will destroy main block, it will update nearby blocks, they will check if main block exists, destroy themselves, update nearby and so on. But i'm getting error on world.destroyBlock((int)tle.px, par3, par4, true); line...

 

Ah, now I see... what error do you get exactly?

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

  Quote

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

 

  Reveal hidden contents

 

This comes when i try to get tl.px...

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Posted
  On 5/2/2013 at 11:42 AM, Naitenne said:

 

  Reveal hidden contents

 

This comes when i try to get tl.px...

 

Seems like your TileEntity is null. Mostly it's caused because the block doesn't set one. Can I see the whole block code of yours? Use pastebin.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

  Quote

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

http://pastebin.com/aBhB7ikB

---

Yeah, when i try

public void onBlockDestroyedByPlayer(World world, int i, int j, int k, int par5)
{
   TileEntityBlockZRail tl = (TileEntityBlockZRail) world.getBlockTileEntity(i, j, k);
   System.out.println(tl);
}

It return null, and for some reason it does that four times. And game does not crash. However, i have tileentityrender class and it reads that data fine without any obvious reason... I think it's something with coordinates...

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Posted

Hell yeah. That code saved me.

public void breakBlock(World world, int i, int j, int k, int par5, int par6)
{
TileEntityBlockZRail tl = (TileEntityBlockZRail) world.getBlockTileEntity(i, j, k);
if (tl != null)
{
  world.destroyBlock(tl.px, j, tl.py, false);
}
}

public void onNeighborBlockChange(World world, int i, int j, int k, int par5)
{
TileEntityBlockZRail tl = (TileEntityBlockZRail) world.getBlockTileEntity(i, j, k);
if (tl != null)
{
  if(world.getBlockId(tl.px, j, tl.py) != RoW.Rails.blockID)
  {
   world.destroyBlock(i, j, k, false);
  }
}
}

Now, the only thing i need is my locomotive physics...

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

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.