Jump to content

Recommended Posts

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?

Posted

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));
}

}

Posted
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

Posted

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.

Posted

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.

  • Like 1

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

×   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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • inicie un mundo donde instale Croptopia y Farmer's Delight, entonces instale el addon Croptopia Delight pero no funciona 
    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
    • sorry, I might be stupid, but how do I open it? because the only options I have are too X out, copy it, which doesn't work and send crash report, which doesn't show it to me, also, sorry for taking so long.
    • Can you reproduce this with version 55.0.21? A whole lot of plant placement issues were just fixed in this PR.
  • Topics

×
×
  • Create New...

Important Information

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