Posted June 23, 201411 yr I have mod with a level and an xp field set up. These need to be saved when the player leaves the world otherwise they just revert back to their defaults of 1 and 0.
June 23, 201411 yr Looked up ExtendedEntityProperties. Long time Bukkit & Forge Programmer Happy to try and help
June 23, 201411 yr And if you want to keep it persistent over death, look into EntityPlayer.PERSISTANT_TAG (or something similar), EntityJoinWorldEvent and LivingDeathEvent. We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 23, 201411 yr Author Okay I have set this up and I believe it to be correct, but I am not sure what to do from now. I want the xp to increase everytime the mob attacks, any ideas?
June 23, 201411 yr Use the event LivingAttackEvent. Then, check to see if event.entity an instance of the mob you want. If it is, add experience to the mob. Or add the XP to the player if that's what you are trying to do. We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 23, 201411 yr Use spoilers around your code. Notice the "Sp" button right above. In your error log, it will tell you what line of your code is offending. Tell us that so we don't have to read the entire thing and guess. Long time Bukkit & Forge Programmer Happy to try and help
June 23, 201411 yr Author Is this what you meant... Here is the line the error occurs at on its own: this.xp = properties.getInteger("xp"); Here is the crash: [21:38:03] [server thread/ERROR] [FML]: Failed to load extended properties for BlocklingXP. This is a mod issue. java.lang.NullPointerException at com.blocklings.stats.BlocklingStats.loadNBTData(BlocklingStats.java:56) at net.minecraft.entity.Entity.readFromNBT(Entity.java:1642) at net.minecraft.entity.EntityList.createEntityFromNBT(EntityList.java:190) at net.minecraft.world.chunk.storage.AnvilChunkLoader.readChunkFromNBT(AnvilChunkLoader.java:416) at net.minecraft.world.chunk.storage.AnvilChunkLoader.checkedReadChunkFromNBT(AnvilChunkLoader.java:108) at net.minecraft.world.chunk.storage.AnvilChunkLoader.loadChunk(AnvilChunkLoader.java:88) at net.minecraft.world.gen.ChunkProviderServer.safeLoadChunk(ChunkProviderServer.java:179) at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:120) at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:307) at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:79) at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:96) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:442) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:746) Here is the whole class: package com.blocklings.stats; import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraftforge.common.IExtendedEntityProperties; import net.minecraftforge.event.entity.living.LivingAttackEvent; import com.blocklings.entity.EntityBlockling; import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class BlocklingStats implements IExtendedEntityProperties { public final static String EXT_PROP_NAME = "BlocklingXP"; public EntityBlockling blockling; public int xp; public boolean attacking; public BlocklingStats(EntityBlockling blockling) { this.blockling = blockling; this.xp = 0; } public static final void register(EntityBlockling blockling) { blockling.registerExtendedProperties(BlocklingStats.EXT_PROP_NAME, new BlocklingStats(blockling)); } public static final BlocklingStats get(EntityBlockling entity) { return (BlocklingStats) entity.getExtendedProperties(EXT_PROP_NAME); } @Override public void saveNBTData(NBTTagCompound compound) { NBTTagCompound properties = new NBTTagCompound(); properties.setInteger("xp", this.xp); compound.setTag(EXT_PROP_NAME, properties); } @Override public void loadNBTData(NBTTagCompound compound) { NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME); this.xp = properties.getInteger("xp"); System.out.println("[TUT PROPS] Mana from NBT: " + this.xp); } @Override public void init(Entity entity, World world) { } @SubscribeEvent public void onEntityAttacking(LivingAttackEvent event) { if(event.entity instanceof EntityBlockling) { xp++; System.out.println(xp); } } }
June 23, 201411 yr Author Okay, got that error fixed. Now I have added... @SubscribeEvent public void onEntityAttacking(LivingAttackEvent event) { if(event.entity instanceof EntityBlockling) { xp++; System.out.println(xp); } } ...to my properties class but it isn't being called.
June 23, 201411 yr >.> why... Well, did you register the event? We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 23, 201411 yr Author Never mind I put it in the wrong class I will play around with this for a bit and will come back if I hit another problem I can't solve. Thank you all for your help
June 24, 201411 yr Good job and your welcome We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 24, 201411 yr Author Okay I have set up the class and I believe it works, but I am wondering how I would use my getXP() method inside my EntityBlockling class's interact() method that I have. public boolean interact(EntityPlayer par1EntityPlayer) { ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem(); if (itemstack != null && itemstack.getItem() == Item.getItemFromBlock(Blocks.red_flower)) { if (!par1EntityPlayer.capabilities.isCreativeMode) { --itemstack.stackSize; } if (itemstack.stackSize <= 0) { par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, (ItemStack)null); } if (par1EntityPlayer.getCommandSenderName().equalsIgnoreCase(this.getOwnerName()) && !this.worldObj.isRemote) { this.aiSit.setSitting(!this.isSitting()); this.isJumping = false; this.setPathToEntity((PathEntity)null); this.setTarget((Entity)null); this.setAttackTarget((EntityLivingBase)null); onLevelUp(); FMLClientHandler.instance().getClient().ingameGUI.getChatGUI().printChatMessage(new ChatComponentText("XP: " + Integer.toString(xp) + "/256" + " | " + "Level: " + Integer.toString(level)+ " | " + "Health: " + Float.toString(currentHealth) + "/" + this.getEntityAttribute(SharedMonsterAttributes.maxHealth))); } if (!this.worldObj.isRemote && !this.isTamed()) { if (this.rand.nextInt(3) == 0) { this.setTamed(true); this.setPathToEntity((PathEntity)null); this.setAttackTarget((EntityLivingBase)null); this.setOwner(par1EntityPlayer.getCommandSenderName()); this.playTameEffect(true); this.aiSit.setSitting(!this.isSitting()); this.worldObj.setEntityState(this, (byte)7); } else { this.playTameEffect(false); this.worldObj.setEntityState(this, (byte)6); } } return true; } return super.interact(par1EntityPlayer); }
June 24, 201411 yr Please read the second post on this topic http://www.minecraftforum.net/topic/1952901-172164-eventhandler-and-iextendedentityproperties/ . Can confirm the whole thing works in 1.7.10-pre4 with no changes.
June 24, 201411 yr Author Thanks, I have figured it out now and I think I am all set. I have tested and it seems to work just as I wanted
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.