Solved Is it possible to get the data value of a right clicked block?

Discussion in 'Plugin Development' started by AdamDev, Jul 31, 2017.

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

    AdamDev

    As the title goes. I'm trying to do a plugin that when you right click a quartz slab it brings up a menu. I know how to do the menu part. It's just that I only want so that when you click a quartz slab that menu pops up.

    Here's my code:
    Code:
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    
    import me.hype.factorio.Core;
    
    public class TransBeltClicked implements Listener {
    
    public Core plugin = Core.getPlugin();
    
    @EventHandler
    public void transBC(PlayerInteractEvent e) {
    Player p = (Player) e.getPlayer();
    if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) {
        if (e.getClickedBlock().getType == Material.STEP) {
         // Code here
              }
           }
        }
    }
    
    
    
    So if it would be possible for someone to be able to help me I would be glad. :D

    P.S Somewhat new to this kind of stuff.
    P.S.S Did this on my phone may have some errors.
     
  2. Offline

    Caderape2

    @AdamDev
    for Enum, use == and not equals().
    block..getData() will return the data value of the block, like 15 for black wool for example.
    quartz slab should return 7 i think.
    It's deprecated but i dun know if there's another way
     
    Last edited: Jul 31, 2017
  3. Offline

    AdamDev

    @Caderape2
    So does that mean I would do
    e.getClickedBlock.getData()?
     
  4. Offline

    Caderape2

    @AdamDev try it in the event and print the value when you click the quartz lab.
     
  5. Offline

    AdamDev

    It says that "Incompatible operand types byte and Material".

    Edit: I did:
    e.getClickedBlock().getType().getData() != null
    But what can I do to test for a quartz slab
     
  6. Offline

    Machine Maker

    @AdamDev
    Using getData() on a Material gives the MaterialData class associated with the material type, not the data value of the block. It is safe to use e.getClickedBlock().getData() to give you the data value of the block for now. But I think next update Mojang wants to give every block its own id so make sure its not broken next update.
     
  7. Offline

    AdamDev

    So then is that for all versions? Because I'm doing this in 1.8. Like will they be only changing it in the recent version of bukkit or for all of them?

    Edit: Other than that is there any way that the right clicked block would have to have a name? So let's for say it's named 'Bat' only that slab that's named 'Bat' would only be accessable?
     
    Last edited: Jul 31, 2017
  8. Offline

    Zombie_Striker

    Why are you still on 1.8? There is no reason to stay on older versions. You should update to 1.12

    Although Mojang will try to phase it out, spigot needs to be backwards compatible, so data values will most likely stick around for 1.13.

    Spigot only develops for the newest update, so no, it will not change for older versions if they even make that change.
     
Thread Status:
Not open for further replies.

Share This Page