Jump to content

Recommended Posts

Posted

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.

Posted

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?

 

Posted

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.

Posted

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!

Posted

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

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

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

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