Jump to content

Recommended Posts

Posted

I wrote this code:

CustomPlayer.java

  Reveal hidden contents

 

 

CustomPlayerInventory.java

  Reveal hidden contents

 

 

CustomPlayerContainer.java

  Reveal hidden contents

 

according to https://github.com/coolAlias/Forge_Tutorials/blob/master/CustomPlayerInventory.java, but I get this error in console:

  Reveal hidden contents

and empty inventory. So, my question is: Are extended properties saved while exitting world? While I don't exit world, items are saved(or displayed as saved; for now I can't test it)

Posted

save/loadNBTData methods are called whenever Entity, IEEP is assigned to, is saved to NBT - that happens when world is dumped on disk, and that happens (actual saving) every "some" ticks or "special actions" - e.g: when on SP and you go to menu, world will be saved.

 

So yes - IEEP is saved inside Entity which is saved inside World.

 

Now, after actually looking at code:

YOU DON'T call save/load yourself. Never ever.

This is all you need:

public class CustomPlayer implements IExtendedEntityProperties {
    public final static String EXT_PROP_NAME = "CustomPlayer";
    private final EntityPlayer player;
    public CustomPlayerInventory inventory;

    public CustomPlayer(EntityPlayer player) {
        this.player = player;

    }

    public static void register(EntityPlayer player) {
        player.registerExtendedProperties(CustomPlayer.EXT_PROP_NAME, new CustomPlayer(player));
    }

    public static CustomPlayer get(EntityPlayer player) {
        return (CustomPlayer) player.getExtendedProperties(EXT_PROP_NAME);
    }

    @Override
    public void saveNBTData(NBTTagCompound compound) {
        compound.setInteger("size", inventory.getSomeSize());
    }

    @Override
    public void loadNBTData(NBTTagCompound compound) {
        this.inventory = new CustomPlayerInventory(compound.getInteger("size"));
    }

    @Override
    public void init(Entity entity, World world) {
    }
}

 

Obviously in "load" you need to also call inventory.loadFromNBT(parentCompound.getCompoundTag("invTag")).

Same (reversed) goes for saving.

 

Additional note: as of 1.8.9+ IEEP is no longer a thing, use Capabilities.

  Quote

1.7.10 is no longer supported by forge, you are on your own.

Posted
  On 4/9/2016 at 10:14 PM, Ernio said:

save/loadNBTData methods are called whenever Entity, IEEP is assigned to, is saved to NBT - that happens when world is dumped on disk, and that happens (actual saving) every "some" ticks or "special actions" - e.g: when on SP and you go to menu, world will be saved.

 

So yes - IEEP is saved inside Entity which is saved inside World.

 

But only if you override the save / load methods properly.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

I tried to edit it, but I get this list of errors:

 

  Reveal hidden contents

 

and then it crashes with IndexOutOfBoundsException. I don't understand why it call setInventorySlotContents() more than 8 times. Can you explain how it works, because I couldn't get any info from stacktrace, please?

Posted

Thanks for help. I found my bug. it was in

  Reveal hidden contents

Posted

Dude... You have no idea what you are doing, do you? :) Just because it works doesn't mean is is written properly. Post your whole code.

 

compound.getId() return integer-type of NBT where NBTTagCompound equals 10.

compound.getTagList("list",  nbtTypeOfListElements); - as you can see, yeah, it will cover with 10 since list is NBTTagCompound-based, but if the list was e.g: Strings, then what?

  Quote

1.7.10 is no longer supported by forge, you are on your own.

Posted

 

  Reveal hidden contents

 

 

  Reveal hidden contents

 

 

  Reveal hidden contents

 

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.