Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Re-added achievements - Organised all imports (seemed all over the place) - Formatted all code (seemed very combined, used the TinkerStyle)
- Loading branch information
Showing
419 changed files
with
2,408 additions
and
4,146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/tconstruct/achievements/AchievementEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package tconstruct.achievements; | ||
|
||
import cpw.mods.fml.common.eventhandler.SubscribeEvent; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.item.*; | ||
import net.minecraft.item.crafting.FurnaceRecipes; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraftforge.event.entity.living.*; | ||
import tconstruct.items.tools.FryingPan; | ||
import tconstruct.library.event.ToolCraftedEvent; | ||
import tconstruct.library.tools.*; | ||
import tconstruct.tools.logic.ToolForgeLogic; | ||
|
||
public class AchievementEvents | ||
{ | ||
@SubscribeEvent | ||
public void toolCreate (ToolCraftedEvent event) | ||
{ | ||
if (event.player != null) | ||
{ | ||
TAchievements.triggerAchievement(event.player, "tconstruct.tinkerer"); | ||
|
||
if (event.tool != null && event.tool.getItem() instanceof Weapon) | ||
{ | ||
TAchievements.triggerAchievement(event.player, "tconstruct.preparedFight"); | ||
} | ||
|
||
if (event.inventory != null && event.inventory instanceof ToolForgeLogic && event.tool.getItem() instanceof ToolCore && ((ToolCore) event.tool.getItem()).durabilityTypeExtra() != 0) | ||
{ | ||
TAchievements.triggerAchievement(event.player, "tconstruct.proTinkerer"); | ||
} | ||
} | ||
} | ||
|
||
@SubscribeEvent | ||
public void entitySlain (LivingDeathEvent event) | ||
{ | ||
if (event.source != null && event.source.getEntity() instanceof EntityPlayer) | ||
{ | ||
EntityPlayer murderer = (EntityPlayer) event.source.getEntity(); | ||
|
||
if (murderer.getHeldItem() != null && murderer.getHeldItem().getItem() instanceof Weapon) | ||
{ | ||
TAchievements.triggerAchievement(murderer, "tconstruct.enemySlayer"); | ||
} | ||
} | ||
} | ||
|
||
@SubscribeEvent | ||
public void entityDrops (LivingDropsEvent event) | ||
{ | ||
if (event.source.getEntity() instanceof EntityPlayer) | ||
{ | ||
EntityPlayer player = (EntityPlayer) event.source.getEntity(); | ||
|
||
if (player.getHeldItem() != null && player.getHeldItem().getItem() instanceof FryingPan) | ||
{ | ||
for (int i = 0; i < event.drops.size(); i++) | ||
{ | ||
ItemStack is = event.drops.get(i).getEntityItem(); | ||
if (FurnaceRecipes.smelting().getSmeltingResult(is) != null && FurnaceRecipes.smelting().getSmeltingResult(is).getItem() instanceof ItemFood) | ||
{ | ||
NBTTagCompound stackCompound = is.getTagCompound(); | ||
if (stackCompound == null) | ||
{ | ||
stackCompound = new NBTTagCompound(); | ||
} | ||
|
||
stackCompound.setBoolean("frypanKill", true); | ||
is.setTagCompound(stackCompound); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
src/main/java/tconstruct/achievements/TAchievements.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package tconstruct.achievements; | ||
|
||
import java.util.HashMap; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.stats.Achievement; | ||
import net.minecraft.util.StatCollector; | ||
import net.minecraftforge.common.AchievementPage; | ||
import tconstruct.smeltery.TinkerSmeltery; | ||
import tconstruct.tools.TinkerTools; | ||
import tconstruct.util.config.PHConstruct; | ||
|
||
public class TAchievements | ||
{ | ||
|
||
private static AchievementPage achievementsPage; | ||
private static HashMap<String, Achievement> achievementsList = new HashMap<String, Achievement>(); | ||
|
||
/** | ||
* Adds an achievement and registers it, so there is no need to call .registerStat | ||
* @param name The name of the achievement | ||
* @param achievement The achievement | ||
*/ | ||
public static void addAchievement (String name, Achievement achievement) | ||
{ | ||
if (!PHConstruct.achievementsEnabled) | ||
{ | ||
return; | ||
} | ||
|
||
achievementsList.put(name, achievement.registerStat()); | ||
} | ||
|
||
/** | ||
* Returns a registered achievement | ||
* @param name The name of the achievement | ||
* @return The achievement | ||
*/ | ||
public static Achievement getAchievement (String name) | ||
{ | ||
return achievementsList.get(name); | ||
} | ||
|
||
/** | ||
* Grants the achievement | ||
* @param player The player that earned the achievement | ||
* @param name The name of the achievement | ||
*/ | ||
public static void triggerAchievement (EntityPlayer player, String name) | ||
{ | ||
if (!PHConstruct.achievementsEnabled) | ||
{ | ||
return; | ||
} | ||
|
||
Achievement ach = getAchievement(name); | ||
|
||
if (ach != null) | ||
{ | ||
player.triggerAchievement(ach); | ||
} | ||
} | ||
|
||
/** | ||
* Adds all the achievements included in TConstruct, call before registerAchievementPane is called | ||
*/ | ||
public static void addDefaultAchievements () | ||
{ | ||
if (!PHConstruct.achievementsEnabled) | ||
{ | ||
return; | ||
} | ||
|
||
addAchievement("tconstruct.beginner", new Achievement("tconstruct.beginner", "tconstruct.beginner", 0, 0, TinkerTools.manualBook, null).initIndependentStat()); | ||
addAchievement("tconstruct.pattern", new Achievement("tconstruct.pattern", "tconstruct.pattern", 2, 1, TinkerTools.blankPattern, getAchievement("tconstruct.beginner"))); | ||
addAchievement("tconstruct.tinkerer", new Achievement("tconstruct.tinkerer", "tconstruct.tinkerer", 2, 2, new ItemStack(TinkerTools.titleIcon, 1, 4096), getAchievement("tconstruct.pattern"))); | ||
addAchievement("tconstruct.preparedFight", new Achievement("tconstruct.preparedFight", "tconstruct.preparedFight", 1, 3, new ItemStack(TinkerTools.titleIcon, 1, 4097), getAchievement("tconstruct.tinkerer"))); | ||
addAchievement("tconstruct.proTinkerer", new Achievement("tconstruct.proTinkerer", "tconstruct.proTinkerer", 4, 3, new ItemStack(TinkerTools.titleIcon, 1, 4098), getAchievement("tconstruct.tinkerer"))); | ||
addAchievement("tconstruct.smelteryMaker", new Achievement("tconstruct.smelteryMaker", "tconstruct.smelteryMaker", -2, -1, TinkerSmeltery.smeltery, getAchievement("tconstruct.beginner"))); | ||
addAchievement("tconstruct.enemySlayer", new Achievement("tconstruct.enemySlayer", "tconstruct.enemySlayer", 0, 5, new ItemStack(TinkerTools.titleIcon, 1, 4099), getAchievement("tconstruct.preparedFight"))); | ||
addAchievement("tconstruct.dualConvenience", new Achievement("tconstruct.dualConvenience", "tconstruct.dualConvenience", 0, 7, new ItemStack(TinkerTools.titleIcon, 1, 4100), getAchievement("tconstruct.enemySlayer")).setSpecial()); | ||
} | ||
|
||
/** | ||
* Should be called after all the achievements are loaded (PostInit would be good) | ||
*/ | ||
public static void registerAchievementPane () | ||
{ | ||
if (!PHConstruct.achievementsEnabled) | ||
{ | ||
return; | ||
} | ||
|
||
Achievement[] achievements = new Achievement[achievementsList.size()]; | ||
|
||
achievements = achievementsList.values().toArray(achievements); | ||
achievementsPage = new AchievementPage(StatCollector.translateToLocal("tconstruct.achievementPage.name"), achievements); | ||
AchievementPage.registerAchievementPage(achievementsPage); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/tconstruct/achievements/items/CraftAchievementItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package tconstruct.achievements.items; | ||
|
||
import mantle.items.abstracts.CraftingItem; | ||
import net.minecraft.creativetab.CreativeTabs; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.world.World; | ||
import tconstruct.achievements.TAchievements; | ||
|
||
public class CraftAchievementItem extends CraftingItem | ||
{ | ||
public String grantedAchievement = ""; | ||
|
||
public CraftAchievementItem(String[] names, String[] tex, String folder, String modTexturePrefix, CreativeTabs tab, String tachievement) | ||
{ | ||
super(names, tex, folder, modTexturePrefix, tab); | ||
|
||
grantedAchievement = tachievement; | ||
} | ||
|
||
@Override | ||
public void onCreated (ItemStack item, World world, EntityPlayer player) | ||
{ | ||
if (grantedAchievement != null && !grantedAchievement.equals("")) | ||
{ | ||
TAchievements.triggerAchievement(player, grantedAchievement); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.