Solved Change Cauldron Water Level

Discussion in 'Spigot Plugin Development' started by Alex_qp, Jul 5, 2018.

  1. Hey,

    I want to change the water level of a cauldron and if possible also get the water level in a better way than mine. I created a workaround to get the water level (by getting the information out of the data string) but I cannot find a solution to set the new water level.

    - The MaterialData subclass Cauldron does not contain a method for this.
    - I tried
    Code (Text):

    CauldronLevelChangeEvent cauldronEvent = new CauldronLevelChangeEvent(itemLoc.getBlock(), e.getPlayer(), CauldronLevelChangeEvent.ChangeReason.UNKNOWN, oldWater, newWater);
                        cauldronEvent.setNewLevel(newWater);
                        itemLoc.getBlock().getState().update();
    with little hope but it did not work
    - Google searches containing spigot and cauldron will lead to endless discussions about cauldron.


    I neither want to use deprecated functions nor call an event (if thats even a solution).

    Best regards
    Alex
     
  2. Code (Java):
    Cauldron cauldron = (Cauldron) block.getState().getData();

    BlockState cauldronState = block.getState();
    cauldronState.getData().setData((byte) (cauldron.getData() + 1));
    cauldronState.update();
     
  3. Choco

    Moderator

    Just to throw this out there for anyone in the future who refers to this thread: 1.13 has a Levelled BlockData interface in which you may change the volume of a levelled block (cauldron, for example).
    Code (Java):
    Block yourCauldron = ...;
    Levelled cauldronData = (Levelled) yourCauldron.getBlockData();
    cauldronData.setLevel(cauldronData.getMaximumLevel()); // Fill it up!
    yourCauldron.setBlockData(cauldronData);
     
    #3 Choco, Jul 6, 2018
    Last edited: Jul 25, 2018
    • Like Like x 2
    • Winner Winner x 1
  4. Optic_Fusion1

    Resource Staff

    This....would be useful.....if i could think of uses for it
     
  5. FrostedSnowman

    Resource Staff

    this thread
     
    • Creative Creative x 1
  6. Why are those functions deprecated if there is no other solution?

    I guess I will wait until 1.13 to try what 2008Choco suggested.
     
  7. Choco

    Moderator

    They were deprecated due to magic values (arbitrary numbers associated with states). For example, numerical IDs have been deprecated since Minecraft 1.7 but were supported up until Minecraft 1.13. There are a number of deprecations in Bukkit that may be ignored if there are no alternatives because there simply aren't any decent alternatives anyone could come up with. Cauldron water levels are one of those things. Though because 1.13 is so close, there will not be a replacement in 1.12 considering MaterialData will be deprecated anyways.
     
  8. :O GG with Junior Mod :D, But do you still manage resources aswell? :p
     
  9. I just want to correct this before marking the thread as solved:
    In the last line it has to be yourCauldron.setBlockData(cauldronData).

    But thanks for the post it really helped me updating my code!
     
    • Agree Agree x 1