Added basic achievements
This commit is contained in:
parent
8bd7974a74
commit
d5628ff93a
7 changed files with 126 additions and 0 deletions
|
@ -5,6 +5,7 @@ import cpw.mods.fml.common.event.FMLInitializationEvent;
|
|||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import techreborn.achievement.TRAchievements;
|
||||
import techreborn.client.GuiHandler;
|
||||
import techreborn.compat.CompatManager;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
|
@ -51,6 +52,8 @@ public class Core {
|
|||
NetworkRegistry.INSTANCE.registerGuiHandler(INSTANCE, new GuiHandler());
|
||||
//packets
|
||||
PacketHandler.setChannels(NetworkRegistry.INSTANCE.newChannel(ModInfo.MOD_ID + "_packets", new PacketHandler()));
|
||||
//Achievements
|
||||
TRAchievements.init();
|
||||
LogHelper.info("Initialization Compleate");
|
||||
}
|
||||
|
||||
|
|
32
src/main/java/techreborn/achievement/AchievementMod.java
Normal file
32
src/main/java/techreborn/achievement/AchievementMod.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package techreborn.achievement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.stats.Achievement;
|
||||
|
||||
public class AchievementMod extends Achievement{
|
||||
|
||||
public static List<Achievement> achievements = new ArrayList();
|
||||
|
||||
public AchievementMod(String name, int x, int y, ItemStack icon, Achievement parent)
|
||||
{
|
||||
super("achievement.techreborn:" + name, "TechReborn:" + name, x, y, icon, parent);
|
||||
achievements.add(this);
|
||||
registerStat();
|
||||
}
|
||||
|
||||
public AchievementMod(String name, int x, int y, Item icon, Achievement parent)
|
||||
{
|
||||
this(name, x, y, new ItemStack(icon), parent);
|
||||
}
|
||||
|
||||
public AchievementMod(String name, int x, int y, Block icon, Achievement parent)
|
||||
{
|
||||
this(name, x, y, new ItemStack(icon), parent);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package techreborn.achievement;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.stats.Achievement;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent.ItemCraftedEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent.ItemPickupEvent;
|
||||
|
||||
public class AchievementTriggerer {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onItemPickedUp(ItemPickupEvent event) {
|
||||
ItemStack stack = event.pickedUp.getEntityItem();
|
||||
if(stack != null && stack.getItem() instanceof IPickupAchievement) {
|
||||
Achievement achievement = ((IPickupAchievement) stack.getItem()).getAchievementOnPickup(stack, event.player, event.pickedUp);
|
||||
if(achievement != null)
|
||||
event.player.addStat(achievement, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onItemCrafted(ItemCraftedEvent event) {
|
||||
if(event.crafting != null && event.crafting.getItem() instanceof ICraftAchievement) {
|
||||
Achievement achievement = ((ICraftAchievement) event.crafting.getItem()).getAchievementOnCraft(event.crafting, event.player, event.craftMatrix);
|
||||
if(achievement != null)
|
||||
event.player.addStat(achievement, 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
12
src/main/java/techreborn/achievement/ICraftAchievement.java
Normal file
12
src/main/java/techreborn/achievement/ICraftAchievement.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package techreborn.achievement;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.stats.Achievement;
|
||||
|
||||
public interface ICraftAchievement {
|
||||
|
||||
public Achievement getAchievementOnCraft(ItemStack stack, EntityPlayer player, IInventory matrix);
|
||||
|
||||
}
|
12
src/main/java/techreborn/achievement/IPickupAchievement.java
Normal file
12
src/main/java/techreborn/achievement/IPickupAchievement.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package techreborn.achievement;
|
||||
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.stats.Achievement;
|
||||
|
||||
public interface IPickupAchievement {
|
||||
|
||||
public Achievement getAchievementOnPickup(ItemStack stack, EntityPlayer player, EntityItem item);
|
||||
|
||||
}
|
30
src/main/java/techreborn/achievement/TRAchievements.java
Normal file
30
src/main/java/techreborn/achievement/TRAchievements.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
package techreborn.achievement;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.lib.AchievementNames;
|
||||
import techreborn.lib.ModInfo;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.stats.Achievement;
|
||||
import net.minecraftforge.common.AchievementPage;
|
||||
|
||||
public class TRAchievements {
|
||||
|
||||
public static AchievementPage techrebornPage;
|
||||
public static int pageIndex;
|
||||
|
||||
public static Achievement orePickUp;
|
||||
|
||||
public static void init()
|
||||
{
|
||||
orePickUp = new AchievementMod(AchievementNames.ORE_PICKUP, 0, 0, new ItemStack(ModBlocks.ore,1, 0), null);
|
||||
|
||||
pageIndex = AchievementPage.getAchievementPages().size();
|
||||
techrebornPage = new AchievementPage(ModInfo.MOD_NAME, AchievementMod.achievements.toArray(new Achievement[AchievementMod.achievements.size()]));
|
||||
AchievementPage.registerAchievementPage(techrebornPage);
|
||||
|
||||
FMLCommonHandler.instance().bus().register(new AchievementTriggerer());
|
||||
|
||||
}
|
||||
|
||||
}
|
7
src/main/java/techreborn/lib/AchievementNames.java
Normal file
7
src/main/java/techreborn/lib/AchievementNames.java
Normal file
|
@ -0,0 +1,7 @@
|
|||
package techreborn.lib;
|
||||
|
||||
public class AchievementNames
|
||||
{
|
||||
public static final String ORE_PICKUP = "orePickup";
|
||||
|
||||
}
|
Loading…
Reference in a new issue