Jump to content

[1.7.2][SOLVED] Searching for surrounding tile entitys


Shamboozle

Recommended Posts

Hi,

 

Can someone help me fix a problem I am having with my tile entity, I can't seem to find the neighbouring tile entitys from my block, so that I can render some pipes. Here is my code https://github.com/Shamboozle/FluidTransport if some one could look at it and point me i the right direction it would be greatly appreciated.

 

~Sham

(I'm sufficient in Java and Minecraft modding BTW)

Link to comment
Share on other sites

Example code to locate all direct neighbors of a tile-entity.  Lots of ways to do this, including just manually checking each x/y/z +/- set.  But I like loops, so this is a simple loop :)

 

After calling the method, cachedNeighbors will contain references to any nearby tile entities, or null if none.  Each index corresponds to a forge-direction (north, south, east, west, up, down..though not necessarily in that order).

 

TileEntity[] cachedNeighbors = new TileEntity[6];

public void updateNeighbors()
  {
  ForgeDirection d;
  int x, y, z;
  TileEntity te;
  for(int i = 0; i <6 ;i++)
    {
    d = ForgeDirection.values()[i];
    x = xCoord + d.offsetX;
    y = yCoord + d.offsetY;
    z = zCoord + d.offsetZ;
    te = worldObj.getTileEntity(x, y, z);
    cachedNeighbors[d.ordinal()]=te;
    }
  }

 

You can use the above without the caching as well...just put your operational code in instead of putting the te in the array.

 

To check a specific side, after the cache has been updated, you could query such as

 

if(cachedNeighbors[ForgeDirection.NORTH.ordinal]!=null)

{

//do something with the north-neighbor

}

Link to comment
Share on other sites

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.