2015-08-29 14:33:25 +02:00
|
|
|
|
/*
|
|
|
|
|
* This file ("CraftEvent.java") is part of the Actually Additions Mod for Minecraft.
|
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
|
* under the Actually Additions License to be found at
|
|
|
|
|
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
|
*
|
|
|
|
|
* <EFBFBD> 2015 Ellpeck
|
|
|
|
|
*/
|
|
|
|
|
|
2015-03-07 12:51:28 +01:00
|
|
|
|
package ellpeck.actuallyadditions.event;
|
2015-03-07 02:23:31 +01:00
|
|
|
|
|
|
|
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
|
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
2015-04-19 01:50:02 +02:00
|
|
|
|
import ellpeck.actuallyadditions.achievement.InitAchievements;
|
|
|
|
|
import ellpeck.actuallyadditions.achievement.TheAchievements;
|
2015-09-20 20:44:20 +02:00
|
|
|
|
import ellpeck.actuallyadditions.config.values.ConfigBoolValues;
|
2015-08-31 03:58:35 +02:00
|
|
|
|
import ellpeck.actuallyadditions.items.InitItems;
|
|
|
|
|
import ellpeck.actuallyadditions.util.INameableItem;
|
2015-09-30 06:56:33 +02:00
|
|
|
|
import ellpeck.actuallyadditions.util.playerdata.PersistentServerData;
|
2015-08-31 03:58:35 +02:00
|
|
|
|
import net.minecraft.block.Block;
|
2015-09-27 15:31:43 +02:00
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
2015-07-01 21:32:48 +02:00
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-04-19 01:50:02 +02:00
|
|
|
|
import net.minecraft.item.ItemStack;
|
2015-03-07 02:23:31 +01:00
|
|
|
|
|
|
|
|
|
public class CraftEvent{
|
2015-03-29 15:29:05 +02:00
|
|
|
|
|
2015-03-07 02:23:31 +01:00
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void onCraftedEvent(PlayerEvent.ItemCraftedEvent event){
|
2015-07-01 21:32:48 +02:00
|
|
|
|
checkAchievements(event.crafting, event.player, InitAchievements.CRAFTING_ACH);
|
2015-08-31 03:58:35 +02:00
|
|
|
|
|
2015-09-20 20:44:20 +02:00
|
|
|
|
if(ConfigBoolValues.GIVE_BOOKLET_ON_FIRST_CRAFT.isEnabled()){
|
|
|
|
|
if(!event.player.worldObj.isRemote && event.crafting.getItem() != InitItems.itemLexicon && (event.crafting.getItem() instanceof INameableItem || Block.getBlockFromItem(event.crafting.getItem()) instanceof INameableItem)){
|
2015-09-30 06:56:33 +02:00
|
|
|
|
PersistentServerData data = PersistentServerData.get(event.player);
|
2015-09-27 15:34:22 +02:00
|
|
|
|
if(data != null && !data.bookGottenAlready){
|
2015-09-27 15:31:43 +02:00
|
|
|
|
data.bookGottenAlready = true;
|
|
|
|
|
|
|
|
|
|
EntityItem entityItem = new EntityItem(event.player.worldObj, event.player.posX, event.player.posY, event.player.posZ, new ItemStack(InitItems.itemLexicon));
|
|
|
|
|
entityItem.delayBeforeCanPickup = 0;
|
|
|
|
|
event.player.worldObj.spawnEntityInWorld(entityItem);
|
2015-09-20 20:44:20 +02:00
|
|
|
|
}
|
2015-08-31 03:58:35 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-04-19 01:50:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-01 21:32:48 +02:00
|
|
|
|
public static void checkAchievements(ItemStack gotten, EntityPlayer player, int type){
|
2015-04-19 01:50:02 +02:00
|
|
|
|
for(int i = 0; i < TheAchievements.values().length; i++){
|
|
|
|
|
TheAchievements ach = TheAchievements.values()[i];
|
|
|
|
|
if(ach.type == type){
|
2015-07-10 21:19:52 +02:00
|
|
|
|
if(gotten != null && ach.ach.theItemStack != null && gotten.getItem() == ach.ach.theItemStack.getItem()){
|
2015-04-19 01:50:02 +02:00
|
|
|
|
if(gotten.getItemDamage() == ach.ach.theItemStack.getItemDamage()){
|
2015-07-01 21:32:48 +02:00
|
|
|
|
player.addStat(ach.ach, 1);
|
2015-04-19 01:50:02 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-07 02:23:31 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|