Jump to content

Recommended Posts

Posted

So I've been experimenting with IInventory, with the hopes of eventually making a custom size chest, and I came about with the following code.  From my, limited, understanding, I thought that this would allow me to create a block that will store items.  Of course, there's no GUI for it right now, but I thought that I attached hoppers to the block, and then drop items into it, those items would be stored in the block.  Sadly, this is not the case.  I'm basically knifing in the dark here, and I am open to suggestions.

 

Here's the code for the RedChestBlock class:

 

http://pastebin.com/wR2aDZiZ

 

And the code for the RedChestTileEntity class:

 

http://pastebin.com/EE63wT1z

 

And finally, the code for the Main class:

 

http://pastebin.com/2NdcKP9q

 

Thank you for your time.

Posted

So I've been experimenting with IInventory, with the hopes of eventually making a custom size chest, and I came about with the following code.  From my, limited, understanding, I thought that this would allow me to create a block that will store items.  Of course, there's no GUI for it right now, but I thought that I attached hoppers to the block, and then drop items into it, those items would be stored in the block.  Sadly, this is not the case.  I'm basically knifing in the dark here, and I am open to suggestions.

 

Here's the code for the RedChestBlock class:

 

http://pastebin.com/wR2aDZiZ

 

And the code for the RedChestTileEntity class:

 

http://pastebin.com/EE63wT1z

 

And finally, the code for the Main class:

 

http://pastebin.com/2NdcKP9q

 

Thank you for your time.

Posted

I can't see any obvious errors in your code, try stepping through the

IInventory

methods or the NBT reading/writing methods in a debugger and see if anything goes wrong.

 

Side note: You shouldn't be using

IInventory

in 1.8.9+, you should be using the

IItemHandler

capability.

 

I have an example of a chest that uses

IItemHandler

here (all other classes used are in the same repository). This includes the naming and loot generation features of vanilla chests, but not the animated model.

 

You also shouldn't be using the deprecated

GameRegistry.registerBlock

or registering your blocks in init. Use

GameRegistry.register

in preInit to register all

IForgeRegistryEntry

implementations (e.g.

Block

,

Item

,

Biome

,

SoundEvent

). This won't register an

ItemBlock

for your

Block

, you need to do that yourself.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I can't see any obvious errors in your code, try stepping through the

IInventory

methods or the NBT reading/writing methods in a debugger and see if anything goes wrong.

 

Side note: You shouldn't be using

IInventory

in 1.8.9+, you should be using the

IItemHandler

capability.

 

I have an example of a chest that uses

IItemHandler

here (all other classes used are in the same repository). This includes the naming and loot generation features of vanilla chests, but not the animated model.

 

You also shouldn't be using the deprecated

GameRegistry.registerBlock

or registering your blocks in init. Use

GameRegistry.register

in preInit to register all

IForgeRegistryEntry

implementations (e.g.

Block

,

Item

,

Biome

,

SoundEvent

). This won't register an

ItemBlock

for your

Block

, you need to do that yourself.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I edited the code using IItemHandler, but it's still not working.  Note that I did not stop using the depreciated registerBlock, as I wanted to focus on getting this handled first before adding more classes.  If there's still nothing visably wrong, then I'll start debugging line-by-line.

 

Here's the RedChestTileEntity code:

 

http://pastebin.com/EE63wT1z

 

And the RedChestBlock code:

 

http://pastebin.com/wR2aDZiZ

 

And finally, the Main code:

 

http://pastebin.com/2NdcKP9q

Posted

I edited the code using IItemHandler, but it's still not working.  Note that I did not stop using the depreciated registerBlock, as I wanted to focus on getting this handled first before adding more classes.  If there's still nothing visably wrong, then I'll start debugging line-by-line.

 

Here's the RedChestTileEntity code:

 

http://pastebin.com/EE63wT1z

 

And the RedChestBlock code:

 

http://pastebin.com/wR2aDZiZ

 

And finally, the Main code:

 

http://pastebin.com/2NdcKP9q

Posted

Don't implement

IItemHandler

on your

TileEntity

, create a field storing an implementation of it (e.g.

ItemStackHandler

) and expose it as a capability (by overriding the

ICapabilityProvider

methods inherited by

TileEntity

). I do this in

[url=https://github.com/Choonster/TestMod3/blob/d326040ffd81cf942de5ddaebc9c5ed866f1dd33/src/main/java/com/choonster/testmod3/tileentity/TileEntityItemHandler.java]TileEntityItemHandler[/url]

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Don't implement

IItemHandler

on your

TileEntity

, create a field storing an implementation of it (e.g.

ItemStackHandler

) and expose it as a capability (by overriding the

ICapabilityProvider

methods inherited by

TileEntity

). I do this in

[url=https://github.com/Choonster/TestMod3/blob/d326040ffd81cf942de5ddaebc9c5ed866f1dd33/src/main/java/com/choonster/testmod3/tileentity/TileEntityItemHandler.java]TileEntityItemHandler[/url]

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
... create a field storing an implementation of it (e.g. ItemStackHandler) and expose it as a capability (by overriding the ICapabilityProvider methods inherited by TileEntity).

 

I'm sorry, but I don't quite understand how to do this.  I understand the concept of overriding the ICapabilityProvider methods inherited by TileEntity to expose the implementation as a capability, but I don't know how to create a field storing an implementation of ItemStackHandler.

Posted
... create a field storing an implementation of it (e.g. ItemStackHandler) and expose it as a capability (by overriding the ICapabilityProvider methods inherited by TileEntity).

 

I'm sorry, but I don't quite understand how to do this.  I understand the concept of overriding the ICapabilityProvider methods inherited by TileEntity to expose the implementation as a capability, but I don't know how to create a field storing an implementation of ItemStackHandler.

Posted

I believe Choonster means make it a field.

 

public class TE extends TileEntity {
    ItemStackHandler myStacks;
}

 

I could be wrong though, but that's how I read it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I believe Choonster means make it a field.

 

public class TE extends TileEntity {
    ItemStackHandler myStacks;
}

 

I could be wrong though, but that's how I read it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

You never initialise the

myStacks

field. You also never read it from or write it to NBT, do this using the

INBTSerializable

methods implemented by

ItemStackHandler

.

 

I suggest you remove the

ItemStack

array field and the

IInventory

methods.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

You never initialise the

myStacks

field. You also never read it from or write it to NBT, do this using the

INBTSerializable

methods implemented by

ItemStackHandler

.

 

I suggest you remove the

ItemStack

array field and the

IInventory

methods.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I've updated the code by initializing the myStacks field, as well as editing the writeToNBT and readFromNBT methods to use the INBTSerializable methods implemented by ItemStackHandler.  Unfortunately, the block still does not hold any items when I try to add items to the block by using a hopper.

 

Here's the RedChestTileEntity class:

 

http://pastebin.com/EE63wT1z

 

And the RedChestBlock class:

 

http://pastebin.com/wR2aDZiZ

 

And finally, the Main class:

 

http://pastebin.com/2NdcKP9q

Posted

I've updated the code by initializing the myStacks field, as well as editing the writeToNBT and readFromNBT methods to use the INBTSerializable methods implemented by ItemStackHandler.  Unfortunately, the block still does not hold any items when I try to add items to the block by using a hopper.

 

Here's the RedChestTileEntity class:

 

http://pastebin.com/EE63wT1z

 

And the RedChestBlock class:

 

http://pastebin.com/wR2aDZiZ

 

And finally, the Main class:

 

http://pastebin.com/2NdcKP9q

Posted

RedChestBlock#createTileEntity

creates a new

CrateTileEntity

, not a

RedChestTileEntity

.

 

Side note: The standard naming convention used by MCP (in vanilla code) and most mods is to have the parent class as a prefix rather than a suffix (e.g.

TileEntityRedChest

, not

RedChestTileEntity

). I'd recommend following this convention, though it's not required.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

RedChestBlock#createTileEntity

creates a new

CrateTileEntity

, not a

RedChestTileEntity

.

 

Side note: The standard naming convention used by MCP (in vanilla code) and most mods is to have the parent class as a prefix rather than a suffix (e.g.

TileEntityRedChest

, not

RedChestTileEntity

). I'd recommend following this convention, though it's not required.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I updated the code so that a TileEntityRedChest is created, and not a TileEntityCrate. (Honestly, I can't believe I missed that).  I also did some refactoring of the names of the classes for clarity.  However, the block still does not hold any items when I try to add items to the block by using a hopper.

 

Here's the TileEntityRedChest class:

 

http://pastebin.com/WucCAgcy

 

And the BlockRedChest class:

 

http://pastebin.com/cXUjshQ6

 

And finally, the Main class:

 

http://pastebin.com/2NdcKP9q

Posted

I updated the code so that a TileEntityRedChest is created, and not a TileEntityCrate. (Honestly, I can't believe I missed that).  I also did some refactoring of the names of the classes for clarity.  However, the block still does not hold any items when I try to add items to the block by using a hopper.

 

Here's the TileEntityRedChest class:

 

http://pastebin.com/WucCAgcy

 

And the BlockRedChest class:

 

http://pastebin.com/cXUjshQ6

 

And finally, the Main class:

 

http://pastebin.com/2NdcKP9q

Posted

I copied your code into a fresh 1.9.4-12.17.0.1922-1.9.4 MDK, updated it to 1.9.4 (made

TileEntityRedChest#writeToNBT

return

NBTTagCompound

, renamed

BlockRedChest#onBlockEventReceived

to

eventReceived

and

CreativeTabs.tabBlock

to [TT]CreativeTabs.BUILDING_BLOCKS[/TT]) and hoppers could put items in and take items out without issue.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I copied your code into a fresh 1.9.4-12.17.0.1922-1.9.4 MDK, updated it to 1.9.4 (made

TileEntityRedChest#writeToNBT

return

NBTTagCompound

, renamed

BlockRedChest#onBlockEventReceived

to

eventReceived

and

CreativeTabs.tabBlock

to [TT]CreativeTabs.BUILDING_BLOCKS[/TT]) and hoppers could put items in and take items out without issue.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
...made TileEntityRedChest#writeToNBT return NBTTagCompound, renamed BlockRedChest#onBlockEventReceived to eventReceived...

 

I don't quite understand. The writeToNBT method in the TileEntity super class returns void, and there is no

eventReceived method in the Block class...

 

 

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.