Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AttatchCapabilities {
- public static final ArrayList<Class<?>> SALTYCLASSES = new ArrayList<Class<?>>();
- public static final List<Class<?>> CLASSESTOIGNORE = new ArrayList<Class<?>>();
- /* Assume the following code is ran during postInit
- for (ItemStack i : OreDictionary.getOres("salt")) {
- SALTYCLASSES.add(i.getClass());
- System.out.println(i.getItem().getClass().getName() + " is salt");
- }
- for (ItemStack i : OreDictionary.getOres("dustSalt")) {
- SALTYCLASSES.add(i.getClass());
- System.out.println(i.getItem().getClass().getName() + " is dustSalt");
- }
- for (ItemStack i : OreDictionary.getOres("itemSalt")) {
- SALTYCLASSES.add(i.getClass());
- System.out.println(i.getItem().getClass().getName() + " is itemSalt");
- }
- for (ItemStack i : OreDictionary.getOres("foodSalt")) {
- SALTYCLASSES.add(i.getClass());
- System.out.println(i.getItem().getClass().getName() + " is foodSalt");
- }
- */
- @SubscribeEvent
- public void onItemCreate(AttachCapabilitiesEvent.Item event) {
- if (event.getItemStack().hasCapability(SaltExampleCapability, null){
- return; //no need to add a capability to something that already has it
- }
- for (Class ig : CLASSESTOIGNORE) {
- if (ig.isInstance(event.getItem())) {
- return; //the class is ignored so the capability isn't added
- }
- }
- for (Class c : Main.SALTYCLASSES) {
- if (c.isInstance(event.getItem())) {
- if (!event.getItemStack().hasCapability(SaltExampleCapability, null)) {
- //add the capability
- event.addCapability(Bla bla bla this is an example); //add SaltExampleCapability
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement