Mine-and-blade-admin / Battlegear2

GNU General Public License v3.0
54 stars 53 forks source link

QuiverBow Support #185

Open Domochevsky opened 9 years ago

Domochevsky commented 9 years ago

Yo, how would I (you? we?) go about adding support for BG2 to my mod? Only a few of these weapons are one-handed, but cases can be made. I hear rumblings that you have an API for this, but is there anything documented on that topic?

GotoLink commented 9 years ago

Hi depends on what kind of support you look for. We have a quiver that could hold and fire custom arrows if you have those. It can recognize arrows from FMLInterModComms. For example, if the arrow is supposed to fire from vanilla bow:

//Where class-path is the class path for the arrow entity class (must extend EntityArrow)
//Where arrowStack is a specific enough case ItemStack instance for the arrow item
FMLInterModComms.sendMessage("battlegear2", "Arrow:" + class-path, arrowStack);

If the arrow is fired from a custom bow, or the entity is not a child of EntityArrow:

//Where class-path points to a class implementing IArrowFireHandler with a default constructor
FMLInterModComms.sendMessage("battlegear2", "FireHandler", class-path);

Those are utility methods to access mods.battlegear2.api.quiver.QuiverArrowRegistry. Which you can access directly if necessary.

Another aspect is adding items to the accepted weapons for "battlemode" aka dual-wielding. One-handed weapons should be working without any work on your part. I'd recommend testing those first, as users often "suggest" before even trying these days.

You can either access mods.battlegear2.api.weapons.WeaponRegistry through FMLInterModComms, or directly from its methods, or implement one of the recommended interface from the api package (IUsableItem might be of interest in your case). Implementing ItemBow or ISpecialBow will automatically grant the same wielding properties to the item as the vanilla bow (including enchantments). See respective docs for each of those classes. Here is the base example of FML message for this system:

//Where hand is a case-insensitive String ("both" -or- "dual" for one-handed items,  "right" -or- "mainhand" -or- "left" -or- "offhand" for two-handed on designated side)
//Where itemStack is an ItemStack instance specific enough of the item
FMLInterModComms.sendMessage("battlegear2", hand, itemStack);
GotoLink commented 9 years ago

I read some of your topic latest messages and saw you had some issues with making a "bow" animation. We have some code for it here

Domochevsky commented 9 years ago

Highly interesting stuff, that.

Bows: No, I am not extending the vanilla bow for any of my stuff. All weapons and projectiles are custom and operated via right click. I hear that this has an effect on their usability when dual-wielding. Despite the mod's name I don't actually have dedicated quivers nor special arrows. :)

Are there any methods for marking weapons as one-handed/two-handed, or is this merely a question of "has been marked as valid for dual wielding"? And if so, where/when would one mark that?

As for the "bow" animation: Thanks for that. I nearly gave up there, digging into the madness that is ItemInUse. (RenderLivingEvent... who knew.)

GotoLink commented 9 years ago

The WeaponRegistry or IUsableItem should cover your question then. Did you read what i said about those ? The FML message is the simplest approach to the problem. Doing

//Where yourCustomBow is a Item instance
FMLInterModComms.sendMessage("battlegear2", "mainhand", new ItemStack(yourCustomBow));

Should force two-handed wield on the corresponding item into WeaponRegistry. Replace "mainhand" by "dual", to get the one-handed wield.

Context-sensitive wield would require implementing IUsableItem.

Domochevsky commented 9 years ago

Coo'. I presume FMLInterModComms is called once in the (pre-?)init after all items have been registered? (IUsableItem... I'll have to check that one out.)

GotoLink commented 9 years ago

From FML docs, messages sent from FMLInterModComms#sendMessage(...) will be received by Battlegear between its Init and PostInit stages. You should use this at the Init stage within your mod. Battlegear does not handle runtime messages.

Domochevsky commented 9 years ago

Hm, question: Will implementing IUsableItem make my mod dependent on the existence of BG2?

GotoLink commented 9 years ago

Not necessarily. We marked our API with FML API annotation. As long as you mark your implementation with FML Optional.Interface annotation, your mod should still be independent. Usage would go:

@Optional.Interface(modid:"battlegear2", iface = "mods.battlegear2.api.IUsableItem", striprefs = true);
Domochevsky commented 9 years ago

...yeah, I don't think I'm doing this right. >_>

If I implement it and then mark it with that annotation, eclipse complains that the hierarchy is inconsistent for the base weapon class and everything that extends it, likely because I don't have BG2 itself in my dev environment. But if I import BG2 eclipse complains that it can't find a bunch of things used by that, for which I have little muse or answer to deal with. This also makes me question if it'd really be ok with me implementing an interface that doesn't exist during build and run time.

Can a weapon somehow be marked as "use right click function by default" via FMLInterModComms, if all else fails? I have not worked with APIs before, which is coming back to bite me now.

GotoLink commented 9 years ago

You can either move a copy of the class into /src/api/java to get the minimum compilation for forgegradle. Or add the complete battlegear dev jar (in 'battlegear api' folder of this repo) into your workspace. Our license allows both.

Battlegear doesn't support forcing "right click function" on items from FMLInterModComms. You could interact with the /weaponwield command...if you really want it to happen right now. But i wouldn't recommend it.