Jump to content

Recommended Posts

Posted

I am making a mod, based on the Mario pipes. basically the problem i am having, is that i have no idea how i can go about using a block to find other blocks to make a path to get from one side of these pipes to the other, i dont think i am explaining this quite right, so i will post a picture.

 

 

 

SPHRIWp.png

 

what i need, is to be able to locate the end pipes, and teleport the player from one to the other and back. if anyone can point me to a tutorial or give me a basic idea of how i would go about doing this, then let me know. thanks in advance!

Posted

As long as your pipes are one-in and one-out you can simply make "search".

Task is simple, can't think of a way to explain it - you just check where is next connected pipe until you reach end.

 

As to what can you do to make it work well:

1. If pipes are TileEntities you can store start/end/whatever in their NBT.

I belive above is not the case, so:

 

2. You are most likely (what I would do) holding pipes rotation in their metadata.

You can simplify your "search" based on this, meaning "where the pipe goes next".

1.7.10 is no longer supported by forge, you are on your own.

Posted

The simplest solution would probably be to use a recursive method. Assuming your blocks store their orientation (e.g. UP = next block is up), this would be trivial, but you'll need a wrapper for the coordinates to make it simpler (I'll use BlockPos from 1.8, but it's easy to make your own or use e.g. Vec3i):

/**
* Assume that you know the beginning block, and x/y/z are the coordinates of that block
* @return wrapped x/y/z coordinates of the final block
*/
public BlockPos findEnd(World world, int x, int y, int z, BlockPos last) {
    Block block = world.getBlock(x, y, z);
    if (block != this) { // important to have a condition to end the recursion 
        // return new BlockPos(x, y, z); // this is the position that the player should come out at
        return last; // this way you still have the orientation information
    }
    int facing = world.getBlockMetadata(x, y, z); // or ForgeDirection - use EnumFacing in 1.8
    switch (facing) { // I'm using names for the cases, but you'd probably be using 0, 1, etc. in 1.7.10
    case UP: return findEnd(world, x, y + 1, z, new BlockPos(x, y, z));
    case DOWN: return findEnd(world, x, y - 1, z, new BlockPos(x, y, z));
    // etc.
    }
}

Those may not be accurate method names - I'm just writing from memory - but that's the idea. Pretty straightforward, and you can even have side-by-side tubes and they won't get mixed up.

 

Then once you've found the ending position (which isn't actually one of your blocks), you need to figure out if it is suitable to teleport there (i.e. there are air blocks) and whether to move the player up or down one more block - this may be easiest if you return the last block position containing your block so that you can still have the orientation information.

Posted

alright, first thing, i managed to make the whole thing work, and i may have done it a difficult way, but basically i have 1 block, and the only thing that i change is the render of the pipes, i have a few tests to get the direction of each pipe, and i managed to write the locations of the end pipes to each other to set their location to teleport to.

 

if you would like i made the first alpha version of my mod, i could upload it to get some feed back and tips/pointers on how to make it better.

 

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.