Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted

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?

Posted

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.

Posted

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

Posted

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);

 

}

 

}

 

}

 

Posted

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.

Posted

Never mind I put it in the wrong class :P 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 :)

Posted

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);

    }

 

 

 

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.