@SubscribeEvent public void onPlayerOpenContainer(PlayerOpenContainerEvent event) { if (event.entityPlayer instanceof EntityPlayerMP) { if (event.entityPlayer.openContainer instanceof net.minecraft.inventory.ContainerWorkbench && event.entityPlayer.openContainer.inventoryItemStacks.get(0) != null) { EntityPlayerMP playerMP = (EntityPlayerMP) event.entityPlayer; PlayerData player = PlayerStore.getInstance().getPlayer(playerMP.getUniqueID().toString()); Item item = (Item) ((ItemStack) event.entityPlayer.openContainer.inventoryItemStacks.get(0)).getItem(); ArrayList<ItemPerk> entitylist = PerkStore.getPerksForItem(item.getUnlocalizedName()); boolean requiresPerk = false; if (entitylist != null) { requiresPerk = true; } for (ItemSkill skill : SkillStore.getInstance().getItemSkill()) { ArrayList<ItemXP> temp = skill.getExp(); for (int i = 0; i < temp.size(); i++) { Item compareItem = ((ItemXP) temp.get(i)).getItem(); if (item.equals(compareItem)) { if (requiresPerk) { if (PlayerHandler.hasPerk(player, entitylist)) { } else { PlayerHandler.taskFail((EntityPlayer) playerMP); event.entityPlayer.closeScreen(); break; } } } } } } } }
@SubscribeEvent // Assumed that crafting wasn't blocked public void onItemCraftedEvent(ItemCraftedEvent event) { if (event.player instanceof EntityPlayerMP) { EntityPlayerMP playerMP = (EntityPlayerMP) event.player; PlayerData player = PlayerStore.getInstance().getPlayer(playerMP.getUniqueID().toString()); Item item = (Item) ((ItemStack) event.player.openContainer.inventoryItemStacks.get(0)).getItem(); ArrayList<ItemPerk> entitylist = PerkStore.getPerksForItem(item.getUnlocalizedName()); boolean requiresPerk = false; if (entitylist != null) { requiresPerk = true; } for (ItemSkill skill : SkillStore.getInstance().getItemSkill()) { ArrayList<ItemXP> temp = skill.getExp(); for (int i = 0; i < temp.size(); i++) { Item compareItem = ((ItemXP) temp.get(i)).getItem(); if (item.equals(compareItem)) { if (requiresPerk) { if (PlayerHandler.hasPerk(player, entitylist)) { // if (event.entity.isDead){ PlayerHandler.awardXP(player, skill.name, temp.get(i).getXp(), playerMP); // } } // else // { // PlayerHandler.taskFail((EntityPlayer) playerMP); // event.player.closeScreen(); // } } else { // if (event.entity.isDead){ PlayerHandler.awardXP(player, skill.name, temp.get(i).getXp(), playerMP); // } } } } } } }