Can't set Buildable to true or does not work.

Discussion in 'Plugin Development' started by denno127, Jul 14, 2012.

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

    denno127

    Code:
    @EventHandler(priority = EventPriority.HIGHEST)
        public void onPlace(BlockCanBuildEvent event) {
            if (event.getBlock().getType() == Material.SUGAR_CANE_BLOCK)
            {
                event.setBuildable(true);
            }
        }
    It should work, but it does not. Also tried SUGER_CANE instead of SUGER_CANE_BLOCK
     
  2. Offline

    EnvisionRed

    I find that in situations like this it is best to compare getTypeId() to an int rather than getType() to a material. Look up the id for sugarcane and check that.
     
  3. I belive event.getBlock() returns the block you clicked on... I'm unsure, but event.getMaterial() specifically says that it's the material of the placed block, so you could try that... it will also lessen the code calls.

    Also, that code should allow sugar cane to be built *anywhere*, are you sure that's what you want ?
    That means, sugar cane on side of blocks, sugar cane in mid-air if rightclicking a torch, sugar cane on/under/side of any possible surface !


    When would that be ? I always compare against Material because it's easier to read and much easier to find items rather than memorizing IDs or always searching for them... and I never had a problem with that.
     
    denno127 likes this.
  4. Offline

    denno127

    Does not work, also I tried:
    Code:
    @EventHandler(priority = EventPriority.HIGHEST)
        public void onPlace(BlockCanBuildEvent event) {
            System.out.println("test1");
            if (event.getBlock().getTypeId() == 338 also tried 83)
            {
                System.out.println("test2");
                event.setBuildable(true);
            }
        }
    The server console only outputs test1, so it doesn't see Suger Cane is placed, maybe I need to use items?

    Digi , I am going to make it check for dirt or sand under it, but I will try event.getMaterial :)

    Oh thank you Digi that worked! Now I will make it check for dirt or sand under it :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  5. Well, you should print the value of getBlock().getType() and try serval stuff... clicking floor, clicking side of blocks, clicking ceiling, etc, and see what it gives you.
     
  6. Offline

    denno127

    I did:
    Code:
    @EventHandler(priority = EventPriority.HIGHEST)
        public void onPlace(BlockCanBuildEvent event) {
            System.out.println("test1");
            if (event.getMaterial() == Material.SUGAR_CANE_BLOCK)
            {
                if(event.getBlock().getRelative(BlockFace.DOWN).getType() == Material.DIRT | event.getBlock().getRelative(BlockFace.DOWN).getType() == Material.SAND)
                {
                    System.out.println("test2");
                    event.setBuildable(true);
                }
            }
        }
    That works, now the only thing left to do is the problem when you update it it breaks...
     
  7. Offline

    denno127

Thread Status:
Not open for further replies.

Share This Page