Posted April 23, 201411 yr 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)
April 23, 201411 yr 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 }
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.