Jump to content

Recommended Posts

Posted (edited)

Hello, I have begun creating my first mod which I am mostly using as a testing grounds to become familiar with the different things Forge is capable of.

Currently I've only created very simple blocks with crafting recipes, loot tables, texturing, etc. As of the past 24 hours or so, I've been trying to understand how to create Tile Entities, specifically chests.

Through my reading of the Forge Docs, I've concluded that it requires a a TileEntity inheritance, and an implementation of IItemHandler and/or ICapabilityProvider. I feel as if I've found some or all of the correct pieces to the puzzle, but I am unsure of how they fit together.

I believe I've created a block that is technically a Tile Entity but has no functionality or GUI with the following code:
 

public class ChestBlock extends BlockBase
{
	public ChestBlock(Properties properties, String registryName)
	{
		super(properties, registryName);
	}

	@Override
	public boolean hasTileEntity(BlockState state)
	{
		return true;
	}

	@Nullable
	@Override
	public TileEntity createTileEntity(BlockState state, IBlockReader world)
	{
		return new TestTileEntity();
	}
}

 

public class TestTileEntity extends TileEntity
{
	private NonNullList<ItemStack> chestContents;

	public TestTileEntity(TileEntityType<?> tileEntityTypeIn)
	{
		super(tileEntityTypeIn);
	}

	public TestTileEntity()
	{
		this(TileEntityLibrary.TEST_CHEST);
	}

	@Override
	public CompoundNBT write(CompoundNBT compound)
	{
		return super.write(compound);
	}

	@Override
	public void read(CompoundNBT compound)
	{
		super.read(compound);
	}
}

 

I've looked at some open source mods for guidance, but those I have looked at are rather complex and consist of many custom classes and implementations for inventories. I would just like to know what are the absolute most basic requirements for creating a custom chest. I do not need sided, orientation, animations, modeling, or any other functionality simply than being able to right click a block, it opens a GUI, and that tile entity is able to receive an ItemStack and properly sync it.

 

If you need any more snippets of my code, please simply ask.

 

Thank you.

Edited by TheHolyChase

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.