I'm sure this is simple but I'm just missing a key point. From the PlayerInteractEvent I have a .getClickedBlock(). How do I then turn this into a chest which can be manipulated? I attempted to check if e.getClickedBlock().getState() instanceof Chest and then I casted it to a chest. It seems I get an error. (Yes, I have null checked it etc.) Essentially I'm asking how to turn a e.getClickedBlock() into an Inventory that can be manipulated.
I'm not at a convenient place to provide one but I assumed somebody might know how to go from a regular Block to an Inventory efficiently.
Just going to write this down step by step. Check if the getClickedBlock() returns null if so, return Check if getClickedBlock().getState() is instanceof Chest Cast getClickedBlock.getState() to a Chest. Now you can do whatever you please with the chest.
Or instead you could check for Code (Text): if(e.getClickedBlock().getType() == Material.CHEST || e.getClickedBlock().getType() == Material.DOUBLE_CHEST){ //Cast object to chest or double chest }