Skip to content

Instantly share code, notes, and snippets.

@fynntimes
Last active April 7, 2016 00:18
Show Gist options
  • Save fynntimes/5d84d0aa962d2f6097a133da2e0e478e to your computer and use it in GitHub Desktop.
Save fynntimes/5d84d0aa962d2f6097a133da2e0e478e to your computer and use it in GitHub Desktop.
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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment