Test if a Material generates water

Discussion in 'Plugin Development' started by Poplo, Nov 11, 2020.

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

    Poplo

    Hi all,

    I'm trying to find a way to test if a material "generates" water.
    For example, if I set the materialDEAR_HORN_CORAL_FAN on a block, water starts flowing. How can I identify materials that do that ?

    Thank you all in advance !
    Poplo
     
  2. Offline

    KarimAKL

  3. Offline

    Poplo

    In order to do that, I need a Block, right ? I can't reach that from a Material, correct ?
    I'm currently using a preloaded list of materials, in which I randomly pick materials. I don't want any water, but I still have some water flowing from my construction. Even if I do something like that :

    Code:
    Block b = player.getEyeLocation().getBlock();
    do {
      b.setType(getRandomMaterial());
    } while(b.getBlockData() instanceof Waterlogged);
     
    Last edited: Nov 11, 2020
  4. Offline

    KarimAKL

  5. Offline

    Poplo

    I have only a Material object, no Block or BlockData, I can't find out how I can use
    createBlockData() or Waterlogged in these conditions :confused:

    My explanations are not clear, nor complete.
    Here is the code :
    Code:
    static void staticInit() {
      int i = 0;
      for (Material m : Material.values())
        if (m.isSolid() && m.isBlock() && !m.name().contains("CORAL") &&   !m.name().contains("CONDUIT")) ++i;
    
      solidMaterials = new Object[i];
    
      i = 0;
      for (Material m : Material.values()) {
        if (m.isSolid() && m.isBlock() && !m.name().contains("CORAL") && !m.name().contains("CONDUIT")) {
        solidMaterials[i++] = m;}
      }
    }
    
    I already found that any CORAL Blocks or CONDUIT flows water. But I'm sure there is better to do than testing each Material :rolleyes:
     
    Last edited: Nov 11, 2020
  6. Offline

    KarimAKL

    @Poplo You get the BlockData using Material or Block. You have the Material, so you can just use the method for that.

    Question: What are you trying to do? What is your end goal?
     
  7. Offline

    Poplo

    @KarimAKL I'm trying to make a method returning a random Material
     
  8. Offline

    KarimAKL

    @Poplo
    Code:Java
    1. public Material getRandomMaterial() {
    2. // Get all possible materials
    3. Material[] materials = Material.values();
    4.  
    5. // Get a random element from the materials array between index 0 and size of array
    6. return materials[ThreadLocalRandom.current().nextInt(materials.length)];
    7. }

    I wrote this on my phone, but it should still work.
     
Thread Status:
Not open for further replies.

Share This Page