Posted April 1, 20169 yr When trying to add some properties to the player, I noticed that there is no registerExtenedProperties. Is this just not implemented into 1.9 at this point in time? Or is there a new way to do this?
April 1, 20169 yr IExtendedEntityProperties was deprecated in favour of the Capability system in 1.8.9, it's now been removed completely in 1.9. For examples, you can look at the capabilities provided by Forge ( CapabilityItemHandler and CapabilityAnimation ), the capability test mod or my own mod's capabilities (API, implementation). 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.
April 2, 20169 yr Author I looked at your code and read the forge documentation on capabilities and am curious about a couple things... I fully understand the interface that tells the capability all of the data it holds and the storage class that goes with it. What I don't understand is implementing ICapabilityProvider, and if I don't implement it what do I pass into addCapability? I would be nice if someone could run through this in a bit more depth. The forge documentation spoke of a factory as a third parameter to the register() method, and I don't quite see what this does. In addition, what exactly does the CapabilityInject annotation do?
April 2, 20169 yr What I don't understand is implementing ICapabilityProvider, and if I don't implement it what do I pass into addCapability? I would be nice if someone could run through this in a bit more depth. ICapabilityProvider is something that can provide a handler for a given Capability and EnumFacing . TileEntity , Entity and ItemStack implement this so they can provide capabilities (e.g. IItemHandler for the inventory of an item, block or entity). If you want to attach capabilities to an object from vanilla or another mod using AttachCapabilitiesEvent , you need to supply an ICapabilityProvider that returns your handler object. Forge uses CapabilityDispatcher to wrap the ICapabilitiyProvider s from the event into a single ICapabilityProvider . The forge documentation spoke of a factory as a third parameter to the register() method, and I don't quite see what this does. The factory provides a new instance of the handler interface's default implementation. In addition, what exactly does the CapabilityInject annotation do? The doc comments of @CapabilityInject explain its purpose pretty clearly: On a field, it will set the field's value to the Capability instance for the specified handler interface when it's registered. On a method, it will call the method with the Capability instance for the specified handler interface when it's registered. 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.
April 2, 20169 yr Author Ok, I get the structure of a capability now, but now say I want to get data from this capability, (disregard packets, I'm talking just getting the capability itself from the player) would I just call getCapability() on the player object and pass in the capability and the default facing objects? What about modifying variables from the capability? Edit: One implementation I have of this capability is getting some values from it to use in a book gui, and I ran getCapability() from the onItemRightClick() as I stated above and it did retrieve the correct value, however to my understanding gui's only operate on the client and information about the player is stored on the client. So I am slightly confused here... Few more questions: - I assume that the class the implements IStorage is where I would put all of the variables pertaining to the capability? - Having studied java syntax and the language itself, but not having a ton of experience, I have an event handler class and a method as follows: public static class EventHandler { @SubscribeEvent public void attachCapabilityEntity(AttachCapabilitiesEvent.Entity e) { if (e.getEntity() instanceof EntityPlayer) { e.addCapability(ID, new Provider()); } } } My IDE is telling me that attachCapabilityEntity() is never used, shouldn't it be called on the attach capabilities event? Or can the IDE not assume an event is called? - In the storage class, when are readNBT and writeNBT called? More will probably arise but that's it for now. I apologize for any stupidity in the questions I ask, I am just trying to learn forge. I am also prone to over-thinking things. Thanks for the help!
April 2, 20169 yr The method gets called if you register your event handler correct (try adding a sysout to be sure) yes you would use getCapability to get the caps. The varialbes get saved in the implementation of your Capability. If you want to get/set the values of the cap just add the methods you need to the inferface and implement them in the implementation public interface IManaHandler { int getMana(); int getMaxMana(); void setMana(int mana); void setMaxMana(int maxMana); boolean consumeMana(int mana); boolean regenerateMana(int mana); } public class ManaHandler implements IManaHandler, INBTSerializable<NBTTagCompound>{ private int mana, maxMana; public ManaHandler(int maxMana, int mana) { this.mana = mana; this.maxMana = maxMana; } public ManaHandler() { this(100,100); } @Override public NBTTagCompound serializeNBT() { NBTTagCompound compound = new NBTTagCompound(); compound.setInteger("mana", getMana()); compound.setInteger("maxmana", getMaxMana()); System.out.println("saving cap"); return compound; } @Override public void deserializeNBT(NBTTagCompound compound) { setMana(compound.getInteger("mana")); setMaxMana(compound.getInteger("maxmana")); } @Override public boolean consumeMana(int mana) { if(this.mana<mana) return false; this.mana-=mana; return true; } @Override public boolean regenerateMana(int mana) { if(this.mana==maxMana) return false; else { this.mana +=mana; if(this.mana>maxMana)this.mana=maxMana; return true; } } @Override public int getMana() { return mana; } @Override public int getMaxMana() { return maxMana; } @Override public void setMana(int mana) { this.mana = mana; } @Override public void setMaxMana(int maxMana) { this.maxMana =maxMana; }
April 2, 20169 yr Author Now is that IManaHandler you posted what you would initiate in the capability on? Example: public static final Capability<IManaHandler> name = null; Or is it it's own entity?
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.