Set block with meta date

Discussion in 'Spigot Plugin Development' started by to175, May 30, 2015.

  1. Hello, I need to set a block as a material with meta data, but I don't understand, can you please give me few line to explain me how to do ? :)
    For example : set 2 types of log

    Thanks !
     
  2. To clarify: You'd have to use Block#setData(). You could've also found this yourself in the Spigot JavaDocs, I suggest you get familiar with them for later reference.
     
  3.  
  4. No one is going to spoon-feed you.
     
  5. If you ask us to provide you with the code, you won't learn to program this yourself - just to copy paste. I'd suggest thinking about the answers we give and looking into the resources we link, so you can figure out how to do this yourself. It'll help you out in the long run!
     
  6. Thanks, I just don't understand that "itemstackname" is equals to "material"
     
  7. Have you even programmed before, this is probably one of the worst spoon feeding threads I have seen in a while. Go look up some tutorials on how to program in Java and then come back. As has been mentioned, nobody is going to spoon feed you.
     
    • Funny Funny x 1
  8. I have already made this :
    Code (Text):
    Random rand = new Random();
                                    List<Material> liste = new ArrayList<Material>();

                                    int randStone = rand.nextInt(20 - 15 + 1) + 15;
                                    for(int i=0; i<= randStone; i++){
                                      liste.add(Material.STONE); // la liste de tes éléments
                                    }
                                    int randDirt = rand.nextInt(7 - 5 + 1) + 5;
                                    for(int i=0; i<= randDirt; i++){
                                        liste.add(Material.DIRT);
                                    }
                                 
                                    int randCoal = rand.nextInt(15 - 5 + 1) + 5;
                                    for(int i=0; i<= randCoal; i++){
                                        liste.add(Material.COAL_ORE);
                                    }
                                 
                                    int randFer = rand.nextInt(15 - 5 + 1) + 5;
                                    for(int i=0; i<= randFer; i++){
                                        liste.add(Material.IRON_ORE);
                                    }
                                 
                                    int randLapis = rand.nextInt(10 - 5 + 1) + 5;
                                    for(int i=0; i<= randLapis; i++){
                                        liste.add(Material.LAPIS_ORE);
                                    }
                                 
                                    int randGravel = rand.nextInt(15 - 10 + 1) + 10;
                                    for(int i=0; i<= randGravel; i++){
                                        liste.add(Material.GRAVEL);
                                    }
                                 
                                    int randRedstone = rand.nextInt(10 - 5 + 1) + 5;
                                    for(int i=0; i<= randRedstone; i++){
                                        liste.add(Material.REDSTONE_ORE);
                                    }
                                 
                                    int randOr = rand.nextInt(3 - 0 + 1) + 0;
                                    for(int i=0; i<= randOr; i++){
                                        liste.add(Material.GOLD_ORE);
                                    }
                                 
                                    int randEmeraude = rand.nextInt(1 - 0 + 1) + 0;
                                    for(int i=0; i<= randEmeraude; i++){
                                        liste.add(Material.EMERALD_ORE);
                                    }
                                 
                                    int randDiams = rand.nextInt(1 - 0 + 1) + 0;
                                    for(int i=0; i<= randDiams; i++){
                                        liste.add(Material.DIAMOND_ORE);
                                    }
                                 
                                    int restant = 100 - liste.size();
                                    for(int i=0; i<= restant; i++){
                                        liste.add(Material.COBBLESTONE);
                                        }
                                 
                                    Collections.shuffle(liste);
                                    World world = Bukkit.getServer().getWorld("Mecraft");
                                    int i=0;
                                    for(int x=165;x<=169;x++){
                                        for(int y=0;y<=4;y++){
                                            for(int z=68;z<=71;z++){
                                                int newY = y-231;
                                                Location location = new Location(world, newY, z, x, (float) 92.851685, (float) 12.149901);
                                                world.getBlockAt(location).setType(liste.get(i));
                                                i++;
                                            }
                                        }
                                    }
    But I can't for data !!!
    $
    I have lists of "material" which is different from itemstack !
     
  9. ItemStack itemstackname = new ItemStack(Material.LOG, 1, (short) 2)

    Or .getLocation().getBlock().setData((byte) data)

    Fuck the logic.
     
    #10 robertforyou, May 30, 2015
    Last edited: May 30, 2015
  10. I still don't understand. I have list of materials and you give me "ItemStack",
    first my list can't add ItemStack and the line which set the block is
    world.getBlockAt(location).setType(liste.get(i));
    I can"t do :
    world.getBlockAt(location).setData((byte) data)
    This is stupid I have
    Code (Text):
    for(int x=165;x<=169;x++){
                            for(int y=0;y<=4;y++){
                                for(int z=a;z<=b;z++){
                                    int newY = y-231;
    And nobody know where is the log which has to have data "2" in the list because of the random algo.

    No way you are all wrong, your theories (so no code to provide) are dumb so nobody have the answer that's all ! But say it instead of speaking about spoon...

    The method setType(Material) in the type Block is not applicable for the arguments (ItemStack)
     
  11. Why the fuck you want to spoon feed you? You can use setData(), you can use hashmaps instead of lists to store materials and datas. We are on Spigot, if you want to be spoon-feeded go to bukkit.

    We gave you the method to set data on a block, now you need to think yourself for your own code and make it also set the data as you need.
     
    #12 robertforyou, May 31, 2015
    Last edited: May 31, 2015
  12. I have not the locations !
    Blocks are randomly placed.
    I don't want to change every data but only few blocs !
    So I can't do this after blocks are set...

    Ps : you just give me theoric stuff that I already have... I can't use them properly, I'm asking for help in a forum.
     
  13. As i said, use HashMaps instead of array list as you can store more variables, you can create a hashmap with Integer, String, Byte, Material etc.
    So you could to create a hashmap with integer (where would be just to count), material (where you store the material) and byte (where you store the data of the block). More i can't give you, because this is pure java, if you want to code a plugin for mc, first learn java.
     
  14. @to175 ItemStacks have MetaData. Simple procedure:
    Get a location (say it's called DummyLand).
    Get the Block at a location (which would be DummyLand) OR Create a new ItemStack or Block.
    Change the Item/Block you created to whatever you desire
    Set the ItemMeta or BlockMeta to whatever you desire.
    Place block at the location you want (which would be DummyLand).

    For more information on how to program using Java, use Wikipedia and other tutorials, or hire a tutor.

    Dun Dun Dun
     
    #15 GODofCRAFTERS, May 31, 2015
    Last edited: May 31, 2015
  15. I don't understand, I will try to see that. (This is not "java", this is algorithm)
    And of course you read my code and implicitly say I can
    Collections.shuffle(liste); my hash map hu ? ...
    I have not the locations look at my code...

    Edit : The = of blocks I want to be log(2)
     
    #16 to175, May 31, 2015
    Last edited: Jun 1, 2015
  16. Well I must be mis-informed. I think Location is not spelled "l-o-c-a-t-i-o-n"... Stupid me...
     
    • Funny Funny x 1
  17. Ooooh great ! Stupid me... I must be mis-informed. I didn't know that you can use a location A to modify a block at location B...

    Ps : this is a 5*5*4 cube so omg 1 location for 100 blocks ? nice :D

    Edit : I read again, ok the problem is that how do you know this is the block I want to change ? This is in a "for for for" loop !
     
    #18 to175, Jun 1, 2015
    Last edited: Jun 1, 2015
  18. I assumed it is the block you want to change. Because you are setting the block at that location with:
     
  19. Ok great, this is AIR block. I can change it with the list so I can put only "Material" with "setType()" !
    In the list there are : stone, log(2), log(3) etc... so i can't do setdata because I don't know which block is read in the list to be set. And I even don't know how to put instead of log(2) etc...