Mod related question

I’ve seen examples of people talking about interacting with other mods within Sponge. I don’t have experience in making mods with forge, only Bukkit and Sponge plugins. What kinds of interactions can I make with other mods from Sponge plugins? And is it required for me to have source code to the other mods? Thanks a ton; very interested in this topic :smile:

Sponge, by default, is designed to work well even when changes to the game underneath happen, either through vanilla updates or mods. You can create and modify entities that aren’t part of the API, query inventories that aren’t vanilla, etc.

If you wanted to access parts of a mod, you can either use the compatibility APIs they provide (such as custom entity types or DataManipulators, or you could create those compatibility APIs yourself.

The mod I use provides no API. How would I know the entity types they use? Or interact with it even? @ZephireNZ

You will of course need to know how the mod works, the entities it provides.

Sponge automatically registers all mod entities in the same way it registers vanilla entities - you can get a list of all vanilla and mod entity types through GameRegistry.getAllOf(EntityType.class). You could then, for example, match the class type in getEntityClass() to that of the mods - therefore giving you the entity type of one of that plugin’s entities.

From then on you can use that EntityType just as you would any other type in the API.

The reason that sounds quite complex is that you’re having to discover the mod’s entities. This is why it’s suggested the author integrate sponge support, as they can easily provide those interfaces.

For more complex stuff you’ll unfortunately have to make the compatibility layer a forge mod itself. That way you can make use of Sponge’s fancy “mixin” system, which forces a mod/vanilla type to act like a sponge type, for example.

That way you could have an entity interface that extends the sponge Entity interface for each of the entities the mod has, and have various functions attached to that entity. The mixin would link those functions the the counterparts in the underlying mod entity.

@ZephireNZ Thank you so much for the information. Would adding the other mod jar as an external jar in Eclipse be enough to get the class type as you described above when you said “match the class type in getEntityClass() to that of the mods”. For example would I do something like (pseudocode):

- Get class from external mod with the ExternalEntityType.class(); method.
 - Find all entities with GameRegistry.getAllOf(EntityType.class)
 - Stream each entity and check if (entity instanceof ExternalEntityType)
 - If so, now I can cast to the external type?

As you can see, I’m not very comfortable with these concepts, so I’m just trying to grasp them awkwardly (as you can see above). So if what I described above was correct, now what? I have the instance of the foreign entity, but how do I find out the things I can do? Would this be restricted to sponge methods/maneuvers unless I did “more complex stuff”. If I choose to do the more complex stuff, is there any example on how? Or is it even possible without the original source code of the mod? Thanks again :heart:

Unfortunately, you’d have to integrate yourself in the Forge environment and write a module that is dependent on that mod (I say module because if you write it as a module, you can happily not load the module if the mod isn’t installed). Unless the mod comes up with a SpongeAPI compatible API layer in which plugins can depend on and interact with without depending on the Forge workspace environment, there’s not much else you can do.

It’s similar to writing compatibility modules for interacting with other plugin’s API’s provided they’re written with SpongeAPI.

Okay thanks @gabizou, I’ll research Forge modules and Forge development further to investigate that area. As for what I stated above, would that be the right process for interacting with foreign entities in a Sponge-ish way? And if I were to create a module, would I be able to interact with the mod through Sponge plugins through the module? Or is Sponge independent of the mod (other than the entities interaction we previously discussed) unless it comes up with a SpongeAPI compatible API layer?

The problem is that the types for location, entities, blocks etc that Sponge use are not the same types that Forge and the base game uses. This is what the “mixin” system does, it forces the base types to act like sponge types.

While you could cast mod entities to their true type, you would not be able to use any of the existing Sponge features with that entity. While they technically are the same thing, from the Sponge API perspective they are not.

That’s why you need a forge mod to have full compatibility. You would create an API based entirely in the Sponge API which would extend from Sponge entity types. You would then have the compatibility layer that would implement this API, passing it onto the mod with types it would recognise.

1 Like