Problem With Materials

Discussion in 'Plugin Development' started by Molten, Jan 10, 2014.

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

    Molten

    I'm having a problem with materials, I have a check to see if the block is valid and I'm getting problems on blocks that have more than 1, as in wood, or wool etc.

    I'm not finding the actual names of those if I try and do Material.getMaterial(Block Name)
    I can only find the first one of regular wool, or wood (which is oak).

    I set my variables based on what the user entered, if they enter 17:1 then it's spruce wood etc. I then set another variable to that name so Block Name = spruce wood if the player entered 17:1.

    But as far as I know, there isn't anything named spruce wood, or magenta wool that I can use so it gives me an error when I use for example, 17:1.

    Here's my list for "int's" to strings, such as 17:1 -> spruce wood. I do this elsewhere in the code but the String arrays are basically 1-1 as far as location goes. I used this site to get the base names expecting them to be the same but they are not. http://minecraft-ids.grahamedgecombe.com/

    Is there anyone that can help me get the actual names that I can use this way? By this way I mean Material.getMaterial(Name)

    Here are the arrays I have with the id's and names:

    Code:java
    1. private String[] validBlockIDs = {"1", "2", "3","4", "5", "5:1","5:2", "5:3", "17","17:1", "17:2", "17:3",
    2. "20", "24", "24:1","24:2", "35", "35:1","35:2", "35:3", "35:4", "35:5",
    3. "35:6", "35:7", "35:8","35:9", "35:10", "35:11","35:12", "35:13", "35:14",
    4. "35:15", "43", "43:1","43:2", "43:3", "43:4","43:5", "43:6", "43:7","45",
    5. "48", "49", "60", "78", "79","80", "82", "87","88", "89", "98", "98:1",
    6. "98:2", "98:3", "110","112", "121", "125", "125:1", "125:2",
    7. "125:3", "155", "159", "159:1","159:2", "159:3", "159:4", "159:5","159:6",
    8. "159:7", "159:8","159:9", "159:10", "159:11","159:12", "159:13", "159:14",
    9. "159:15", "170", "172"};
    10. private String[] validBlockNames = {"STONE", "GRASS", "DIRT","COBBLESTONE",
    11. "OAK_WOOD_PLANK", "SPRUCE_WOOD_PLANK", "BIRCH_WOOD_PLANK",
    12. "JUNGLE_WOOD_PLANK", "OAK_WOOD","SPRUCE_WOOD", "BIRCH_WOOD",
    13. "JUNGLE_WOOD","GLASS", "SANDSTONE",
    14. "CHISELED_SANDSTONE","SMOOTH_SANDSTONE", "WHITE_WOOL",
    15. "ORANGE_WOOL","MAGENTA_WOOL", "LIGHT_BLUE_WOOL", "YELLOW_WOOL",
    16. "LIME_WOOL","PINK_WOOL", "GRAY_WOOL", "LIGHT_GRAY_WOOL","CYAN_WOOL",
    17. "PURPLE_WOOL", "BLUE_WOOL","BROWN_WOOL", "GREEN_WOOL",
    18. "RED_WOOL","BLACK_WOOL", "DOUBLE_STONE_SLAB",
    19. "DOUBLE_SANDSTONE_SLAB","DOUBLE_WOODEN_SLAB",
    20. "DOUBLE_COBBLESTONE_SLAB", "DOUBLE_BRICK_SLAB",
    21. "DOUBLE_STONE_BRICK_SLAB", "DOUBLE_NETHER_BRICK_SLAB",
    22. "DOUBLE_QUARTZ_SLAB","BRICK", "MOSSY_COBBLESTONE", "OBSIDIAN", "SOIL", "SNOW",
    23. "ICE","SNOW_BLOCK", "CLAY", "NETHERRACK", "SOUL_SAND", "GLOWSTONE",
    24. "STONE_BRICK", "MOSSY_STONE_BRICK","CRACKED_STONE_BRICK",
    25. "CHISELED_STONE_BRICK", "MYCELIUM","NETHER_BRICK",
    26. "END_STONE","DOUBLE_OAK_WOOD_SLAB", "DOUBLE_SPRUCE_WOOD_SLAB",
    27. "DOUBLE_BIRCH_WOOD_SLAB","DOUBLE_JUNGLE_WOOD_SLAB", "QUARTZ_BLOCK",
    28. "WHITE_STAINED_CLAY", "ORANGE_STAINED_CLAY","MAGENTA_STAINED_CLAY",
    29. "LIGHT_BLUE_STAINED_CLAY", "YELLOW_STAINED_CLAY",
    30. "LIME_STAINED_CLAY","PINK_STAINED_CLAY", "GRAY_STAINED_CLAY",
    31. "LIGHT_GRAY_STAINED_CLAY","CYAN_STAINED_CLAY",
    32. "PURPLE_STAINED_CLAY","BLUE_STAINED_CLAY","BROWN_STAINED_CLAY",
    33. "GREEN_STAINED_CLAY", "RED_STAINED_CLAY", "BLACK_STAINED_CLAY", "HAY_BALE",
    34. "HARDENED_CLAY"};
    35.  
    36.  



    Sorry about the formatting, it looks a lot better in my file.
     
  2. Offline

    CopyableCougar4

    For wools I know you have to declare the ItemStacks like this:
    Code:java
    1. Wool w = new Wool(DyeColor.GREEN); // declares a green wool object
    2. ItemStack i = w.toItemStack(); // converts the wool to an item stack


    Also, I think for woods you declare the ItemStack by using a third parameter after Quantity, like so:
    Code:java
    1. ItemStack i = new ItemStack(Material.WOOD, 1, (short)3); // should get a jungle wood block


    Let me know if this doesn't work, as I am not entirely positive about the wood itemstack. But I know the wool code works :)
     
  3. Offline

    evilmidget38

    Molten Material only represents the "regular item". Every other item is specified as either the durability for that ItemStack, or the data for that Block. For example, 5:1 would represent an ItemStack with the Material WOOD and a durability of 1. If you just want a "regular item", then you should keep the default durability of 0.
     
  4. Offline

    Molten

    So how do I use itemstacks to place a block though? Im trying to setType for a block and not sure how I can with itemstacks.
     
  5. Offline

    evilmidget38

    Molten You'd want to get the block, and then set the type to the material of the ItemStack, and the data to the durability of the ItemStack. Keep in mind though that this isn't going to work for Materials that only represent an item and not a block, such as tools or records. I believe beds also require special treatment as they're made up of two blocks instead of one.
     
  6. Offline

    Molten

    evilmidget38 so the durability means which one it is, i.e oak would be 0, spruce 1, etc.

    Im still not sure how to set a block using itemstacks vs material. Are you able to explain that a little bit?

    Also, thanks for the reply!!

    Ok that makes sense, and i dont need item types other than blocks. Im making a basic drawbridge plugin that uses most regular blocks without ores etc.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  7. Offline

    evilmidget38

    Exactly.
    Code:
    // Get whatever Block you need.
    Block block =someWorld.getBlockAt(someX, someY, someZ);
     
    // Set the type of the block to whatever the type of the ItemStack is.
    block.setType(someItem.getType());
     
    // Also apply the durability of the item to the block, that way you keep the data value.
    block.setData(someItem.getDurability());
    setData is deprecated as it relies upon magic numbers, but I figured it was best to keep referencing magic numbers since you were using them in your original post.
     
    lukegb likes this.
  8. Offline

    Molten

    Thanks that helps a lot, and i thought setType wasnt deprecated and was in use? Thats what ive been using, is there something else i should be?
     
  9. Offline

    dupsmckracken


    How would I achieve this without using .setData()?
     
Thread Status:
Not open for further replies.

Share This Page