ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/achievement/TheAchievements.java

141 lines
7.3 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("TheAchievements.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.achievement;
2015-04-19 01:50:02 +02:00
2016-06-17 23:37:01 +02:00
import de.ellpeck.actuallyadditions.mod.achievement.InitAchievements.Type;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
import de.ellpeck.actuallyadditions.mod.items.InitItems;
2016-08-05 04:49:04 +02:00
import de.ellpeck.actuallyadditions.mod.items.metalists.TheCrystals;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
2016-08-05 04:49:04 +02:00
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
2015-04-19 01:50:02 +02:00
import net.minecraft.item.ItemStack;
import net.minecraft.stats.Achievement;
2016-08-05 04:49:04 +02:00
import net.minecraft.stats.StatisticsManager;
import net.minecraft.util.JsonSerializableSet;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
2015-04-19 01:50:02 +02:00
public enum TheAchievements{
2016-06-17 23:37:01 +02:00
OPEN_BOOKLET("openBooklet", 0, 0, new ItemStack(InitItems.itemBooklet), null, Type.MISC),
2016-08-05 04:49:04 +02:00
NAME_SMILEY_CLOUD("nameSmileyCloud", 4, 3, new ItemStack(InitBlocks.blockSmileyCloud), null, Type.MISC, true, 0),
2016-06-17 23:37:01 +02:00
OPEN_TREASURE_CHEST("openTreasureChest", 1, -3, new ItemStack(InitBlocks.blockTreasureChest), OPEN_BOOKLET, Type.MISC),
2015-12-09 15:47:57 +01:00
CRAFT_COAL_GEN("craftCoalGen", -2, 0, new ItemStack(InitBlocks.blockCoalGenerator), OPEN_BOOKLET),
CRAFT_LEAF_GEN("craftLeafGen", -3, -2, new ItemStack(InitBlocks.blockLeafGenerator), CRAFT_COAL_GEN),
CRAFT_RECONSTRUCTOR("craftReconstructor", -5, 0, new ItemStack(InitBlocks.blockAtomicReconstructor), CRAFT_COAL_GEN),
2016-08-05 04:49:04 +02:00
MAKE_FIRST_CRYSTAL("makeCrystal", -4, 2, new ItemStack(InitItems.itemCrystal, 1, TheCrystals.EMERALD.ordinal()), CRAFT_RECONSTRUCTOR, Type.PICK_UP, new ItemStack(InitItems.itemCrystal, 1, Util.WILDCARD), new ItemStack(InitBlocks.blockCrystal, 1, Util.WILDCARD)),
CRAFT_EMPOWERER("craftEmpowerer", -4, 4, new ItemStack(InitBlocks.blockEmpowerer), MAKE_FIRST_CRYSTAL),
2015-12-09 15:47:57 +01:00
CRAFT_PHANTOMFACE("craftPhantomface", 2, 0, new ItemStack(InitBlocks.blockPhantomface), OPEN_BOOKLET),
CRAFT_LIQUIFACE("craftLiquiface", 2, 2, new ItemStack(InitBlocks.blockPhantomLiquiface), CRAFT_PHANTOMFACE),
2016-08-05 04:49:04 +02:00
CRAFT_ENERGYFACE("craftEnergyface", 4, -1, new ItemStack(InitBlocks.blockPhantomEnergyface), CRAFT_PHANTOMFACE),
2015-12-09 15:47:57 +01:00
CRAFT_LASER_RELAY("craftLaserRelay", -7, -2, new ItemStack(InitBlocks.blockLaserRelay), CRAFT_RECONSTRUCTOR),
CRAFT_LASER_RELAY_ITEM("craftLaserRelayItem", -9, -2, new ItemStack(InitBlocks.blockLaserRelayItem), CRAFT_LASER_RELAY, Type.PICK_UP),
2016-08-05 04:49:04 +02:00
CRAFT_ITEM_INTERFACE("craftItemInterface", -11, -3, new ItemStack(InitBlocks.blockItemViewer), CRAFT_LASER_RELAY_ITEM),
CRAFT_LASER_RELAY_ADVANCED("craftLaserRelayAdvanced", -7, -4, new ItemStack(InitBlocks.blockLaserRelayAdvanced), CRAFT_LASER_RELAY),
CRAFT_LASER_RELAY_EXTREME("craftLaserRelayExtreme", -9, -4, new ItemStack(InitBlocks.blockLaserRelayExtreme), CRAFT_LASER_RELAY_ADVANCED),
2015-12-09 15:47:57 +01:00
CRAFT_CRUSHER("craftCrusher", -8, 0, new ItemStack(InitBlocks.blockGrinder), CRAFT_RECONSTRUCTOR),
2016-08-05 04:49:04 +02:00
CRAFT_DOUBLE_CRUSHER("craftDoubleCrusher", -10, 1, new ItemStack(InitBlocks.blockGrinderDouble), CRAFT_CRUSHER),
PICK_UP_COFFEE("pickUpCoffee", -2, 2, new ItemStack(InitItems.itemCoffeeBean), CRAFT_COAL_GEN, Type.PICK_UP),
CRAFT_COFFEE_MACHINE("craftCoffeeMachine", -1, 3, new ItemStack(InitBlocks.blockCoffeeMachine), PICK_UP_COFFEE),
CRAFT_FIREWORK_BOX("craftFireworkBox", -4, -5, new ItemStack(InitBlocks.blockFireworkBox), null, Type.CRAFTING, true, 0),
GET_UNPROBED("getUnProbed", -7, 3, new ItemStack(InitItems.itemPlayerProbe), null, Type.MISC, true, 0),
2016-08-05 04:49:04 +02:00
GET_CRYSTALS_MILESTONE("getCrystalsMilestone", 6, -3, new ItemStack(InitBlocks.blockCrystal, 1, TheCrystals.DIAMOND.ordinal()), null, Type.PICK_UP, true, 200, new ItemStack(InitItems.itemCrystal, 1, Util.WILDCARD), new ItemStack(InitBlocks.blockCrystal, 1, Util.WILDCARD)),
OPEN_BOOKLET_MILESTONE("openBookletMilestone", 6, -1, new ItemStack(InitItems.itemBooklet), null, Type.MISC, true, 50);
2015-04-19 01:50:02 +02:00
2016-06-17 23:37:01 +02:00
public final Achievement chieve;
public final Type type;
2016-08-05 04:49:04 +02:00
public final int progressToReach;
public List<ItemStack> itemsToBeGotten;
2015-04-19 01:50:02 +02:00
2016-08-05 04:49:04 +02:00
TheAchievements(String name, int x, int y, ItemStack displayStack, TheAchievements hasToHaveBefore, ItemStack... specialItemsToBeGotten){
this(name, x, y, displayStack, hasToHaveBefore, Type.CRAFTING, false, 0, specialItemsToBeGotten);
2015-10-03 10:19:40 +02:00
}
2016-08-05 04:49:04 +02:00
TheAchievements(String name, int x, int y, ItemStack displayStack, TheAchievements hasToHaveBefore, Type type, boolean special, int progressToReach, ItemStack... specialItemsToBeGotten){
this.type = type;
this.progressToReach = progressToReach;
2016-06-17 23:37:01 +02:00
this.chieve = new Achievement("achievement."+ModUtil.MOD_ID+"."+name, ModUtil.MOD_ID+"."+name, x, y, displayStack, hasToHaveBefore == null ? null : hasToHaveBefore.chieve);
2015-10-03 10:16:18 +02:00
if(hasToHaveBefore == null){
2016-06-17 23:37:01 +02:00
this.chieve.initIndependentStat();
2015-10-03 10:16:18 +02:00
}
2015-12-09 15:47:57 +01:00
if(special){
2016-06-17 23:37:01 +02:00
this.chieve.setSpecial();
2015-12-09 15:47:57 +01:00
}
2016-08-05 04:49:04 +02:00
if(progressToReach > 0){
this.chieve.setSerializableClazz(JsonSerializableSet.class);
}
2016-06-17 23:37:01 +02:00
this.chieve.registerStat();
2016-08-05 04:49:04 +02:00
if(specialItemsToBeGotten == null || specialItemsToBeGotten.length <= 0){
this.itemsToBeGotten = Collections.singletonList(displayStack);
}
else{
this.itemsToBeGotten = Arrays.asList(specialItemsToBeGotten);
}
}
TheAchievements(String name, int x, int y, ItemStack displayStack, TheAchievements hasToHaveBefore, Type type, ItemStack... specialItemsToBeGotten){
this(name, x, y, displayStack, hasToHaveBefore, type, false, 0, specialItemsToBeGotten);
2015-04-19 01:50:02 +02:00
}
2015-12-19 10:30:39 +01:00
2016-08-05 04:49:04 +02:00
public void get(EntityPlayer player){
this.get(player, 1);
}
public void get(EntityPlayer player, int amount){
if(this.progressToReach > 0){
this.updateStatus(player, amount);
}
else{
player.addStat(this.chieve);
}
}
private void updateStatus(EntityPlayer player, int amount){
if(player instanceof EntityPlayerMP){
2016-08-05 04:49:04 +02:00
StatisticsManager manager = ((EntityPlayerMP)player).getStatFile();
if(manager != null && !manager.hasAchievementUnlocked(this.chieve) && manager.canUnlockAchievement(this.chieve)){
JsonSerializableSet data = manager.getProgress(this.chieve);
if(data == null){
data = manager.setProgress(this.chieve, new JsonSerializableSet());
}
int gottenSoFar = 0;
for(String strg : data){
try{
int i = Integer.parseInt(strg);
gottenSoFar += i;
data.remove(strg);
}
catch(Exception e){
data.remove(strg);
}
}
gottenSoFar += amount;
if(gottenSoFar >= this.progressToReach){
player.addStat(this.chieve);
}
else{
data.add(Integer.toString(gottenSoFar));
}
}
}
2015-12-19 10:30:39 +01:00
}
2015-04-19 01:50:02 +02:00
}