Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.13.2] Tile Entity items not saved
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
MyRedAlien43

[1.13.2] Tile Entity items not saved

By MyRedAlien43, May 13 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

MyRedAlien43    0

MyRedAlien43

MyRedAlien43    0

  • Tree Puncher
  • MyRedAlien43
  • Members
  • 0
  • 20 posts
Posted May 13 (edited)

So, I made a tile entity that stores items, it works and all of that but the only problem is that it doesn't save the contents. My read and write methods:

@Override
public void read(NBTTagCompound compound) {
	super.read(compound);
  	this.handler = new ItemStackHandler(this.getSizeInventory());
  	this.handler.deserializeNBT(compound.getCompound("inventory"));
  	if(compound.contains("CustomName", 8)) {
    	this.customName = ITextComponent.Serializer.fromJson(compound.getString("CustomName"));
    }
}

@Override
public NBTTagCompound write(NBTTagCompound compound) {
	super.write(compound);
	compound.setTag("inventory", this.handler.serializeNBT());
	if(this.hasCustomName()) {
		compound.setString("CustomName", 	ITextComponent.Serializer.toJson(customName));
	}
    return compound;
}

(What the handler is:)

public ItemStackHandler handler = new ItemStackHandler(9);

And I get no error. After I rejoin the items I put in just disappear like they were never saved (or loaded).

Edited May 13 by MyRedAlien43
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6688

diesieben07

diesieben07    6688

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6688
  • 45727 posts
Posted May 13
  • Do not replace the handler with a new instance when reading from NBT.
  • Do not use hardcoded magic numbers for NBT Type-IDs. Use the constants in Constants.NBT.
  • What is getSizeInventory? Are you implementing IInventory? If so, don't.
  • Like 1
  • Quote

Share this post


Link to post
Share on other sites

MyRedAlien43    0

MyRedAlien43

MyRedAlien43    0

  • Tree Puncher
  • MyRedAlien43
  • Members
  • 0
  • 20 posts
Posted May 13
11 minutes ago, diesieben07 said:
  • What is getSizeInventory? Are you implementing IInventory? If so, don't.

I extended TileEntityLockable, so thanks. But now when I try to open the tile entity it does nothing.

 

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6688

diesieben07

diesieben07    6688

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6688
  • 45727 posts
Posted May 13
18 minutes ago, MyRedAlien43 said:

I extended TileEntityLockable, so thanks

That means you are implementing IInventory. Don't.

 

Show where you open the GUI of your block.

  • Quote

Share this post


Link to post
Share on other sites

MyRedAlien43    0

MyRedAlien43

MyRedAlien43    0

  • Tree Puncher
  • MyRedAlien43
  • Members
  • 0
  • 20 posts
Posted May 13 (edited)
4 minutes ago, diesieben07 said:

That means you are implementing IInventory. Don't.

 

Show where you open the GUI of your block.

Yea, I meant I now extend only TileEntity.

@Override
	public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
		if (worldIn.isRemote) {
			return true;
		} else {
			TileEntity tileentity = worldIn.getTileEntity(pos);
			if (tileentity instanceof TileEntityBarrel && player instanceof EntityPlayerMP) {
				TileEntityBarrel barrel = (TileEntityBarrel)tileentity;
				NetworkHooks.openGui((EntityPlayerMP)player, barrel);
			}

			return true;
		}
	}

I don't know if this is correct. Also, my block does NOT extend BlockContainer

Edited May 13 by MyRedAlien43
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6688

diesieben07

diesieben07    6688

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6688
  • 45727 posts
Posted May 13

Show where you registered your Gui factory and your implementation of IInteractionObject (your tile entity, judging from your code above).

  • Quote

Share this post


Link to post
Share on other sites

MyRedAlien43    0

MyRedAlien43

MyRedAlien43    0

  • Tree Puncher
  • MyRedAlien43
  • Members
  • 0
  • 20 posts
Posted May 13
1 minute ago, diesieben07 said:

implementation of IInteractionObject (your tile entity, judging from your code above).

@Override
    public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) {
        return new ContainerBarrel(playerInventory, this, playerIn);
    }

    @Override
    public String getGuiID() {
        return "moresimplestuff:barrel";
    }

 

1 minute ago, diesieben07 said:

Show where you registered your Gui factory

IGuiHandler?

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6688

diesieben07

diesieben07    6688

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6688
  • 45727 posts
Posted May 13

IGuiHandler is not used in 1.13.2.

Your GUI factory is registered through ModLoadingContext#registerExtensionPoint with ExtensionPoint.GUIFACTORY.

  • Quote

Share this post


Link to post
Share on other sites

MyRedAlien43    0

MyRedAlien43

MyRedAlien43    0

  • Tree Puncher
  • MyRedAlien43
  • Members
  • 0
  • 20 posts
Posted May 13 (edited)
2 minutes ago, diesieben07 said:

IGuiHandler is not used in 1.13.2.

Your GUI factory is registered through ModLoadingContext#registerExtensionPoint with ExtensionPoint.GUIFACTORY.

Ohh that makes sense. Mind showing me how to do so? Sorry, 1.13.2 is new to me.

Edited May 13 by MyRedAlien43
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6688

diesieben07

diesieben07    6688

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6688
  • 45727 posts
Posted May 13

I just did...?

  • Quote

Share this post


Link to post
Share on other sites

MyRedAlien43    0

MyRedAlien43

MyRedAlien43    0

  • Tree Puncher
  • MyRedAlien43
  • Members
  • 0
  • 20 posts
Posted May 13
1 minute ago, diesieben07 said:

I just did...?

Oh god this wasn't what I meant... I also don't want to turn this into a tutorial either.

What I meant was, What does the Gui Factory have to extend/implement or method to have?

  • Quote

Share this post


Link to post
Share on other sites

desht    73

desht

desht    73

  • Creeper Killer
  • desht
  • Members
  • 73
  • 205 posts
Posted May 13

You should take a careful read of the 1.12 -> 1.13/1.14 update primer linked at the top of this forum.  In particular, this comment will be helpful to you: https://gist.github.com/williewillus/353c872bcf1a6ace9921189f6100d09a#gistcomment-2870154

 

Regarding your original problem (TE data not saving), are you marking the tile entity dirty when the inventory changes?  If not, your changes won't get saved. Best bet is to override the onSlotChanged() method of your ItemStackHandler object to call te.markDirty().

  • Thanks 1
  • Quote

Share this post


Link to post
Share on other sites

MyRedAlien43    0

MyRedAlien43

MyRedAlien43    0

  • Tree Puncher
  • MyRedAlien43
  • Members
  • 0
  • 20 posts
Posted May 13
1 minute ago, desht said:

You should take a careful read of the 1.12 -> 1.13/1.14 update primer linked at the top of this forum.  In particular, this comment will be helpful to you: https://gist.github.com/williewillus/353c872bcf1a6ace9921189f6100d09a#gistcomment-2870154

Thank you very much! This is exactly what I needed.

  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • diesieben07
      Memory Heap Thingy!

      By diesieben07 · Posted 2 hours ago

      That's not what this thread is about... Make your own thread and post logs.
    • gudie73
      Memory Heap Thingy!

      By gudie73 · Posted 3 hours ago

      It gets stuck on that part and doesn’t change
    • gudie73
      Memory Heap Thingy!

      By gudie73 · Posted 3 hours ago

      Wym  
    • RaphGamingz
      ScreenGui does nothing

      By RaphGamingz · Posted 3 hours ago

      any errors?
    • RaphGamingz
      Game crashing when the block is activated

      By RaphGamingz · Posted 3 hours ago

      then you    your not assigning a value to the tileEntity try in the constructor tileEntity = world.getTileEntity(pos);
  • Topics

    • Mizinov
      7
      Memory Heap Thingy!

      By Mizinov
      Started August 24

    • Jaffaaaaa
      2
      ScreenGui does nothing

      By Jaffaaaaa
      Started Wednesday at 07:03 PM

    • jun2040
      5
      Game crashing when the block is activated

      By jun2040
      Started 20 hours ago

    • Merthew
      5
      [1.12.2] Multiple Structure Generation

      By Merthew
      Started November 7, 2018

    • Professional Derp
      16
      Server frequently crashes

      By Professional Derp
      Started 13 hours ago

  • Who's Online (See full list)

    • DragonITA
    • MarkNutt0
    • crackedEgg
    • Ugdhar
    • Neverless013
    • Yanny7
    • saxon564
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.13.2] Tile Entity items not saved
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community