Solved In 1.13 how would I toggle a redstone torch off/on?

Discussion in 'Spigot Plugin Development' started by Ugleh, Sep 5, 2018.

Thread Status:
Not open for further replies.
  1. I used to be able to do it by changing the material from REDSTONE_TORCH_OFF to REDSTONE_TORCH_ON but that no longer works in 1.13, instead we have LEGACY_ appended to them both, however I noticed on the wiki there is an ID called unlit_redstone_torch. How would I use that ID since the API doesn't have that yet?

    I also see there is a block state for "lit" to equal true or false. What is the newest way to set/get the blockstate via the tag?
     
    #1 Ugleh, Sep 5, 2018
    Last edited: Sep 5, 2018
  2. Senmori

    Senmori Retired Resource Staff
    Retired Patron

    REDSTONE_TORCH has a BlockData of type 'Lightable'.
    REDSTONE_WALL_TORCH has a BlockData of type 'RedstoneWallTorch'.

    Use those to set if the torch is lit or not. I'm fairly sure that is calculated every tick though, so you might need to set up a repeating task
    to handle that.
     
  3. That ID doesn't exist in 1.13. It's the wiki that is outdated, not the API. Both REDSTONE_TORCH and REDSTONE_WALL_TORCH are Lightables. Set the block type to whatever you need, get the BlockData and cast it to Lightable.
    Code (Text):
    block.setType(Material.REDSTONE_WALL_TORCH);
    Lightable data = (Lightable) block.getBlockData();
    data.setLit(true);
    block.setBlockData(data);
     
  4. Is the JavaDoc not updated either because Lightable is only a an interface for Redstone Wall Torch and not Redstone Torch.

    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/type/RedstoneWallTorch.html

    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/material/RedstoneTorch.html
     
  5. Redstone torchs don't have unique BlockData, they are just Lightable, while redstone wall torchs are RedstoneWallTorchs, which doesn't have unique methods either, but brings together Lightable and Directional.
     
  6. Thank you all for your help. I used @Sataniel's example above. Worked out just fine.
     
Thread Status:
Not open for further replies.