diff --git a/common/buildcraft/BuildCraftBuilders.java b/common/buildcraft/BuildCraftBuilders.java index 9d8c885d..d9b8e426 100644 --- a/common/buildcraft/BuildCraftBuilders.java +++ b/common/buildcraft/BuildCraftBuilders.java @@ -25,6 +25,7 @@ import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.launchwrapper.Launch; +import net.minecraft.stats.Achievement; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.event.FMLInitializationEvent; @@ -161,7 +162,11 @@ public class BuildCraftBuilders extends BuildCraftMod { public static ItemBlueprintTemplate templateItem; public static ItemBlueprintStandard blueprintItem; - public static ActionFiller[] fillerActions; + public static Achievement architectAchievement; + public static Achievement libraryAchievement; + public static Achievement blueprintAchievement; + public static Achievement builderAchievement; + public static Achievement templateAchievement; public static BlueprintDatabase serverDB; public static BlueprintDatabase clientDB; @@ -453,6 +458,12 @@ public class BuildCraftBuilders extends BuildCraftMod { BlueprintDeployer.instance = new RealBlueprintDeployer(); + architectAchievement = BuildCraftCore.achievementManager.registerAchievement(new Achievement("achievement.architect", "architectAchievement", 11, 2, BuildCraftBuilders.architectBlock, BuildCraftCore.goldGearAchievement)); + builderAchievement = BuildCraftCore.achievementManager.registerAchievement(new Achievement("achievement.builder", "builderAchievement", 13, 2, BuildCraftBuilders.builderBlock, architectAchievement)); + blueprintAchievement = BuildCraftCore.achievementManager.registerAchievement(new Achievement("achievement.blueprint", "blueprintAchievement", 11, 4, BuildCraftBuilders.blueprintItem, architectAchievement)); + templateAchievement = BuildCraftCore.achievementManager.registerAchievement(new Achievement("achievement.template", "templateAchievement", 13, 4, BuildCraftBuilders.templateItem, blueprintAchievement)); + libraryAchievement = BuildCraftCore.achievementManager.registerAchievement(new Achievement("achievement.blueprintLibrary", "blueprintLibraryAchievement", 15, 2, BuildCraftBuilders.libraryBlock, builderAchievement)); + if (BuildCraftCore.loadDefaultRecipes) { loadRecipes(); } diff --git a/common/buildcraft/BuildCraftCore.java b/common/buildcraft/BuildCraftCore.java index f6f28829..874b8550 100644 --- a/common/buildcraft/BuildCraftCore.java +++ b/common/buildcraft/BuildCraftCore.java @@ -13,6 +13,7 @@ import java.nio.ByteBuffer; import java.nio.FloatBuffer; import java.nio.IntBuffer; import java.util.HashSet; +import java.util.Set; import java.util.UUID; import com.mojang.authlib.GameProfile; @@ -73,6 +74,7 @@ import buildcraft.api.statements.ITriggerInternal; import buildcraft.api.statements.StatementManager; import buildcraft.api.statements.StatementParameterItemStack; import buildcraft.api.tiles.IControllable; +import buildcraft.core.AchievementManager; import buildcraft.core.BlockSpring; import buildcraft.core.BuildCraftConfiguration; import buildcraft.core.CommandBuildCraft; @@ -112,7 +114,6 @@ import buildcraft.core.statements.TriggerInventoryLevel; import buildcraft.core.statements.TriggerMachine; import buildcraft.core.statements.TriggerRedstoneInput; import buildcraft.core.utils.ColorUtils; -import buildcraft.core.utils.CraftingHandler; import buildcraft.core.utils.WorldPropertyIsDirt; import buildcraft.core.utils.WorldPropertyIsFarmland; import buildcraft.core.utils.WorldPropertyIsFluidSource; @@ -254,30 +255,14 @@ public class BuildCraftCore extends BuildCraftMod { public static boolean loadDefaultRecipes = true; public static boolean consumeWaterSources = false; + public static AchievementManager achievementManager; + public static Achievement woodenGearAchievement; public static Achievement stoneGearAchievement; public static Achievement ironGearAchievement; public static Achievement goldGearAchievement; public static Achievement diamondGearAchievement; public static Achievement wrenchAchievement; - public static Achievement engineAchievement1; - public static Achievement engineAchievement2; - public static Achievement engineAchievement3; - public static Achievement aLotOfCraftingAchievement; - public static Achievement straightDownAchievement; - public static Achievement chunkDestroyerAchievement; - public static Achievement fasterFillingAchievement; - public static Achievement timeForSomeLogicAchievement; - public static Achievement refineAndRedefineAchievement; - public static Achievement tinglyLaserAchievement; - - public static Achievement architectAchievement; - public static Achievement builderAchievement; - public static Achievement blueprintAchievement; - public static Achievement templateAchievement; - public static Achievement libraryAchievement; - - public static AchievementPage BuildcraftAchievements; public static HashSet recipesBlacklist = new HashSet(); @@ -400,6 +385,16 @@ public class BuildCraftCore extends BuildCraftMod { channels = NetworkRegistry.INSTANCE.newChannel (DefaultProps.NET_CHANNEL_NAME + "-CORE", new BuildCraftChannelHandler(), new PacketHandler()); + achievementManager = new AchievementManager(); + FMLCommonHandler.instance().bus().register(achievementManager); + + woodenGearAchievement = achievementManager.registerAchievement(new Achievement("achievement.woodenGear", "woodenGearAchievement", 0, 0, woodenGearItem, null)); + stoneGearAchievement = achievementManager.registerAchievement(new Achievement("achievement.stoneGear", "stoneGearAchievement", 2, 0, stoneGearItem, woodenGearAchievement)); + ironGearAchievement = achievementManager.registerAchievement(new Achievement("achievement.ironGear", "ironGearAchievement", 4, 0, ironGearItem, stoneGearAchievement)); + goldGearAchievement = achievementManager.registerAchievement(new Achievement("achievement.goldGear", "goldGearAchievement", 6, 0, goldGearItem, ironGearAchievement)); + diamondGearAchievement = achievementManager.registerAchievement(new Achievement("achievement.diamondGear", "diamondGearAchievement", 8, 0, diamondGearItem, goldGearAchievement)); + wrenchAchievement = achievementManager.registerAchievement(new Achievement("achievement.wrench", "wrenchAchievement", 3, 2, wrenchItem, stoneGearAchievement)); + // BuildCraft 6.1.4 and below - migration only StatementManager.registerParameterClass("buildcraft:stackTrigger", StatementParameterItemStack.class); StatementManager.registerParameterClass("buildcraft:stackAction", StatementParameterItemStack.class); @@ -490,8 +485,6 @@ public class BuildCraftCore extends BuildCraftMod { EntityList.stringToClassMapping.remove("BuildCraft|Core.bcLaser"); EntityList.stringToClassMapping.remove("BuildCraft|Core.bcEnergyLaser"); - FMLCommonHandler.instance().bus().register(new CraftingHandler()); - CoreProxy.proxy.initializeRendering(); CoreProxy.proxy.initializeEntityRendering(); @@ -508,6 +501,8 @@ public class BuildCraftCore extends BuildCraftMod { } } + achievementManager.finalize(); + BuildCraftAPI.softBlocks.add(Blocks.snow); BuildCraftAPI.softBlocks.add(Blocks.vine); BuildCraftAPI.softBlocks.add(Blocks.fire); @@ -650,33 +645,4 @@ public class BuildCraftCore extends BuildCraftMod { property.clear(); } } - - @Mod.EventHandler - public void load(FMLInitializationEvent event) { - woodenGearAchievement = new Achievement("achievement.woodenGear", "woodenGearAchievement", 0, 0, woodenGearItem, null).registerStat(); - stoneGearAchievement = new Achievement("achievement.stoneGear", "stoneGearAchievement", 2, 0, stoneGearItem, woodenGearAchievement).registerStat(); - ironGearAchievement = new Achievement("achievement.ironGear", "ironGearAchievement", 4, 0, ironGearItem, stoneGearAchievement).registerStat(); - goldGearAchievement = new Achievement("achievement.goldGear", "goldGearAchievement", 6, 0, goldGearItem, ironGearAchievement).registerStat(); - diamondGearAchievement = new Achievement("achievement.diamondGear", "diamondGearAchievement", 8, 0, diamondGearItem, goldGearAchievement).registerStat(); - wrenchAchievement = new Achievement("achievement.wrench", "wrenchAchievement", 3, 2, wrenchItem, stoneGearAchievement).registerStat(); - engineAchievement1 = new Achievement("achievement.redstoneEngine", "engineAchievement1", 1, -2, new ItemStack(BuildCraftEnergy.engineBlock, 1, 0), woodenGearAchievement).registerStat(); - engineAchievement2 = new Achievement("achievement.stirlingEngine", "engineAchievement2", 3, -2, new ItemStack(BuildCraftEnergy.engineBlock, 1, 1), engineAchievement1).registerStat(); - engineAchievement3 = new Achievement("achievement.combustionEngine", "engineAchievement3", 5, -2, new ItemStack(BuildCraftEnergy.engineBlock, 1, 2), engineAchievement2).registerStat(); - aLotOfCraftingAchievement = new Achievement("achievement.aLotOfCrafting", "aLotOfCraftingAchievement", 1, 2, BuildCraftFactory.autoWorkbenchBlock, woodenGearAchievement).registerStat(); - straightDownAchievement = new Achievement("achievement.straightDown", "straightDownAchievement", 5, 2, BuildCraftFactory.miningWellBlock, ironGearAchievement).registerStat(); - chunkDestroyerAchievement = new Achievement("achievement.chunkDestroyer", "chunkDestroyerAchievement", 9, 2, BuildCraftFactory.quarryBlock, diamondGearAchievement).registerStat(); - fasterFillingAchievement = new Achievement("achievement.fasterFilling", "fasterFillingAchievement", 7, 2, BuildCraftBuilders.fillerBlock, goldGearAchievement).registerStat(); - timeForSomeLogicAchievement = new Achievement("achievement.timeForSomeLogic", "timeForSomeLogicAchievement", 9, -2, BuildCraftSilicon.assemblyTableBlock, diamondGearAchievement).registerStat(); - refineAndRedefineAchievement = new Achievement("achievement.refineAndRedefine", "refineAndRedefineAchievement", 10, 0, BuildCraftFactory.refineryBlock, diamondGearAchievement).registerStat(); - tinglyLaserAchievement = new Achievement("achievement.tinglyLaser", "tinglyLaserAchievement", 11, -2, BuildCraftSilicon.laserBlock, - timeForSomeLogicAchievement).registerStat(); - architectAchievement = new Achievement("achievement.architect", "architectAchievement", 11, 2, BuildCraftBuilders.architectBlock, chunkDestroyerAchievement).registerStat(); - builderAchievement = new Achievement("achievement.builder", "builderAchievement", 13, 2, BuildCraftBuilders.builderBlock, architectAchievement).registerStat(); - blueprintAchievement = new Achievement("achievement.blueprint", "blueprintAchievement", 11, 4, BuildCraftBuilders.blueprintItem, architectAchievement).registerStat(); - templateAchievement = new Achievement("achievement.template", "templateAchievement", 13, 4, BuildCraftBuilders.templateItem, blueprintAchievement).registerStat(); - libraryAchievement = new Achievement("achievement.blueprintLibrary", "blueprintLibraryAchievement", 15, 2, BuildCraftBuilders.libraryBlock, builderAchievement).registerStat(); - - BuildcraftAchievements = new AchievementPage("Buildcraft", woodenGearAchievement, stoneGearAchievement, ironGearAchievement, goldGearAchievement, diamondGearAchievement, wrenchAchievement, engineAchievement1, engineAchievement2, engineAchievement3, aLotOfCraftingAchievement, straightDownAchievement, chunkDestroyerAchievement, fasterFillingAchievement, timeForSomeLogicAchievement, refineAndRedefineAchievement, tinglyLaserAchievement, architectAchievement, builderAchievement, blueprintAchievement, templateAchievement, libraryAchievement); - AchievementPage.registerAchievementPage(BuildcraftAchievements); - } } diff --git a/common/buildcraft/BuildCraftEnergy.java b/common/buildcraft/BuildCraftEnergy.java index 98c7d885..712686a8 100644 --- a/common/buildcraft/BuildCraftEnergy.java +++ b/common/buildcraft/BuildCraftEnergy.java @@ -19,6 +19,7 @@ import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.stats.Achievement; import net.minecraft.world.biome.BiomeGenBase; import cpw.mods.fml.common.Mod; @@ -100,6 +101,10 @@ public class BuildCraftEnergy extends BuildCraftMod { public static Item bucketRedPlasma; public static Item fuel; + public static Achievement engineAchievement1; + public static Achievement engineAchievement2; + public static Achievement engineAchievement3; + public static boolean canOilBurn; public static boolean isOilDense; public static boolean canEnginesExplode; @@ -355,6 +360,10 @@ public class BuildCraftEnergy extends BuildCraftMod { EnergyProxy.proxy.registerBlockRenderers(); EnergyProxy.proxy.registerTileEntities(); + + engineAchievement1 = BuildCraftCore.achievementManager.registerAchievement(new Achievement("achievement.redstoneEngine", "engineAchievement1", 1, -2, new ItemStack(engineBlock, 1, 0), BuildCraftCore.woodenGearAchievement)); + engineAchievement2 = BuildCraftCore.achievementManager.registerAchievement(new Achievement("achievement.stirlingEngine", "engineAchievement2", 3, -2, new ItemStack(engineBlock, 1, 1), engineAchievement1)); + engineAchievement3 = BuildCraftCore.achievementManager.registerAchievement(new Achievement("achievement.combustionEngine", "engineAchievement3", 5, -2, new ItemStack(engineBlock, 1, 2), engineAchievement2)); } @Mod.EventHandler diff --git a/common/buildcraft/BuildCraftFactory.java b/common/buildcraft/BuildCraftFactory.java index 43bee9da..ddcf388a 100644 --- a/common/buildcraft/BuildCraftFactory.java +++ b/common/buildcraft/BuildCraftFactory.java @@ -17,6 +17,7 @@ import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import net.minecraft.stats.Achievement; import net.minecraft.world.World; import cpw.mods.fml.common.Mod; @@ -90,6 +91,11 @@ public class BuildCraftFactory extends BuildCraftMod { public static BlockRefinery refineryBlock; public static BlockHopper hopperBlock; + public static Achievement aLotOfCraftingAchievement; + public static Achievement straightDownAchievement; + public static Achievement chunkDestroyerAchievement; + public static Achievement refineAndRedefineAchievement; + public static boolean quarryLoadsChunks = true; public static boolean allowMining = true; public static boolean quarryOneTimeUse = false; @@ -165,6 +171,11 @@ public class BuildCraftFactory extends BuildCraftMod { BuilderAPI.schematicRegistry.registerSchematicBlock(autoWorkbenchBlock, SchematicAutoWorkbench.class); BuilderAPI.schematicRegistry.registerSchematicBlock(hopperBlock, SchematicTile.class); + aLotOfCraftingAchievement = BuildCraftCore.achievementManager.registerAchievement(new Achievement("achievement.aLotOfCrafting", "aLotOfCraftingAchievement", 1, 2, autoWorkbenchBlock, BuildCraftCore.woodenGearAchievement)); + straightDownAchievement = BuildCraftCore.achievementManager.registerAchievement(new Achievement("achievement.straightDown", "straightDownAchievement", 5, 2, miningWellBlock, BuildCraftCore.ironGearAchievement)); + chunkDestroyerAchievement = BuildCraftCore.achievementManager.registerAchievement(new Achievement("achievement.chunkDestroyer", "chunkDestroyerAchievement", 9, 2, quarryBlock, BuildCraftCore.diamondGearAchievement)); + refineAndRedefineAchievement = BuildCraftCore.achievementManager.registerAchievement(new Achievement("achievement.refineAndRedefine", "refineAndRedefineAchievement", 10, 0, refineryBlock, BuildCraftCore.diamondGearAchievement)); + if (BuildCraftCore.loadDefaultRecipes) { loadRecipes(); } diff --git a/common/buildcraft/BuildCraftSilicon.java b/common/buildcraft/BuildCraftSilicon.java index 291f73ce..2ff6503e 100644 --- a/common/buildcraft/BuildCraftSilicon.java +++ b/common/buildcraft/BuildCraftSilicon.java @@ -16,6 +16,7 @@ import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.stats.Achievement; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.event.FMLInitializationEvent; @@ -131,6 +132,9 @@ public class BuildCraftSilicon extends BuildCraftMod { public static IActionInternal actionStationDropInPipe = new ActionStationAcceptItemsPipe(); public static IActionInternal actionStationMachineRequestItems = new ActionStationRequestItemsMachine(); + public static Achievement timeForSomeLogicAchievement; + public static Achievement tinglyLaserAchievement; + public static float chipsetCostMultiplier = 1.0F; public static List blacklistedRobots; @@ -227,6 +231,9 @@ public class BuildCraftSilicon extends BuildCraftMod { BuilderAPI.schematicRegistry.registerSchematicBlock(laserBlock, SchematicRotateMeta.class, new int[] {2, 5, 3, 4}, true); + timeForSomeLogicAchievement = BuildCraftCore.achievementManager.registerAchievement(new Achievement("achievement.timeForSomeLogic", "timeForSomeLogicAchievement", 9, -2, assemblyTableBlock, BuildCraftCore.diamondGearAchievement)); + tinglyLaserAchievement = BuildCraftCore.achievementManager.registerAchievement(new Achievement("achievement.tinglyLaser", "tinglyLaserAchievement", 11, -2, laserBlock, timeForSomeLogicAchievement)); + if (BuildCraftCore.loadDefaultRecipes) { loadRecipes(); } diff --git a/common/buildcraft/core/AchievementManager.java b/common/buildcraft/core/AchievementManager.java new file mode 100644 index 00000000..eab140b6 --- /dev/null +++ b/common/buildcraft/core/AchievementManager.java @@ -0,0 +1,38 @@ +package buildcraft.core; + +import java.util.HashSet; +import java.util.Set; +import net.minecraft.item.Item; +import net.minecraft.stats.Achievement; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.PlayerEvent; +import net.minecraftforge.common.AchievementPage; + +public class AchievementManager { + public AchievementPage page; + + public AchievementManager() { + page = new AchievementPage("BuildCraft"); + } + + public Achievement registerAchievement(Achievement a) { + page.getAchievements().add(a.registerStat()); + return a; + } + + public void finalize() { + AchievementPage.registerAchievementPage(page); + } + + @SubscribeEvent + public void onCrafting(PlayerEvent.ItemCraftedEvent event) { + Item item = event.crafting.getItem(); + int damage = event.crafting.getItemDamage(); + + for (Achievement a : page.getAchievements()) { + if (item.equals(a.theItemStack.getItem()) && damage == a.theItemStack.getItemDamage()) { + event.player.addStat(a, 1); + } + } + } +} diff --git a/common/buildcraft/core/utils/CraftingHandler.java b/common/buildcraft/core/utils/CraftingHandler.java deleted file mode 100644 index c25743f0..00000000 --- a/common/buildcraft/core/utils/CraftingHandler.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com - * - * BuildCraft is distributed under the terms of the Minecraft Mod Public - * License 1.0, or MMPL. Please check the contents of the license located in - * http://www.mod-buildcraft.com/MMPL-1.0.txt - */ -package buildcraft.core.utils; - -import net.minecraft.item.Item; - -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.common.gameevent.PlayerEvent; - -import buildcraft.BuildCraftBuilders; -import buildcraft.BuildCraftCore; -import buildcraft.BuildCraftEnergy; -import buildcraft.BuildCraftFactory; -import buildcraft.BuildCraftSilicon; - -public class CraftingHandler { - - @SubscribeEvent - public void onCrafting(PlayerEvent.ItemCraftedEvent event) { - Item item = event.crafting.getItem(); - - if (item.equals(BuildCraftCore.woodenGearItem)) { - event.player.addStat(BuildCraftCore.woodenGearAchievement, 1); - } else if (item.equals(BuildCraftCore.stoneGearItem)) { - event.player.addStat(BuildCraftCore.stoneGearAchievement, 1); - } else if (item.equals(BuildCraftCore.ironGearItem)) { - event.player.addStat(BuildCraftCore.ironGearAchievement, 1); - } else if (item.equals(BuildCraftCore.goldGearItem)) { - event.player.addStat(BuildCraftCore.goldGearAchievement, 1); - } else if (item.equals(BuildCraftCore.diamondGearItem)) { - event.player.addStat(BuildCraftCore.diamondGearAchievement, 1); - } else if (item.equals(BuildCraftCore.wrenchItem)) { - event.player.addStat(BuildCraftCore.wrenchAchievement, 1); - } else if (item.equals(Item.getItemFromBlock(BuildCraftEnergy.engineBlock))) { - if (event.crafting.getItemDamage() == 0) { - event.player.addStat(BuildCraftCore.engineAchievement1, 1); - } else if (event.crafting.getItemDamage() == 1) { - event.player.addStat(BuildCraftCore.engineAchievement2, 1); - } else if (event.crafting.getItemDamage() == 2) { - event.player.addStat(BuildCraftCore.engineAchievement3, 1); - } - } else if (item.equals(Item.getItemFromBlock(BuildCraftFactory.autoWorkbenchBlock))) { - event.player.addStat(BuildCraftCore.aLotOfCraftingAchievement, 1); - } else if (item.equals(Item.getItemFromBlock(BuildCraftFactory.miningWellBlock))) { - event.player.addStat(BuildCraftCore.straightDownAchievement, 1); - } else if (item.equals(Item.getItemFromBlock(BuildCraftFactory.quarryBlock))) { - event.player.addStat(BuildCraftCore.chunkDestroyerAchievement, 1); - } else if (item.equals(Item.getItemFromBlock(BuildCraftFactory.refineryBlock))) { - event.player.addStat(BuildCraftCore.refineAndRedefineAchievement, 1); - } else if (item.equals(Item.getItemFromBlock(BuildCraftBuilders.fillerBlock))) { - event.player.addStat(BuildCraftCore.fasterFillingAchievement, 1); - } else if (item.equals(Item.getItemFromBlock(BuildCraftSilicon.laserBlock))) { - event.player.addStat(BuildCraftCore.tinglyLaserAchievement, 1); - } else if (item.equals(Item.getItemFromBlock(BuildCraftSilicon.assemblyTableBlock))) { - event.player.addStat(BuildCraftCore.timeForSomeLogicAchievement, 1); - } else if (item.equals(Item.getItemFromBlock(BuildCraftBuilders.architectBlock))) { - event.player.addStat(BuildCraftCore.architectAchievement, 1); - } else if (item.equals(Item.getItemFromBlock(BuildCraftBuilders.builderBlock))) { - event.player.addStat(BuildCraftCore.builderAchievement, 1); - } else if (item.equals(BuildCraftBuilders.blueprintItem)) { - event.player.addStat(BuildCraftCore.blueprintAchievement, 1); - } else if (item.equals(BuildCraftBuilders.templateItem)) { - event.player.addStat(BuildCraftCore.templateAchievement, 1); - } else if (item.equals(Item.getItemFromBlock(BuildCraftBuilders.libraryBlock))) { - event.player.addStat(BuildCraftCore.libraryAchievement, 1); - } - } - -}