Jump to content

[1.12.2] Items don't drop when I break my custom chest [SOLVED]


Recommended Posts

Posted (edited)

Hello, I'm codding for only a week ago new, so I'm kind of nww for the moment :)

 

It's been 10 hours between yesterday and today that i don't succed to find out why I don't get the content of my custom chest (yes, I make my tests on blocks called FakeBlock first ^^) when I use BreakBlock.

 

Here is my block

  Reveal hidden contents

 

Its TileEntity

  Reveal hidden contents

 

and its Container, even if I don't think the problem comes from it

  Reveal hidden contents

 

 

I'm almost sure the problem comes from the way i write my items in TileEntity, but whenever I try another method my items just disseapear when I log out ^^

 

if anyone can help me that would be nice :)

thank in advance ;)

Edited by sunsigne
solved
Posted
  On 1/21/2019 at 7:02 AM, sunsigne said:

private NonNullList<ItemStack> fakeblockConstents = NonNullList.<ItemStack>withSize(SIZE, ItemStack.EMPTY);
        public static final int SIZE = 8;

Expand  

Use ItemStackHandler instead of this

  On 1/21/2019 at 7:02 AM, sunsigne said:

ITileEntityProvider, IHasModel

Expand  

Don’t do this

  On 1/21/2019 at 7:02 AM, sunsigne said:

@Override
    public void registerModels()
    {
    
        MyMod.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
    }
    
    
    @SideOnly(Side.CLIENT)
    public void initModel() {
        ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
    }

Expand  

Don’t do this

  On 1/21/2019 at 7:02 AM, sunsigne said:

FakeBlockTileEntity tileentity = (FakeBlockTileEntity) worldIn.getTileEntity(pos);

       if (tileentity != null)
       {
          InventoryHelper.dropInventoryItems(worldIn, pos, tileentity);
       }

       super.breakBlock(worldIn, pos, state);

Expand  

You should check for null before casting. What does InventoryHelper#dropInventoryItems do?

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted (edited)

 

  On 1/21/2019 at 10:46 AM, Cadiboo said:

Don’t do this

Don’t do this

You should check for null before casting

Expand  

It's nice to try to help me :)

but has i spent 10 hours you can guess i already tried a lot of things and if you aren't more precise in your explanations i'll just revolve around the problem.

 

I deleted the parts you dislike, but if i remove NonNullList from my tile entity (and everything assiociated) i just get a new problem in my FakeBlock

 

TileEntity

  Reveal hidden contents

 

FakeBlock : the problem is there

  Reveal hidden contents

Now it says "The method dropInventoryItems(World, BlockPos IInventory) in the type InventoryHelper is not applicable for the arguments (World, BlockPos, FakeBlockTileEntity).

That's why I used NonNullList in the first case.

Edited by sunsigne
More precision
Posted

In the breakBlock method, loop through the inventory's slots. Create a new EntityItem in the for loop and then call spawnAsEntity. I think InventoryHelper#dropInventoryItems wants an IInventory, which probably won't work in your case. This is somewhat how I did it, and I use ItemStackHandler.

  • Thanks 1
Posted (edited)
  On 1/21/2019 at 6:20 PM, Siqhter said:

In the breakBlock method, loop through the inventory's slots. Create a new EntityItem in the for loop and then call spawnAsEntity. I think InventoryHelper#dropInventoryItems wants an IInventory, which probably won't work in your case. This is somewhat how I did it, and I use ItemStackHandler.

Expand  

 

You are my HERO ! It worked !

 

for curious people, here is the new BreakBlock part :

  Reveal hidden contents

 

I guess i'll never know why "dropitem" didn't work, but as lon as my items still "dropped" i don't really care ^^

 

Have a nice day ;)

 

 

 

 

A little (maybe stupid) question. How do i mark a topic as "solved" ? It's been 20 minutes i'm searching but not finding ^^

Edited by sunsigne
How to solve a topic ?
Posted

You can edit your original post and add “[SOLVED] “ to the title.

 

Here is an example of how I drop my items https://github.com/Cadiboo/WIPTechAlpha/blob/fb5883e9d76ef0361ec1ebbcb9c508611dd2ef6b/src/main/java/cadiboo/wiptech/capability/inventory/ModItemStackHandler.java#L23-L35

You still need to

- Not use ITileEntityProvider: It is legacy vanilla code, simply override hasTileEntity and createTileEntity.

- Not use IHasModel: It is a stupid way of registering things that makes you write the exact same lines of code for ever class, it is unneeded and a better result can be achieved with 1 single line of code.

- Check for null before using the tile entity you get from world#getTileEntity

- Check that the tile entity you get from world#getTileEntity actually is an instance of your tile entity before you cast it (when the block is replaced, a structure is loaded on top of it, commands like /fill, /clone or /setblock are used, or even if the server is just overloaded, it might not be an instance of your tile entity)

  • Like 1

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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.