Jump to content

[1.9] registerExtendedProperties


WaffleMan0310

Recommended Posts

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.

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

    • I have created a very simple mod that is just supposed to send a message to a player when they join. Upon adding it to a server (that has other mods on it), the following crash message appears: [12:13:01] [main/ERROR] [minecraft/Main]: Failed to start the minecraft server net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [         Epic Mod (epicmod) has failed to load correctly §7java.lang.NoSuchMethodException: net.ed.epicmod.EpicMod.<init>() ]         at net.minecraftforge.fml.ModLoader.waitForTransition(ModLoader.java:243) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.fml.ModLoader.lambda$dispatchAndHandleError$24(ModLoader.java:208) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at java.util.Optional.ifPresent(Optional.java:178) ~[?:?] {re:mixin}         at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:208) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.fml.ModLoader.lambda$gatherAndInitializeMods$14(ModLoader.java:185) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?] {re:mixin,re:computing_frames}         at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:185) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.server.loading.ServerModLoader.load(ServerModLoader.java:32) ~[forge-1.19.2-43.2.14-universal.jar%23552!/:?] {re:classloading}         at net.minecraft.server.Main.main(Main.java:113) ~[server-1.19.2-20220805.130853-srg.jar%23547!/:?] {re:classloading,re:mixin,pl:mixin:A}         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}         at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}         at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}         at net.minecraftforge.fml.loading.targets.CommonServerLaunchHandler.lambda$launchService$0(CommonServerLaunchHandler.java:29) ~[fmlloader-1.19.2-43.2.14.jar%2367!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) [bootstraplauncher-1.1.2.jar:?] {} Why could this be? I have tried using the mod on another forge server with only this mod installed and it works there. Is my mod somehow interfering with other mods? MC version is 1.19.2
    • how to make animated doors?, maybe geckolib, but i don't know how to code it?
    • For crash 1, set max-tick-time to -1 in your server.properties Crash 2 shows a conflict or incompatibility between LuckPerms and the mod boh-0.0.6.1-forge-1.20.1_2.jar
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
    • so my minecraft crashes when opening my world, i played without any troubles for about 5 days and today it started tweaking.. pls help me
  • Topics

×
×
  • Create New...

Important Information

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