Get visible blocks from location

Discussion in 'Plugin Development' started by j_selby, Aug 26, 2012.

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

    j_selby

    Hey guys,
    For my companion plugin, I am trying to implement a mining mode, where the companion goes to mine. Using the below code, it will just teleport through blocks, and mine a block that it shouldn't be able to reach.
    Is there a way to get the blocks that the NPC would be able to reach, without no-clipping etc?

    Code:
    Code:
        public static Byte[] notSolidBlocks = {0, 30, 6, 37, 38, 39, 40, 106, 65, 66, 27, 28, 70, 72, 50, 76, 77, 69, (byte) 323, (byte) 331, 86, 8, 9, 10, 11, 31, 78, 80};
        public Block getNearbyBlock(Location location, int radius, String playerName, ch.spacebase.npccreatures.npcs.entity.NPC companion){
            Block currentBlock = null;
            List<Block> blocksVisible = companion.getLineOfSight((HashSet<Byte>) arrayToByte(notSolidBlocks), 20);
            Iterator<Block> blocksIterator = blocksVisible.iterator();
            companion.
            while(blocksIterator.hasNext()){
                currentBlock = blocksIterator.next();
                if (currentBlock.getType() == Material.STONE || currentBlock.getType() == Material.DIRT){
                    System.out.println("Found a good block");
                    return currentBlock;
                }
                   
            }
            System.out.println("No block is not visible");
            return null;
        }
        public Set<Byte> arrayToByte(Byte[] numbers){
            List<Byte> list = Arrays.asList(numbers);
            Set<Byte> set = new HashSet<Byte>(list);
     
            for (Iterator<Byte> iterator = set.iterator(); iterator.hasNext();) {
              @SuppressWarnings("unused")
              Object o = iterator.next();
            }
            return set;
        }
    Thanks,
    j_selby
     
  2. Offline

    VoidWhisperer

    Are you talking about all around the player, or just in their line of sight? However, this seems like a very interesting idea. What you'd probably want to do is to check to make sure there is air next to the block and that the space is connected to an area where the player is, to keep it from noclipping into caves.
     
  3. Offline

    j_selby

    Hopefully just in their line of sight. Couldn't I just make it like the block looking at code, and just loop that over the NPC's line of sight.
     
Thread Status:
Not open for further replies.

Share This Page