Cactus Hopper Plugin

Discussion in 'Plugin Development' started by SnipesGaming, Mar 27, 2017.

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

    SnipesGaming

    @Zombie_Striker
    @timtower
    Am I on the right track
    Code:
        @EventHandler
        public void onCactusBreak(BlockPhysicsEvent e){
            if (e.getBlock().getRelative(BlockFace.NORTH).getType()!=Material.AIR || e.getBlock().getRelative(BlockFace.SOUTH).getType()!=Material.AIR || e.getBlock().getRelative(BlockFace.EAST).getType()!=Material.AIR || e.getBlock().getRelative(BlockFace.WEST).getType()!=Material.AIR){}
            List<Block> getBlocks(Location loc, BlockFace blockFace, Integer depth){
            List<Block> block = new ArrayList();
            int BlockX = loc.getBlockX();
            int BlockY = loc.getBlockY();
            int BlockZ = loc.getBlockZ();
            for (int x = BlockX; x <= BlockX; x++)
                for (int y = BlockY; y <= BlockY; y++)
                    for (int z = BlockZ; z <= BlockZ; z++){
    Some Slight Changes

    Code:
        @EventHandler
        public void onCactusBreak(BlockPhysicsEvent e){
            if (e.getBlock().getRelative(BlockFace.NORTH).getType()!=Material.AIR || e.getBlock().getRelative(BlockFace.SOUTH).getType()!=Material.AIR || e.getBlock().getRelative(BlockFace.EAST).getType()!=Material.AIR || e.getBlock().getRelative(BlockFace.WEST).getType()!=Material.AIR){
            }
        }
           
            boolean getBlocks(Location loc, BlockFace blockFace, Integer depth){
                List<Block> block = new ArrayList();
            int BlockX = loc.getBlockX();
            int BlockY = loc.getBlockY();
            int BlockZ = loc.getBlockZ();
            for (int x = BlockX; x <= BlockX; x++)
                for (int y = BlockY; y <= BlockY; y++)
                    for (int z = BlockZ; z <= BlockZ; z++){
                    }
            return true;
     
    Last edited: Apr 14, 2017
  2. Offline

    Zombie_Striker

    @SnipesGaming
    Kind of. For the X and Z, the int should start at the X and Z minus one, and loop up to plus 1. Also, they y should be the first loop, before the X.
     
  3. Offline

    SnipesGaming

    when you mean loop up do you mean like ++ to loop back up to the top or what I'm confused
    @Zombie_Striker

    Made some changes tell me if it's correct or not what I need to change
    Code:
            List<Block> getBlocks(Location loc, BlockFace blockFace, Integer depth){
            int BlockX = loc.getBlockX();
            int BlockY = loc.getBlockY();
            int BlockZ = loc.getBlockZ();
            World world = loc.getWorld();
            for (int y = BlockY; y <= BlockY; y--){}
                for (int x = BlockX; x <= BlockX; x--){}
                    for (int z = BlockZ; z <= BlockZ; z++){}   
                    Block currentBlock = world.getBlockAt(BlockY, BlockX, BlockZ);
                    currentBlock.equals(Material.CACTUS);
     
    Last edited: Apr 24, 2017
  4. Offline

    Zombie_Striker

    @SnipesGaming
    Yes. That is correct, however, you still need to subtract one when you initialize x and z, and add one when checking the less than, so it should be:
    Code:
                for (int x = BlockX-1; x <= BlockX+1; x++){
                    for (int z = BlockZ-1; z <= BlockZ+1; z++){   
                    }
                 }
     
  5. Offline

    SnipesGaming

    @Zombie_Striker
    k made some changes should I make it for Y
    Code:
    for (int y = BlockY-1; y <= BlockY+1; y++){
    }
    Code:
        @EventHandler
        public void onCactusBreak(BlockPhysicsEvent e){
            if (e.getBlock().getRelative(BlockFace.NORTH).getType()!=Material.AIR || e.getBlock().getRelative(BlockFace.SOUTH).getType()!=Material.AIR || e.getBlock().getRelative(BlockFace.EAST).getType()!=Material.AIR || e.getBlock().getRelative(BlockFace.WEST).getType()!=Material.AIR){}
            }
            List<Block> getBlocks(Location loc, BlockFace blockFace, Integer depth){
            int BlockX = loc.getBlockX();
            int BlockY = loc.getBlockY();
            int BlockZ = loc.getBlockZ();
            World world = loc.getWorld();
            for (int y = BlockY; y <= BlockY; y++){}
                for (int x = BlockX-1; x <= BlockX+1; x++){}
                    for (int z = BlockZ-1; z <= BlockZ+1; z++){} 
                    Block currentBlock = world.getBlockAt(BlockY, BlockX, BlockZ);
                    currentBlock.equals(Material.CACTUS);
                    return null;
    some more changes @Zombie_Striker I need some help with whats next
    Code:
        @EventHandler
        public void onCactusBreak(BlockPhysicsEvent e){
            if (e.getBlock().getRelative(BlockFace.NORTH).getType()!=Material.AIR || e.getBlock().getRelative(BlockFace.SOUTH).getType()!=Material.AIR || e.getBlock().getRelative(BlockFace.EAST).getType()!=Material.AIR || e.getBlock().getRelative(BlockFace.WEST).getType()!=Material.AIR){}
            }
            List<Block> getBlocks(Location loc, BlockFace blockFace, Integer depth){
            int BlockX = loc.getBlockX();
            int BlockY = loc.getBlockY();
            int BlockZ = loc.getBlockZ();
            World world = loc.getWorld();
            for (int y = BlockY-1; y <= BlockY; y++){
                for (int x = BlockX-1; x <= BlockX+1; x++){
                    for (int z = BlockZ-1; z <= BlockZ+1; z++){  
                    Block currentBlock = world.getBlockAt(BlockY, BlockX, BlockZ);
                    currentBlock.equals(Material.CACTUS);
                    currentBlock.equals(Material.HOPPER);
                    return null;
                    }
                }
            }
            return null;
            }
    }
    @timtower What do I do next to add the cactus that just dropped to a hopper with a custom name on it should I create a new event or what
     
    Last edited: May 1, 2017
Thread Status:
Not open for further replies.

Share This Page