Posted October 15, 201510 yr I'm basically just trying to assign an NBT tag to each player that tracks how many cobblestone they've broken and assigns an achievement once it hits a certain amount. It seems to work somewhat but only the first player connecting to a world can unlock the achievement - everyone connecting after that has the cumulative value of all the cobblestone broken by previous players assigned to the tag. For example, if player 101 if the first player to join a new world from a test client and digs up 10 blocks, the tag registers perfectly ok and the achievement is triggered - if the client is closed and reopened, player 102 will having the tag assigned to a value of 11 upon breaking the first cobblestone block. Is this because of some weirdness associated with the eclipse test client (I've noticed you start with the same items, but not achievements?) loading the same player data over and over, or is my code just running indiscriminately and assigning NBT tag values regardless of specific player? My extendedplayer class that assigns the NBT tags is below package achievementsplus; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraftforge.common.IExtendedEntityProperties; public class ExtendedPlayer implements IExtendedEntityProperties { public final static String EXT_PROP_NAME = "Achievements+"; private final EntityPlayer player; private int cobblebrokenCount = 0; private int obsidianbrokenCount = 0; private int woodbrokenCount = 0; public ExtendedPlayer(EntityPlayer player) { this.player = player; this.cobblebrokenCount = 0; this.obsidianbrokenCount = 0; this.woodbrokenCount = 0; } public static final void register(EntityPlayer player) { player.registerExtendedProperties(ExtendedPlayer.EXT_PROP_NAME, new ExtendedPlayer(player)); } public static final ExtendedPlayer get(EntityPlayer player) { return (ExtendedPlayer) player.getExtendedProperties(EXT_PROP_NAME); } @Override public void saveNBTData(NBTTagCompound compound) { NBTTagCompound properties = new NBTTagCompound(); properties.setInteger("CobbleBroken", this.cobblebrokenCount); properties.setInteger("WoodBroken", this.woodbrokenCount); properties.setInteger("ObsidianBroken", this.obsidianbrokenCount); compound.setTag(EXT_PROP_NAME, properties); } @Override public void loadNBTData(NBTTagCompound compound) { NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME); this.cobblebrokenCount = properties.getInteger("CobbleBroken"); this.woodbrokenCount = properties.getInteger("WoodBroken"); this.obsidianbrokenCount = properties.getInteger("ObsidianBroken"); } @Override public void init(Entity entity, World world) { } //////Block checker methods public int increasecobbleCount() { this.cobblebrokenCount++; if (this.cobblebrokenCount == 10){return 4;} if (this.cobblebrokenCount == 9){return 3;} if (this.cobblebrokenCount == {return 2;} if (this.cobblebrokenCount == 7){return 1;} System.out.println(cobblebrokenCount); return 0; } public int increasewoodCount() { this.woodbrokenCount++; if (this.woodbrokenCount == 4){return 4;} if (this.woodbrokenCount == 3){return 3;} if (this.woodbrokenCount == 2){return 2;} if (this.woodbrokenCount == 1){return 1;} System.out.println(woodbrokenCount); return 0; } public int increaseobsidianCount() { this.obsidianbrokenCount++; if (this.obsidianbrokenCount == 80){return 4;} if (this.obsidianbrokenCount == 60){return 3;} if (this.obsidianbrokenCount == 40){return 2;} if (this.obsidianbrokenCount == 20){return 1;} System.out.println(obsidianbrokenCount); return 0; } } and the eventhandler calling it is here package achievementsplus; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.event.entity.EntityEvent.EntityConstructing; import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; import net.minecraftforge.event.world.BlockEvent.BreakEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class myEventHandler { @SubscribeEvent public void onApplePickup(LivingUpdateEvent event) { if (event.entityLiving instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer)event.entity; if (player.inventory.hasItem(Items.apple)) { System.out.println("SCRUB!"); player.addStat(AchievementsList.appleAchieve, 1); } } } @SubscribeEvent public void onBlockBreak(BreakEvent event) { EntityPlayer player = event.getPlayer(); ExtendedPlayer props = ExtendedPlayer.get(player); if (event.block == Blocks.stone && player.capabilities.isCreativeMode == false) { int count = props.increasecobbleCount(); if(count == 4){player.addStat(AchievementsList.cobbleAchieve4, 4);} if(count == 3){player.addStat(AchievementsList.cobbleAchieve3, 3);} if(count == 2){player.addStat(AchievementsList.cobbleAchieve2, 2);} if(count == 1){player.addStat(AchievementsList.cobbleAchieve1, 1);} } if (event.block == Blocks.obsidian && player.capabilities.isCreativeMode == false) { int count = props.increaseobsidianCount(); if(count == 4){player.addStat(AchievementsList.obsidianAchieve4, 4);} if(count == 3){player.addStat(AchievementsList.obsidianAchieve3, 3);} if(count == 2){player.addStat(AchievementsList.obsidianAchieve2, 2);} if(count == 1){player.addStat(AchievementsList.obsidianAchieve1, 1);} } if (event.block == Blocks.log && player.capabilities.isCreativeMode == false) { int count = props.increasewoodCount(); if(count == 4){player.addStat(AchievementsList.woodAchieve4, 4);} if(count == 3){player.addStat(AchievementsList.woodAchieve3, 3);} if(count == 2){player.addStat(AchievementsList.woodAchieve2, 2);} if(count == 1){player.addStat(AchievementsList.woodAchieve1, 1);} } } @SubscribeEvent public void onEntityConstructing(EntityConstructing event) { if (event.entity instanceof EntityPlayer && ExtendedPlayer.get((EntityPlayer) event.entity) == null) { ExtendedPlayer.register((EntityPlayer) event.entity); } } }
October 15, 201510 yr I'm pretty sure that's just the Eclipse test environment - unless you specify a username or full login, it gives you a semi-random username each time you launch the client, but it sounds like it uses the same player data file in the background regardless of user name. As I said, I haven't tested that, but your code looks like it should work fine. If you can, try running the test Server via Eclipse, then connect via both your computer and one other computer via LAN - each player should have their own IEEP data. http://i.imgur.com/NdrFdld.png[/img]
October 15, 201510 yr Author Ah ok. Upon opening a LAN server and having another test client join it seems to be working properly for them. Thanks for your help!
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.