faizaand
4/7/2016 - 12:12 AM

Chests

Chests


CraftChest chest = (CraftChest) block.getState(); //block has to be a chest
       
try
{
    Field inventoryField = chest.getClass().getDeclaredField("chest"); //This gets the CraftChest variable 'chest' which is the TileEntityChest that is stored within it
    inventoryField.setAccessible(true); //Allows you to access that field since it's declared as private
    TileEntityChest teChest = ((TileEntityChest) inventoryField.get(chest)); //obtains the field and casts it to a TileEntityChest
    teChest.a("Name Goes Here"); //The a(String) method sets the title of the chest
}
catch (Exception e) //This has to be here as the getDeclaredField(String) throws an exception if the input doesn't exist in the given class
{
     e.printStackTrace();
}