MaterialData for items such as slabs from config

Discussion in 'Plugin Development' started by ZephireNZ, Oct 19, 2013.

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

    ZephireNZ

    I'm developing a plugin that will have the item name (eg WOOL) stored in a config file. However, to allow for things such as wool colours and wood types, I'm including a second 'data' variable in the config, that will adapt depending on the material type (eg WOOL would create Wool with DyeColor, whereas WOOD would create Tree with TreeSpecies).

    So far I've made progress, covering all the Material types that have MaterialData. I have come across a couple snags, however:
    Code:java
    1. Material material = Material.getMaterial(item);
    2. ItemStack itemStack = new ItemStack(material);
    3. MaterialData materialData = null;
    4.  
    5. switch(material) {
    6. case WOOD:
    7. case SAPLING:
    8. case LOG:
    9. case LEAVES:
    10. materialData = new Tree(TreeSpecies.valueOf(data));
    11. break;
    12. case SANDSTONE:
    13. materialData = new Sandstone(SandstoneType.valueOf(data));
    14. break;
    15. case LONG_GRASS:
    16. materialData = new LongGrass(GrassSpecies.valueOf(data));
    17. break;
    18. case WOOL:
    19. materialData = new Wool(DyeColor.valueOf(data));
    20. break;
    21. // WARNING: NOT SURE HOW WOOD SLABS WILL WORK
    22. case DOUBLE_STEP:
    23. case STEP:
    24. materialData = new Step(Material.valueOf(data));
    25. break;
    26. case WOOD_STAIRS:
    27. case COBBLESTONE_STAIRS:
    28. materialData = new Stairs(Material.valueOf(data));
    29. break;
    30. case SMOOTH_BRICK:
    31. materialData = new SmoothBrick()
    32. }


    The methods for getting data for wood and Smooth brick have recently been deprecated, but as far as I know there's no way to get the Material type for birch wood or cracked stone brick, for example.

    So, any help? Or even more so, is there better way to do this? It needs to be human readable (ie no serialization) and won't need to be updated once it's set.

    Probably should have read a little further haha. The WoodenStep covers the steps, luckily. But the blocks like SMOOTH_BRICK are still unknown to me.

    ... and I answer my own question yet again, by starting up a debugger and just running the SmoothBrick().getTextures() method.

    Apparently they use STONE, MOSSY_COBBLESTONE, COBBLESTONE and SMOOTH_BRICK to define the textures for each, and I'm assuming STONE is normal smooth stone, and SMOOTH_BRICK is carved.

    Unless I missed something, that kind of thing should *really* be in the documentation for SmoothBrick. Otherwise it's confusing as to how you work it out without using deprecated methods.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page