Staircase 3D Function

Discussion in 'Spigot Plugin Development' started by Raydond123, May 11, 2015.

  1. Hello there! Before I start, I'd like to say that I'm relatively knew to plotting and graphing, especially in 3 dimensions.

    So, I was poking around the internet and I came upon this site here. The function that I'm interested in is the stairs 3D function. In case you're too lazy to look for it, here it is: (sin(-.65-x)+sin(-.35-x)+sin(-.05-x)+sin(.25-x)+sin(.55-x))/7. I have no idea where to start on re-creating this inside of Minecraft. If I could be able to recreate this, I should be able to mess around with the numbers and get the stair to be steeper, point in a different direction, and etc. As said before though, I simply don't know where to start with this. I've never really dealt with a 3D function before.

    Thanks in advance,
    Raymond
     
  2. In minecraft its actually a bit different then a function like that. We just work with a 2d line. This line is a 2d side view of the staircase. The slope of this line tells us how to place the blocks. If our line is y = x then we have the basic 1 block over 1 block up.
    If our line is y = x/2 then we have a 2 over 1 up. No matter what we need to round to whole numbers because we cant place anything on x.5 or x.75 etc. This means that y = 2x/3 is going to produce a pattern 1 over 1 up, 2 over 1 up, 1 over 1 up... you get the idea, its no longer straight. You can look at the worldedit source if you are really interested in 3d plotting but if its not the main feature just work with this over and up way of thinking.
     
  3. I've looked around the WorldEdit source but I've found no help. I've looked inside the EffectLib by Slikey and went into the HillEffect class. I honestly have no idea how it's creating the hill.
     
    • Informative Informative x 1
  4. That's a really interesting site you found right there. Thanks a lot for sharing.
     
    • Like Like x 1
  5. That's way more complex math than is required to build stairs, if that's your intent. I think what MrBlobman was suggesting was to greatly simplify what you're trying to do.

    For instance, a simple psuedocode example of a straight line of stairs might be like

    Code (Text):
    while (!done) {
       location.setBlock(Material.STONE);
       location.setX(location.getX() + 1);
       location.setBlock(Material.STONE);
       location.setY(location.getY() + 1);
    }
     
    That will make a diagonal line going up and forward in X. To really make stairs, you'd want to set to Material.STAIRS of some kind, but then you have to worry about getting the data value right so the stairs face the correct direction.

    In any case, you don't need any complex trig or anything to do this. The HillEffect works with particles and floating-point positions to create a smooth curve- not something you're going to be able to do with blocks excepting on a very, very large scale.
     
  6. Well actually... I just thought of another way of doing it...
    What if I just got the players line of sight, then for every single block within the line of sight, I would create a cylinder. It actually worked out pretty nicely.
    I made it so it also removes itself after a configurable amount of time.
    Here it is:

    PHP:
     int counter = 0;
                        int counter2 = 0;

                        for(Block block : player.getLineOfSight(null, 21)) {

                            if(counter == 0) {

                                final ArrayList<Location> blocks = generateFilledCylinder(block.getLocation(), 3, 1);

                                Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

                                    @Override
                                    public void run() {

                                        for(final Location loc : blocks) {

                                            if(loc.getBlock().getType() == Material.AIR) {

                                                loc.getWorld().playEffect(loc, Effect.STEP_SOUND, 174);
                                                loc.getBlock().setType(Material.PACKED_ICE);
                                                Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

                                                    @Override
                                                    public void run() {

                                                        loc.getBlock().setType(Material.AIR);
                                                        loc.getWorld().playEffect(loc, Effect.STEP_SOUND, 174);

                                                    }

                                                }, 20L * plugin.getConfig().getInt("icepath-remove-delay"));

                                            }

                                        }

                                    }

                                }, 10L * counter2);

                                counter2++;

                                counter++;

                            } else if(counter == 1) {

                                counter = 0;

                            }

                        }