Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hey everyone,

I am triing to start getting used to the new Capabilities system.

I am triing to create my own TileEntity with an Capabilitie, instead of IInventory.

And even after reading the page about it I am TOTALLY confused.

Do I need to create my TileEntity and make it an ICapabilityProvider?

  • Author

If I see this right I need to manually save it right?

 

public abstract class TileEntityInventoryProvider extends TileEntity{

private ItemStackHandler handler;

private static final String INVENTORY_KEY = "beeverutils.inventory";
protected abstract int getSize();

public TileEntityInventoryProvider() {
	handler = new ItemStackHandler(getSize());
}

@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
	if(capability==CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return true;
	return false;
}

@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
	// TODO Auto-generated method stub
	return (T)handler;
}

@Override
public void writeToNBT(NBTTagCompound compound) {
	super.writeToNBT(compound);
	compound.setTag(INVENTORY_KEY, handler.serializeNBT());
}

@Override
public void readFromNBT(NBTTagCompound compound) {
	super.readFromNBT(compound);
	handler.deserializeNBT((NBTTagCompound) compound.getTag(INVENTORY_KEY));
}

}

public abstract class TileEntityInventoryProvider extends TileEntity{ // Why is this abstract?

private ItemStackHandler handler; // IItemHandler, better to use the interface itself

private static final String INVENTORY_KEY = "beeverutils.inventory";
protected abstract int getSize();

public TileEntityInventoryProvider() {
	handler = new ItemStackHandler(getSize()); // You should wrap this in a if (IITEM_CAP != null)
}

@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
	if(capability==CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return true;
	return false; // be sure to return super else added capabilities or parents won't work
}

@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
	// TODO Auto-generated method stub
	return (T)handler;  // be sure to return super else added capabilities or parents won't work
	// Also you NEED to test what the capability and side is so that you don't return your IItemHandler when it asks you for an IEnergyData or something like that.
}

@Override
public void writeToNBT(NBTTagCompound compound) {
	super.writeToNBT(compound);
	compound.setTag(INVENTORY_KEY, handler.serializeNBT());
}

@Override
public void readFromNBT(NBTTagCompound compound) {
	super.readFromNBT(compound);
	handler.deserializeNBT((NBTTagCompound) compound.getTag(INVENTORY_KEY));
}

}

This stuff is fairly simple, and we have examples in Forge.... Not sure why people are getting so confused.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

  • Author

Well. I dont see any example of using a capability, and the tutorial from readthedocs is seriously hard to read.

Im just having problems because im just like "oh yeah that piece of code looks awesome but I dont really see where I use it".

But thats obviously also my problem because I kinda hate text tutorials.

Take these with a rain of salt code-style wise as they are patches but:

Furnaces

Chests

BrewingStands

 

This is my original test code which shows my intention of how modders should so it with Caps that Forge/They don't provide {Doing it this way gives soft-dependencies}

https://github.com/LexManos/MinecraftForge/blob/Capabilities/patches/minecraft/net/minecraft/tileentity/TileEntityFurnace.java.patch#L58

This shows my original test code which creates, and queries a TE for it's capability:

https://github.com/LexManos/MinecraftForge/blob/Capabilities/src/test/java/net/minecraftforge/test/capabilitytest/TestCapabilityMod.java#L27-L62

 

It's not to difficult. Someone write better docs.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.