How to generate custom structures

Discussion in 'Plugin Development' started by SpectrumCrafter, Oct 26, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    SpectrumCrafter

    Ok so I have looked all over the place for a good tutorial on how to generate structures.

    What I mean is that I want to be able to make a schematic and if the player stacks blocks in a certain way, it will generate it. Similar to the TARDIS plugin (http://dev.bukkit.org/bukkit-plugins/tardis/)

    See in that plugin you can stack diamond, lapis, then a torch and it will create a tardis. So could someone PLEASE help me with how to create this. Thanks!
     
  2. Offline

    The_Doctor_123

    Here's an example of his farm schematic layout:
    Code:
    35:8,35:8,35:8,35:8,35:8,35:8,35:8,35:8,35:8,35:8,35:8,35:8,35:8
    35:8,2:0,2:0,2:0,2:0,2:0,35:8,2:0,2:0,2:0,2:0,2:0,35:8
    35:8,2:0,2:0,2:0,2:0,2:0,35:8,2:0,2:0,2:0,2:0,2:0,35:8
    35:8,2:0,2:0,2:0,2:0,2:0,35:8,2:0,2:0,2:0,2:0,2:0,35:8
    35:8,2:0,2:0,2:0,2:0,2:0,35:8,2:0,2:0,2:0,2:0,2:0,35:8
    35:8,2:0,2:0,2:0,2:0,2:0,35:8,2:0,2:0,2:0,2:0,2:0,35:8
    35:8,35:8,35:8,35:8,35:8,35:8,52:0,35:8,35:8,35:8,35:8,35:8,35:8
    35:8,2:0,2:0,2:0,2:0,2:0,35:8,2:0,2:0,2:0,2:0,2:0,35:8
    35:8,2:0,2:0,2:0,2:0,2:0,35:8,2:0,2:0,2:0,2:0,2:0,35:8
    35:8,2:0,2:0,2:0,2:0,2:0,35:8,2:0,2:0,2:0,2:0,2:0,35:8
    35:8,2:0,2:0,2:0,2:0,2:0,35:8,2:0,2:0,2:0,2:0,2:0,35:8
    35:8,2:0,2:0,2:0,2:0,2:0,35:8,2:0,2:0,2:0,2:0,2:0,35:8
    35:8,35:8,35:8,35:8,35:8,35:8,35:8,35:8,35:8,35:8,35:8,35:8,35:8
    69:13,124:0,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,124:0,69:14
    124:0,0:0,0:0,37:0,0:0,85:0,0:0,85:0,0:0,31:1,31:1,0:0,124:0
    35:1,0:0,31:1,31:1,31:1,85:0,0:0,85:0,31:1,31:1,31:1,31:1,35:1
    35:1,37:0,31:1,31:1,31:1,107:1,0:0,107:3,31:1,31:1,31:1,38:0,35:1
    35:1,37:0,31:1,31:1,31:1,85:0,0:0,85:0,0:0,31:1,37:0,0:0,35:1
    35:1,85:0,85:0,107:2,85:0,85:0,0:0,85:0,85:0,107:2,85:0,85:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,85:0,85:0,107:0,85:0,85:0,0:0,85:0,85:0,107:0,85:0,85:0,35:1
    35:1,31:1,0:0,31:1,31:1,85:0,0:0,85:0,31:1,31:1,31:1,31:1,35:1
    35:1,0:0,31:1,31:1,31:1,107:1,0:0,107:3,31:1,31:1,31:1,0:0,35:1
    35:1,0:0,31:1,31:1,31:1,85:0,0:0,85:0,31:1,31:1,38:0,31:1,35:1
    124:0,0:0,31:1,31:1,0:0,85:0,0:0,85:0,0:0,38:0,31:1,31:1,124:0
    69:13,124:0,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,124:0,69:14
    0:0,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,0:0
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    0:0,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,0:0
    0:0,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,0:0
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    0:0,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,35:1,0:0
    0:0,0:0,0:0,0:0,35:1,124:0,98:0,124:0,35:1,0:0,0:0,0:0,0:0
    0:0,35:1,35:1,35:1,0:0,0:0,0:0,0:0,0:0,35:1,35:1,35:1,0:0
    0:0,35:1,124:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,124:0,35:1,0:0
    0:0,35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1,0:0
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    124:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,124:0
    98:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,98:0
    124:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,124:0
    35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1
    0:0,35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1,0:0
    0:0,35:1,124:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,124:0,35:1,0:0
    0:0,35:1,35:1,35:1,0:0,0:0,0:0,0:0,0:0,35:1,35:1,35:1,0:0
    0:0,0:0,0:0,0:0,35:1,124:0,98:0,124:0,35:1,0:0,0:0,0:0,0:0
    0:0,0:0,0:0,0:0,69:13,35:8,0:0,35:8,69:13,0:0,0:0,0:0,0:0
    0:0,0:0,0:0,0:0,35:1,0:0,98:0,0:0,35:1,0:0,0:0,0:0,0:0
    0:0,0:0,69:14,35:1,0:0,0:0,0:0,0:0,0:0,35:1,69:14,0:0,0:0
    0:0,0:0,35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1,0:0,0:0
    69:14,35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1,69:14
    35:8,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:8
    0:0,98:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,98:0,0:0
    35:8,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:8
    69:14,35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1,69:14
    0:0,0:0,35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1,0:0,0:0
    0:0,0:0,69:13,35:1,0:0,0:0,0:0,0:0,0:0,35:1,69:14,0:0,0:0
    0:0,0:0,0:0,0:0,35:1,0:0,98:0,0:0,35:1,0:0,0:0,0:0,0:0
    0:0,0:0,0:0,0:0,69:13,35:8,0:0,35:8,69:13,0:0,0:0,0:0,0:0
    0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0
    0:0,0:0,0:0,0:0,0:0,35:8,0:0,35:8,0:0,0:0,0:0,0:0,0:0
    0:0,0:0,0:0,0:0,35:1,0:0,98:0,0:0,35:1,0:0,0:0,0:0,0:0
    0:0,0:0,0:0,35:1,0:0,0:0,44:13,0:0,0:0,35:1,0:0,0:0,0:0
    0:0,0:0,35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1,0:0,0:0
    0:0,35:8,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:8,0:0
    0:0,0:0,98:0,44:13,0:0,0:0,0:0,0:0,0:0,44:13,98:0,0:0,0:0
    0:0,35:8,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:8,0:0
    0:0,0:0,35:1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,35:1,0:0,0:0
    0:0,0:0,0:0,35:1,0:0,0:0,44:13,0:0,0:0,35:1,0:0,0:0,0:0
    0:0,0:0,0:0,0:0,35:1,0:0,98:0,0:0,35:1,0:0,0:0,0:0,0:0
    0:0,0:0,0:0,0:0,0:0,35:8,0:0,35:8,0:0,0:0,0:0,0:0,0:0
    0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0
    0:0,0:0,0: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,0:0,0:0,0:0,0:0,0:0,0:0
    0:0,0:0,0:0,35:8,35:8,35:8,0:0,35:8,35:8,35:8,0:0,0:0,0:0
    0:0,0:0,0:0,0:0,35:8,35:8,0:0,35:8,35:8,0:0,0:0,0:0,0:0
    0:0,0:0,0:0,0:0,0:0,35:8,0:0,35:8,0:0,0:0,0:0,0:0,0:0
    0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0
    0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0
    0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,19:0
    So, make a handy class that can read those values and give you a List of Blocks or something.

    As for the TARDIS creation thing, what are you confused about? Detecting if the player created the right shape to make a TARDIS, or actually building the TARDIS?
     
  3. Offline

    SpectrumCrafter


    First of all, cant I just use a schematic file? That seems WAY to complicated. Second of all, I want to know about the detection of the player making the right shape and last of all, Doctor Who is a baus!
     
  4. Offline

    The_Doctor_123

    That's no lie.

    Not sure how schematic files work. :p But schematics would be way more complicated than that. I'm sure schematics are compressed and junk. All that is I showed you is layers. For example:

    Layer 1:
    Code:
    1:0, 0:0, 1:0
    0:0, 0:0, 0:0
    1:0, 0:0, 1:1
    Layer 2:
    Code:
    0:0, 0:0, 0:0
    0:0, 1:0, 0:0
    0:0, 0:0, 0:0
    Layer 3:
    Code:
    1:0, 0:0, 1:0
    0:0, 0:0, 0:0
    1:0, 0:0, 1:1
    That would look like:
    [​IMG]
     
  5. Offline

    qhenckel

    use the eventhandler BlockPlaceEvent. eventhandlers
    Then use like block.getRelative() to check if it's all there

    if you're going to "paste" schematics you will have to use worldedit.
    this mean you have to add the worldedit.jar file as an external library then check the worldedit API for the rest.
     
  6. Offline

    SpectrumCrafter

    Ahhh Ok, so I get the layers stuff but what about the player detection?
     
  7. Offline

    qhenckel

    The_Doctor_123 evidently I don't exist =P
    SpectrumCrafter
    Code:
    if event.getblock == material.diamond{
      if event.getblock.getrelative == matrial.lapis
          putschmatichere();
    }
    Just to give you an idea =)
     
  8. Offline

    SpectrumCrafter



    Oh, sorry. So what would that look like? Like would it be a diamond on top of a lapis or what?
     
  9. Offline

    qhenckel

    Code:java
    1. public void tardis(BlockPlaceEvent event){
    2. if(event.getBlock().getType().equals(Material.REDSTONE_TORCH_OFF)){//is the block placed a tourch
    3. if(event.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.LAPIS_BLOCK)){//is the one under it lapis
    4. if(event.getBlock().getRelative(BlockFace.DOWN).getRelative(BlockFace.DOWN).getType().equals(Material.DIAMOND_BLOCK)){
    5. //do what ever
    6. }
    7. }
    8. }
    9. }
     
  10. Offline

    SpectrumCrafter


    Ok, but I have one more question. So I got the code to detect the block placement, I have the whole layers thing down, but now I need to know how code it to where it will create the layers

    My code:

    Code:java
    1. public void test(BlockPlaceEvent event){
    2.  
    3. if(event.getBlock().getType().equals(Material.REDSTONE_TORCH_ON)){
    4. if(event.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.LAPIS_BLOCK)){
    5. if(event.getBlock().getRelative(BlockFace.DOWN).getRelative(BlockFace.DOWN).getType().equals(Material.DIAMOND_BLOCK)){
    6.  
    7. //What would go here to generate the layers
    8.  
    9. }
    10.  
    11. }
    12.  
    13. }
    14.  
    15. }
    16.  
     
  11. Offline

    qhenckel

    Code:java
    1. public final class Mylistener implements Listener {
    2. @EventHandler
    3. public void tardis(BlockPlaceEvent event){
    4. if(event.getBlock().getType().equals(Material.REDSTONE_TORCH_ON)){
    5. if(event.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.LAPIS_BLOCK)){
    6. if(event.getBlock().getRelative(BlockFace.DOWN).getRelative(BlockFace.DOWN).getType().equals(Material.DIAMOND_BLOCK)){
    7. Block base = event.getBlock().getRelative(BlockFace.DOWN).getRelative(BlockFace.DOWN);
    8. Location ori = base.getRelative(BlockFace.NORTH_WEST).getLocation();
    9. int layloc;
    10. for (int y = 0; y < 3; y++){
    11. int by = ori.getBlock().getY() + y;
    12. layloc = 0;
    13. for (int x = 0; x < 3; x++){
    14. int bx = ori.getBlock().getX() + x;
    15. for (int z = 0; z < 3; z++){
    16. int bz = ori.getBlock().getZ() + z;
    17. Location block = new Location(event.getBlock().getWorld(), bx, by, bz);
    18. block.getBlock().setType(Material.matchMaterial(layers(y, layloc)));
    19. layloc++;
    20. }
    21. }
    22. }
    23. }
    24. }
    25. }
    26. }
    27. }
    28.  
    29. public String layers(int y, int layloc){
    30. String[] layer1 = {
    31. "STONE", "AIR", "STONE",
    32. "AIR", "STONE", "AIR",
    33. "STONE", "AIR", "STONE"
    34. };
    35.  
    36. String[] layer2 = {
    37. "AIR", "AIR", "AIR",
    38. "AIR", "STONE", "AIR",
    39. "AIR", "AIR", "AIR"
    40. };
    41.  
    42. String[] layer3 = {
    43. "STONE", "AIR", "STONE",
    44. "AIR", "STONE", "AIR",
    45. "STONE", "AIR", "STONE"
    46. };
    47. if (y == 0){return layer1[layloc];}
    48. if (y == 1){return layer2[layloc];}
    49. if (y == 2){return layer3[layloc];}
    50. return null;
    51. }
     
Thread Status:
Not open for further replies.

Share This Page