Get complete block (Doors or chests)

Discussion in 'Spigot Plugin Development' started by relampagorojo93, Jun 25, 2018.

  1. I'm trying to recreate an old plugin, but plugins like lwc or lockette use the same system and I'm trying to find the code but I don't find it. I want to ask, which method do you use to check when a block is part of another block? Because I'm trying to find that common thing that link them two but I didn't find it
     
  2. My problem is that in the Door case, I don't know which method can be used to get the top block, cause I need it to make the verifies if they click that block.
    Edit: Nothing, get it, the istophalf is a checker I see, I'll use it, ty,
     
    #3 relampagorojo93, Jun 25, 2018
    Last edited: Jun 25, 2018
  3. Code (Text):
      public boolean isDoubleChest(Block block)
      {
        BlockState chestState = block.getState();
        if ((chestState instanceof Chest))
        {
          Chest chest = (Chest)chestState;
          if ((chest.getInventory() instanceof DoubleChestInventory)) {
            return true;
          }
        }
        return false;
      }
    I have this code if you want for a double chest. You could clean it up more but it does what need.
     
  4. I have it already, the only thing I need to do is get the two blocks to use the other instead of the clicked one to do the checkings.
     
  5. Yeah i wanted the same thing some time ago, i am not sure if there is a better way but the one is that you have to check where the player is looking and get the block next of the chest location.
     
  6. I did that:

    Code (Java):

                        DoubleChest doubleChest = (DoubleChest) inventory.getHolder();
                        for (BlockFace face:Arrays.asList(BlockFace.EAST, BlockFace.SOUTH, BlockFace.NORTH, BlockFace.WEST)) {
                            if (b.getRelative(face).getState() instanceof Chest) {
                                Chest ch = (Chest) b.getRelative(face).getState();
                                if (ch.getInventory() instanceof DoubleChestInventory) {
                                    DoubleChest dc = (DoubleChest) ch.getInventory().getHolder();
                                    if (dc.getLocation().toString().equals(doubleChest.getLocation().toString())) {
                                        b = b.getRelative(face);
                                        break;
                                    }
                                }
                            }
                        }
     
    So, it's a little bit weird but it's only cause I was testing it, and seems that it worked. Seems like the DoubleChest location is the middle of the two blocks