1.15.2 Beehive API

Discussion in 'Spigot Plugin Development' started by Donkelyn, Aug 23, 2020.

  1. Yo I'm tryna figure out bee api. What I wanna do is just detect when the honey level goes up by 1 and then set it to the max honey level. I honestly have no clue how to do this and can't find anything else online. Any help is appreciated thank you!

    Code (Text):
    public class beeKeeper implements Listener {

        @EventHandler
        public void bees(EntityEnterBlockEvent e) {
            Bukkit.getServer().broadcastMessage("1");
            Entity ent = e.getEntity();
            if (ent.getType() != EntityType.BEE) {
                Bukkit.getServer().broadcastMessage("2");
                return;
            }
            Bukkit.getServer().broadcastMessage("3");
           
            Block b = e.getBlock();
            if (b.getType() != Material.BEEHIVE) {
                Bukkit.getServer().broadcastMessage("4");
                return;
            }
            Bukkit.getServer().broadcastMessage("5");
            Beehive h = (Beehive) b;
            honeyCheck(h);
        }

        private void honeyCheck(Beehive h) {
            new BukkitRunnable() {
                @Override
                public void run() {
                    Bukkit.getServer().broadcastMessage("6");
                    int honey = h.getHoneyLevel();
                    if (honey > 0) {
                        Bukkit.getServer().broadcastMessage("7");
                        h.setHoneyLevel(5);
                        Bukkit.getServer().broadcastMessage("8");
                    }
                   
                }
                }.runTaskLater(main.plugin, 100);
            }
        }
    This is my current code and my output is 1, 3, 5 and then I get an error in the console. Is there any issues you can see that will fix the code?
     
    #1 Donkelyn, Aug 23, 2020
    Last edited: Aug 24, 2020
  2. Listen to EntityEnterBlockEvent and check for the honey-level of the bee-hive. You'll probably have to delay checking for the amount since I believe the honey-level will only be set after the bee enters the hive
     
  3. What would be the way I get the honey level as there isn't a method for that.

    NVM i had the wrong beehive imported thank you!
     
  4. Instead of delay, make a simple addition with the entity's honey and the hive's one.
     
    • Agree Agree x 1
  5. The issue I currently have is I cannot convert the e.getBlock into a Beehive object
     
  6. That's because Beehive extends BlockData, not Block. Also, because you're going to run into this later, once you've modified the Beehive you'll have to set the block's data - changes don't immediately take effect.
     
    • Agree Agree x 1