Merge pull request #917 from GirafiStudios/achievement_fix
Fixed some achievements not working
This commit is contained in:
commit
7eb131681d
1 changed files with 48 additions and 54 deletions
|
@ -7,11 +7,6 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package biomesoplenty.common.handler;
|
package biomesoplenty.common.handler;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
|
|
||||||
import biomesoplenty.api.achievement.BOPAchievements;
|
import biomesoplenty.api.achievement.BOPAchievements;
|
||||||
import biomesoplenty.api.biome.BOPBiomes;
|
import biomesoplenty.api.biome.BOPBiomes;
|
||||||
import biomesoplenty.api.block.BOPBlocks;
|
import biomesoplenty.api.block.BOPBlocks;
|
||||||
|
@ -23,14 +18,14 @@ import biomesoplenty.common.block.BlockBOPFlower;
|
||||||
import biomesoplenty.common.block.BlockBOPLog;
|
import biomesoplenty.common.block.BlockBOPLog;
|
||||||
import biomesoplenty.common.block.BlockBOPPlant;
|
import biomesoplenty.common.block.BlockBOPPlant;
|
||||||
import biomesoplenty.common.block.BlockBOPSapling;
|
import biomesoplenty.common.block.BlockBOPSapling;
|
||||||
import biomesoplenty.common.item.ItemJarFilled;
|
import com.google.common.collect.Sets;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.init.Items;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemBlock;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.stats.AchievementList;
|
import net.minecraft.stats.AchievementList;
|
||||||
import net.minecraft.util.JsonSerializableSet;
|
import net.minecraft.util.JsonSerializableSet;
|
||||||
|
@ -39,120 +34,118 @@ import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.world.biome.Biome;
|
import net.minecraft.world.biome.Biome;
|
||||||
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
|
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
|
||||||
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
|
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
|
||||||
|
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
|
||||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||||
import net.minecraftforge.event.world.BlockEvent;
|
import net.minecraftforge.event.world.BlockEvent;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
|
|
||||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent.ItemCraftedEvent;
|
import net.minecraftforge.fml.common.gameevent.PlayerEvent.ItemCraftedEvent;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class AchievementEventHandler
|
public class AchievementEventHandler
|
||||||
{
|
{
|
||||||
private static final Set<Biome> BOP_BIOMES_TO_EXPLORE = Sets.union(BOPBiomes.REG_INSTANCE.getPresentBiomes(), Biome.EXPLORATION_BIOMES_LIST);
|
private static final Set<Biome> BOP_BIOMES_TO_EXPLORE = Sets.union(BOPBiomes.REG_INSTANCE.getPresentBiomes(), Biome.EXPLORATION_BIOMES_LIST);
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onItemPickup(PlayerEvent.ItemPickupEvent event)
|
public void onItemPickup(EntityItemPickupEvent event)
|
||||||
{
|
{
|
||||||
ItemStack stack = event.pickedUp.getEntityItem();
|
ItemStack stack = event.getItem().getEntityItem();
|
||||||
Item item = stack.getItem();
|
Item item = stack.getItem();
|
||||||
|
|
||||||
Block block = Block.getBlockFromItem(item);
|
IBlockState state = Block.getBlockFromItem(item).getStateFromMeta(item.getMetadata(stack.getMetadata()));
|
||||||
IBlockState state = block != null && item instanceof ItemBlock ? block.getStateFromMeta(((ItemBlock)item).getMetadata(stack.getMetadata())) : null;
|
Block block = state.getBlock();
|
||||||
EntityPlayer player = event.player;
|
EntityPlayer player = event.getEntityPlayer();
|
||||||
|
|
||||||
if (block != null && block instanceof BlockBOPLog)
|
if (block instanceof BlockBOPLog)
|
||||||
{
|
{
|
||||||
player.addStat(AchievementList.MINE_WOOD);
|
player.addStat(AchievementList.MINE_WOOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Flower Child Achievement
|
//Flower Child Achievement
|
||||||
if (block != null && block instanceof BlockBOPFlower || block == Blocks.RED_FLOWER || block == Blocks.YELLOW_FLOWER)
|
if (block instanceof BlockBOPFlower || block == Blocks.RED_FLOWER || block == Blocks.YELLOW_FLOWER)
|
||||||
{
|
{
|
||||||
player.addStat(BOPAchievements.obtain_flowers);
|
player.addStat(BOPAchievements.obtain_flowers);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Berry Good Achievement
|
//Berry Good Achievement
|
||||||
if (item != null && item == BOPItems.berries)
|
if (item == BOPItems.berries)
|
||||||
{
|
{
|
||||||
player.addStat(BOPAchievements.obtain_berry);
|
player.addStat(BOPAchievements.obtain_berry);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Totally Coral Achievement
|
//Totally Coral Achievement
|
||||||
if (block != null && block == BOPBlocks.coral)
|
if (block == BOPBlocks.coral)
|
||||||
{
|
{
|
||||||
player.addStat(BOPAchievements.obtain_coral);
|
player.addStat(BOPAchievements.obtain_coral);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Life Finds a Way Achievement
|
//Life Finds a Way Achievement
|
||||||
if (block != null && state == BlockBOPFlower.paging.getVariantState(BOPFlowers.MINERS_DELIGHT))
|
if (state == BlockBOPFlower.paging.getVariantState(BOPFlowers.MINERS_DELIGHT))
|
||||||
{
|
{
|
||||||
player.addStat(BOPAchievements.obtain_miners_delight);
|
player.addStat(BOPAchievements.obtain_miners_delight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Rather Thorny Achievement
|
//Rather Thorny Achievement
|
||||||
if (block != null && state == BlockBOPPlant.paging.getVariantState(BOPPlants.THORN))
|
if (state == BlockBOPPlant.paging.getVariantState(BOPPlants.THORN))
|
||||||
{
|
{
|
||||||
player.addStat(BOPAchievements.obtain_thorn);
|
player.addStat(BOPAchievements.obtain_thorn);
|
||||||
}
|
}
|
||||||
|
|
||||||
//I am Become Death Achievement
|
//I am Become Death Achievement
|
||||||
if (block != null && state == BlockBOPFlower.paging.getVariantState(BOPFlowers.DEATHBLOOM))
|
if (state == BlockBOPFlower.paging.getVariantState(BOPFlowers.DEATHBLOOM))
|
||||||
{
|
{
|
||||||
player.addStat(BOPAchievements.obtain_deathbloom);
|
player.addStat(BOPAchievements.obtain_deathbloom);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Godsend Achievement
|
//Godsend Achievement
|
||||||
if (block != null && state == BlockBOPFlower.paging.getVariantState(BOPFlowers.WILTED_LILY))
|
if (state == BlockBOPFlower.paging.getVariantState(BOPFlowers.WILTED_LILY))
|
||||||
{
|
{
|
||||||
player.addStat(BOPAchievements.obtain_wilted_lily);
|
player.addStat(BOPAchievements.obtain_wilted_lily);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Stalk Market Achievement
|
//Stalk Market Achievement
|
||||||
if (item != null && item == BOPItems.turnip)
|
if (item == BOPItems.turnip)
|
||||||
{
|
{
|
||||||
player.addStat(BOPAchievements.obtain_turnip);
|
player.addStat(BOPAchievements.obtain_turnip);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Soul Searching Achievement
|
//Soul Searching Achievement
|
||||||
if (item != null && item == BOPItems.soul)
|
if (item == BOPItems.soul)
|
||||||
{
|
{
|
||||||
player.addStat(BOPAchievements.obtain_soul);
|
player.addStat(BOPAchievements.obtain_soul);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Honeycomb's Big Achievement
|
//Honeycomb's Big Achievement
|
||||||
if (item != null && item == BOPItems.filled_honeycomb)
|
if (item == BOPItems.filled_honeycomb)
|
||||||
{
|
{
|
||||||
player.addStat(BOPAchievements.obtain_honeycomb);
|
player.addStat(BOPAchievements.obtain_honeycomb);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Don't Breathe This Achievement
|
//Don't Breathe This Achievement
|
||||||
if (item != null && item == BOPItems.pixie_dust)
|
if (item == BOPItems.pixie_dust)
|
||||||
{
|
{
|
||||||
player.addStat(BOPAchievements.obtain_pixie_dust);
|
player.addStat(BOPAchievements.obtain_pixie_dust);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Far Out Achievement
|
//Far Out Achievement
|
||||||
if (item != null && item == BOPItems.crystal_shard)
|
if (item == BOPItems.crystal_shard)
|
||||||
{
|
{
|
||||||
player.addStat(BOPAchievements.obtain_celestial_crystal);
|
player.addStat(BOPAchievements.obtain_celestial_crystal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onItemUsed(PlayerInteractEvent event)
|
public void onItemUsed(PlayerInteractEvent.RightClickItem event)
|
||||||
{
|
{
|
||||||
/* TODO: 1.9 if (event.action != Action.LEFT_CLICK_BLOCK)
|
ItemStack stack = event.getItemStack();
|
||||||
{
|
EntityPlayer player = event.getEntityPlayer();
|
||||||
ItemStack stack = event.entityPlayer.getHeldItem();
|
|
||||||
Item item = stack != null ? stack.getItem() : null;
|
|
||||||
EntityPlayer player = event.entityPlayer;
|
|
||||||
|
|
||||||
//Gone Home
|
//Gone Home
|
||||||
if (item == BOPItems.enderporter)
|
if (!stack.isEmpty() && stack.getItem() == BOPItems.enderporter) {
|
||||||
{
|
|
||||||
player.addStat(BOPAchievements.use_enderporter);
|
player.addStat(BOPAchievements.use_enderporter);
|
||||||
}
|
}
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
@ -181,8 +174,7 @@ public class AchievementEventHandler
|
||||||
if (stack != null)
|
if (stack != null)
|
||||||
{
|
{
|
||||||
Item item = stack.getItem();
|
Item item = stack.getItem();
|
||||||
Block block = Block.getBlockFromItem(item);
|
IBlockState state = Block.getBlockFromItem(item).getStateFromMeta(item.getMetadata(stack.getMetadata()));
|
||||||
IBlockState state = block != null && item instanceof ItemBlock ? block.getStateFromMeta(((ItemBlock)item).getMetadata(stack.getMetadata())) : null;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -192,7 +184,7 @@ public class AchievementEventHandler
|
||||||
event.getPlayer().addStat(BOPAchievements.grow_sacred_oak);
|
event.getPlayer().addStat(BOPAchievements.grow_sacred_oak);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception e) {} //Fail quietly if there's a problem matching metadata to a block state
|
catch(Exception ignored) {} //Fail quietly if there's a problem matching metadata to a block state
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,25 +195,25 @@ public class AchievementEventHandler
|
||||||
EntityPlayer player = event.player;
|
EntityPlayer player = event.player;
|
||||||
|
|
||||||
//Nectar of the Gods Achievement
|
//Nectar of the Gods Achievement
|
||||||
if (item != null && item == BOPItems.ambrosia)
|
if (item == BOPItems.ambrosia)
|
||||||
{
|
{
|
||||||
player.addStat(BOPAchievements.craft_ambrosia);
|
player.addStat(BOPAchievements.craft_ambrosia);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Flaxen Fun Achievement
|
//Flaxen Fun Achievement
|
||||||
if (item != null && item == BOPItems.flax_string)
|
if (item == BOPItems.flax_string)
|
||||||
{
|
{
|
||||||
player.addStat(BOPAchievements.craft_flax_string);
|
player.addStat(BOPAchievements.craft_flax_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Getting a Downgrade Achievement
|
//Getting a Downgrade Achievement
|
||||||
if (item != null && item == BOPItems.mud_pickaxe)
|
if (item == BOPItems.mud_pickaxe)
|
||||||
{
|
{
|
||||||
player.addStat(BOPAchievements.craft_muddy_pickaxe);
|
player.addStat(BOPAchievements.craft_muddy_pickaxe);
|
||||||
}
|
}
|
||||||
|
|
||||||
//By Your Powers Combined Achievement
|
//By Your Powers Combined Achievement
|
||||||
if (item != null && item == BOPItems.terrestrial_artifact)
|
if (item == BOPItems.terrestrial_artifact)
|
||||||
{
|
{
|
||||||
player.addStat(BOPAchievements.craft_terrestrial_artifact);
|
player.addStat(BOPAchievements.craft_terrestrial_artifact);
|
||||||
}
|
}
|
||||||
|
@ -231,24 +223,26 @@ public class AchievementEventHandler
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onPlayerUpdate(LivingUpdateEvent event)
|
public void onPlayerUpdate(LivingUpdateEvent event)
|
||||||
{
|
{
|
||||||
/* TODO: 1.9 if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer)
|
if (!event.getEntityLiving().world.isRemote && event.getEntityLiving() instanceof EntityPlayer)
|
||||||
{
|
{
|
||||||
EntityPlayerMP player = (EntityPlayerMP)event.entity;
|
EntityPlayerMP player = (EntityPlayerMP) event.getEntityLiving();
|
||||||
|
|
||||||
//Check every five seconds if the player has entered a new biome, if they haven't already gotten the achievement
|
//Check every five seconds if the player has entered a new biome, if they haven't already gotten the achievement
|
||||||
if (player.ticksExisted % 20 * 5 == 0)
|
if (player.ticksExisted % 20 * 5 == 0)
|
||||||
{
|
{
|
||||||
|
//Search Party
|
||||||
if (!player.getStatFile().hasAchievementUnlocked(BOPAchievements.use_biome_finder))
|
if (!player.getStatFile().hasAchievementUnlocked(BOPAchievements.use_biome_finder))
|
||||||
{
|
{
|
||||||
this.updateBiomeRadarExplore(player);
|
this.updateBiomeRadarExplore(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!player.getStatFile().hasAchievementUnlocked(BOPAchievements.explore_all_biomes))
|
//The Wanderer
|
||||||
|
if (!player.getStatFile().hasAchievementUnlocked(BOPAchievements.explore_all_biomes)) // TODO Test
|
||||||
{
|
{
|
||||||
this.updateBiomesExplored(player);
|
this.updateBiomesExplored(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateBiomeRadarExplore(EntityPlayerMP player)
|
private void updateBiomeRadarExplore(EntityPlayerMP player)
|
||||||
|
@ -259,7 +253,7 @@ public class AchievementEventHandler
|
||||||
for (ItemStack stack : player.inventory.mainInventory)
|
for (ItemStack stack : player.inventory.mainInventory)
|
||||||
{
|
{
|
||||||
//If the stack is null, skip it
|
//If the stack is null, skip it
|
||||||
if (stack == null)
|
if (stack.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (stack.getItem() == BOPItems.biome_finder && stack.hasTagCompound() && stack.getTagCompound().hasKey("biomeIDToFind"))
|
if (stack.getItem() == BOPItems.biome_finder && stack.hasTagCompound() && stack.getTagCompound().hasKey("biomeIDToFind"))
|
||||||
|
@ -281,12 +275,12 @@ public class AchievementEventHandler
|
||||||
Biome currentBiome = player.world.getBiome(new BlockPos(MathHelper.floor(player.posX), 0, MathHelper.floor(player.posZ)));
|
Biome currentBiome = player.world.getBiome(new BlockPos(MathHelper.floor(player.posX), 0, MathHelper.floor(player.posZ)));
|
||||||
String biomeName = currentBiome.getBiomeName();
|
String biomeName = currentBiome.getBiomeName();
|
||||||
//Get a list of the current explored biomes
|
//Get a list of the current explored biomes
|
||||||
JsonSerializableSet exploredBiomeNames = (JsonSerializableSet)player.getStatFile().getProgress(BOPAchievements.explore_all_biomes);
|
JsonSerializableSet exploredBiomeNames = player.getStatFile().getProgress(BOPAchievements.explore_all_biomes);
|
||||||
|
|
||||||
if (exploredBiomeNames == null)
|
if (exploredBiomeNames == null)
|
||||||
{
|
{
|
||||||
//Set the stat data
|
//Set the stat data
|
||||||
exploredBiomeNames = (JsonSerializableSet)player.getStatFile().setProgress(BOPAchievements.explore_all_biomes, new JsonSerializableSet());
|
exploredBiomeNames = player.getStatFile().setProgress(BOPAchievements.explore_all_biomes, new JsonSerializableSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add the current biome to the set of biomes that the player has explored
|
//Add the current biome to the set of biomes that the player has explored
|
||||||
|
@ -305,7 +299,7 @@ public class AchievementEventHandler
|
||||||
//Iterate over the set of biomes required to be explored and remove those that already have been explored
|
//Iterate over the set of biomes required to be explored and remove those that already have been explored
|
||||||
while (iterator.hasNext())
|
while (iterator.hasNext())
|
||||||
{
|
{
|
||||||
Biome biome = (Biome)iterator.next();
|
Biome biome = iterator.next();
|
||||||
|
|
||||||
if (biome.getBiomeName().equals(exploredBiomeName))
|
if (biome.getBiomeName().equals(exploredBiomeName))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue