Cauldrons problems

Discussion in 'Plugin Development' started by callum.thepro, Apr 9, 2014.

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

    callum.thepro

    Ok, I want it so that after someone presses the cauldron with the bucket, it emptys the cauldron.

    Code I have at the minute:
    Code:java
    1. if (player.getItemInHand().getType() == Material.BUCKET && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.CAULDRON) {
    2. Cauldron block = (Cauldron) event.getClickedBlock().getState().getData();
    3. if (block.isFull()) {
    4. player.getInventory().remove(new ItemStack(Material.BUCKET));
    5. player.getInventory().addItem(new ItemStack(Material.WATER_BUCKET));
    6. block.setData((byte) 0);
    7. player.updateInventory();
    8. return;
    9. } else {
    10. return;
    11. }
    12. }


    It lets them fill the bucket but the cauldron does not empty.
    Thanks in advance
     
  2. Offline

    Hoolean

    callum.thepro

    Have you experimented with different values for block.setData()? If I remember correctly, higher values may correspond to an empty cauldron, with 0 meaning full.
     
  3. Offline

    xTigerRebornx

  4. Offline

    Hoolean

    xTigerRebornx

    And so they are! Those should definitely be used preferably. Looking at that, it sure looks like 0 does mean empty.

    However, callum.thepro , I think I know what the problem is. When doing Block.getState(), it gets a fixed snapshot of the Block, which will not be changed by modifications.

    Try changing:

    Code:
    Cauldron block = (Cauldron) event.getClickedBlock().getState().getData();
    to:

    Code:
    Cauldron block = (Cauldron) event.getClickedBlock().getData();
    :)
     
  5. Offline

    xTigerRebornx

    Hoolean Well, he needs the MaterialData from the BlockState to be able to cast it to a Cauldron, couldn't he just update the BlockState instead?
     
  6. Offline

    Hoolean

    xTigerRebornx

    Sorry, this line:
    Code:
    use block.getState() to get a snapshot state of a block which will not be modified.
    ...in the JavaDocs confused me, perhaps I should not be awake at this hour. ;)
     
  7. Offline

    xTigerRebornx

    Hoolean I believe that is saying that the state will not be modified by Bukkit, but you are able to manipulate it and then apply an update
     
  8. Offline

    callum.thepro

    I cannot apply an update as I use the blocks data. Either that or it did not work. If I do not use .getData() then it simply breaks and gives me a classCastException

    xTigerRebornx Hoolean Bump

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

    xTigerRebornx

    callum.thepro You need to apply an update to set the changes you've done to that BlockState.
    An idea for solving this could be setting the Block's type to air then back to Cauldron.
     
  10. Offline

    Brixishuge

    get location of clicked block(full cauldron), remove clicked block (full cauldron), put new cauldron there...
     
  11. Offline

    callum.thepro

    xTigerRebornx I have tried doing that, but for some reason, that does not work either. I thought that was strange.
     
Thread Status:
Not open for further replies.

Share This Page