2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("PlayerObtainEvents.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-2016 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.event;
|
2015-03-07 02:23:31 +01:00
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.achievement.InitAchievements;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.achievement.TheAchievements;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
|
2016-06-15 16:43:59 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.data.PlayerData;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.items.InitItems;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
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-10-22 22:18:33 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
|
2015-03-07 02:23:31 +01:00
|
|
|
|
2016-01-11 22:02:41 +01:00
|
|
|
import java.util.Locale;
|
|
|
|
|
2015-11-23 19:17:17 +01:00
|
|
|
public class PlayerObtainEvents{
|
2015-03-29 15:29:05 +02:00
|
|
|
|
2016-02-01 20:39:11 +01:00
|
|
|
public static void checkAchievements(ItemStack gotten, EntityPlayer player, InitAchievements.Type type){
|
2016-05-24 18:31:09 +02:00
|
|
|
for(TheAchievements ach : TheAchievements.values()){
|
2016-02-01 20:39:11 +01:00
|
|
|
if(ach.type == type){
|
|
|
|
if(gotten != null && ach.ach.theItemStack != null && gotten.getItem() == ach.ach.theItemStack.getItem()){
|
|
|
|
if(gotten.getItemDamage() == ach.ach.theItemStack.getItemDamage()){
|
|
|
|
player.addStat(ach.ach, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-07 02:23:31 +01:00
|
|
|
@SubscribeEvent
|
|
|
|
public void onCraftedEvent(PlayerEvent.ItemCraftedEvent event){
|
2015-12-09 15:47:57 +01:00
|
|
|
checkAchievements(event.crafting, event.player, InitAchievements.Type.CRAFTING);
|
2015-08-31 03:58:35 +02:00
|
|
|
|
2015-09-20 20:44:20 +02:00
|
|
|
if(ConfigBoolValues.GIVE_BOOKLET_ON_FIRST_CRAFT.isEnabled()){
|
2016-01-11 21:56:01 +01:00
|
|
|
if(!event.player.worldObj.isRemote && event.crafting != null && event.crafting.getItem() != null && event.crafting.getItem() != InitItems.itemBooklet){
|
2015-09-27 15:31:43 +02:00
|
|
|
|
2016-04-20 21:39:03 +02:00
|
|
|
String name = event.crafting.getItem().getRegistryName().toString();
|
|
|
|
if(name != null && name.toLowerCase(Locale.ROOT).contains(ModUtil.MOD_ID)){
|
2016-06-15 17:15:26 +02:00
|
|
|
PlayerData.PlayerSave compound = PlayerData.getDataFromPlayer(event.player);
|
|
|
|
if(compound != null && !compound.theCompound.getBoolean("BookGottenAlready")){
|
|
|
|
compound.theCompound.setBoolean("BookGottenAlready", true);
|
2015-12-03 20:15:07 +01:00
|
|
|
|
|
|
|
EntityItem entityItem = new EntityItem(event.player.worldObj, event.player.posX, event.player.posY, event.player.posZ, new ItemStack(InitItems.itemBooklet));
|
2016-01-08 08:10:55 +01:00
|
|
|
entityItem.setPickupDelay(0);
|
2015-12-03 20:15:07 +01:00
|
|
|
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-10-03 10:19:40 +02:00
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
@SubscribeEvent
|
|
|
|
public void onSmeltedEvent(PlayerEvent.ItemSmeltedEvent event){
|
2015-12-09 15:47:57 +01:00
|
|
|
checkAchievements(event.smelting, event.player, InitAchievements.Type.SMELTING);
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onPickupEvent(PlayerEvent.ItemPickupEvent event){
|
2015-12-09 15:47:57 +01:00
|
|
|
checkAchievements(event.pickedUp.getEntityItem(), event.player, InitAchievements.Type.PICK_UP);
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
2015-03-07 02:23:31 +01:00
|
|
|
}
|