Advertisement
Gamebuster

AttachCapabilitiesExample.class

Jul 11th, 2016
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. public class AttatchCapabilities {
  2.  
  3.     public static final ArrayList<Class<?>> SALTYCLASSES = new ArrayList<Class<?>>();
  4.     public static final List<Class<?>> CLASSESTOIGNORE = new ArrayList<Class<?>>();
  5.  
  6.     /* Assume the following code is ran during postInit
  7.         for (ItemStack i : OreDictionary.getOres("salt")) {
  8.             SALTYCLASSES.add(i.getClass());
  9.             System.out.println(i.getItem().getClass().getName() + " is salt");
  10.         }
  11.         for (ItemStack i : OreDictionary.getOres("dustSalt")) {
  12.             SALTYCLASSES.add(i.getClass());
  13.             System.out.println(i.getItem().getClass().getName() + " is dustSalt");
  14.         }
  15.         for (ItemStack i : OreDictionary.getOres("itemSalt")) {
  16.             SALTYCLASSES.add(i.getClass());
  17.             System.out.println(i.getItem().getClass().getName() + " is itemSalt");
  18.         }
  19.         for (ItemStack i : OreDictionary.getOres("foodSalt")) {
  20.             SALTYCLASSES.add(i.getClass());
  21.             System.out.println(i.getItem().getClass().getName() + " is foodSalt");
  22.         }
  23.     */
  24.  
  25.  
  26.  
  27.     @SubscribeEvent
  28.     public void onItemCreate(AttachCapabilitiesEvent.Item event) {
  29.         if (event.getItemStack().hasCapability(SaltExampleCapability, null){
  30.             return; //no need to add a capability to something that already has it
  31.         }
  32.         for (Class ig : CLASSESTOIGNORE) {
  33.             if (ig.isInstance(event.getItem())) {
  34.                 return; //the class is ignored so the capability isn't added
  35.             }
  36.         }
  37.         for (Class c : Main.SALTYCLASSES) {
  38.             if (c.isInstance(event.getItem())) {
  39.                 if (!event.getItemStack().hasCapability(SaltExampleCapability, null)) {
  40.                     //add the capability
  41.                     event.addCapability(Bla bla bla this is an example); //add SaltExampleCapability
  42.                 }
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement