|
@@ -1,79 +1,73 @@
|
|
|
package me.km.capabilities;
|
|
|
|
|
|
import java.util.List;
|
|
|
-import me.km.KajetansMod;
|
|
|
import me.km.items.ItemGun;
|
|
|
import me.km.items.ItemKey;
|
|
|
import net.minecraft.item.Item;
|
|
|
import net.minecraft.item.ItemArmor;
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
-import net.minecraft.util.ResourceLocation;
|
|
|
+import net.minecraft.nbt.NBTTagCompound;
|
|
|
import net.minecraft.util.text.TextFormatting;
|
|
|
-import net.minecraftforge.common.capabilities.CapabilityManager;
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
|
-import net.minecraftforge.event.AttachCapabilitiesEvent;
|
|
|
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
|
|
public class CapabilitiesEvents
|
|
|
{
|
|
|
- public static final ResourceLocation DEFENSE_CAP = new ResourceLocation(KajetansMod.MODID, "defense");
|
|
|
- public static final ResourceLocation CHEST_KEY_CAP = new ResourceLocation(KajetansMod.MODID, "chestkey");
|
|
|
- public static final ResourceLocation GUN_LOAD_CAP = new ResourceLocation(KajetansMod.MODID, "gunload");
|
|
|
+ //public static final ResourceLocation DEFENSE_CAP = new ResourceLocation(KajetansMod.MODID, "defense");
|
|
|
+ //public static final ResourceLocation CHEST_KEY_CAP = new ResourceLocation(KajetansMod.MODID, "chestkey");
|
|
|
+ //public static final ResourceLocation GUN_LOAD_CAP = new ResourceLocation(KajetansMod.MODID, "gunload");
|
|
|
|
|
|
public static void init()
|
|
|
{
|
|
|
- CapabilityManager.INSTANCE.register(IDefense.class, new DefenseStorage(), ItemDefenseStats.class);
|
|
|
- CapabilityManager.INSTANCE.register(IChestKey.class, new ChestKeyStorage(), ItemChestKey.class);
|
|
|
- CapabilityManager.INSTANCE.register(IGunLoad.class, new GunLoadStorage(), ItemGunLoad.class);
|
|
|
+ //CapabilityManager.INSTANCE.register(IDefense.class, new DefenseStorage(), ItemDefenseStats.class);
|
|
|
+ //CapabilityManager.INSTANCE.register(IChestKey.class, new ChestKeyStorage(), ItemChestKey.class);
|
|
|
+ //CapabilityManager.INSTANCE.register(IGunLoad.class, new GunLoadStorage(), ItemGunLoad.class);
|
|
|
}
|
|
|
|
|
|
- @SubscribeEvent
|
|
|
- public void attachDefenseData(AttachCapabilitiesEvent<ItemStack> e)
|
|
|
+ /*@SubscribeEvent
|
|
|
+ public void attachData(AttachCapabilitiesEvent<ItemStack> e)
|
|
|
{
|
|
|
- Item item = e.getObject().getItem();
|
|
|
- if(item instanceof ItemArmor)
|
|
|
+ if(e.getObject().getItem() instanceof ItemSword)
|
|
|
{
|
|
|
- e.addCapability(DEFENSE_CAP, new DefenseProvider());
|
|
|
+ ItemStack stack = e.getObject();
|
|
|
+ System.out.println("DICK");
|
|
|
+ ItemStackUtils.addAttribute(stack, ItemStackUtils.Attribute.ATTACK_SPEED,
|
|
|
+ EntityEquipmentSlot.MAINHAND, -2.7d, ItemStackUtils.Operation.ADD);
|
|
|
}
|
|
|
- else if(item.getClass() == ItemKey.class)
|
|
|
- {
|
|
|
- e.addCapability(CHEST_KEY_CAP, new ChestKeyProvider());
|
|
|
- }
|
|
|
- else if(item.getClass() == ItemGun.class)
|
|
|
- {
|
|
|
- e.addCapability(GUN_LOAD_CAP, new GunLoadProvider());
|
|
|
- }
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
@SubscribeEvent
|
|
|
public void showingTooltip(ItemTooltipEvent e)
|
|
|
{
|
|
|
ItemStack stack = e.getItemStack();
|
|
|
- if(stack.hasCapability(DefenseProvider.DEFENSE_CAP, null))
|
|
|
+ Item item = stack.getItem();
|
|
|
+ if(item instanceof ItemArmor)
|
|
|
{
|
|
|
- IDefense defense = stack.getCapability(DefenseProvider.DEFENSE_CAP, null);
|
|
|
- int magic = defense.getMagicDefense();
|
|
|
- if(magic != 0)
|
|
|
+ NBTTagCompound com = stack.getTagCompound();
|
|
|
+ if(com != null && com.hasKey("magic"))
|
|
|
{
|
|
|
- List<String> list = e.getToolTip();
|
|
|
- String s = TextFormatting.BLUE + " +";
|
|
|
- for(int i = 0; i < list.size(); i++)
|
|
|
+ int magic = com.getInteger("magic");
|
|
|
+ if(magic != 0)
|
|
|
{
|
|
|
- if(list.get(i).startsWith(s))
|
|
|
+ List<String> list = e.getToolTip();
|
|
|
+ String s = TextFormatting.BLUE + " +";
|
|
|
+ for(int i = 0; i < list.size(); i++)
|
|
|
{
|
|
|
- list.add(i, TextFormatting.BLUE + " +" + magic + " Magic Armor");
|
|
|
- break;
|
|
|
+ if(list.get(i).startsWith(s))
|
|
|
+ {
|
|
|
+ list.add(i, TextFormatting.BLUE + " +" + magic + " Magic Armor");
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- else if(stack.hasCapability(GunLoadProvider.GUN_LOAD_CAP, null))
|
|
|
+ else if(item.getClass() == ItemGun.class)
|
|
|
{
|
|
|
- IGunLoad gunLoad = stack.getCapability(GunLoadProvider.GUN_LOAD_CAP, null);
|
|
|
- int load = gunLoad.getCurrentLoad();
|
|
|
+ int load = ItemGun.getLoad(stack);
|
|
|
if(load >= 0)
|
|
|
{
|
|
|
List<String> list = e.getToolTip();
|
|
@@ -87,11 +81,11 @@ public class CapabilitiesEvents
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- else if(stack.hasCapability(ChestKeyProvider.CHEST_KEY_CAP, null))
|
|
|
+ else if(item.getClass() == ItemKey.class)
|
|
|
{
|
|
|
- IChestKey key = stack.getCapability(ChestKeyProvider.CHEST_KEY_CAP, null);
|
|
|
+ String s = ItemKey.getKey(stack);
|
|
|
List<String> list = e.getToolTip();
|
|
|
- if(key.getKey().isEmpty())
|
|
|
+ if(s.isEmpty())
|
|
|
{
|
|
|
list.set(0, TextFormatting.RED + list.get(0));
|
|
|
}
|