Better Combat Two-Handed weapons unable to apply anoitnments (Includes 20.1 KubeJS script fix)
Shibva opened this issue ยท 2 comments
Better Combat is a mod that is similar to Epic Fight but different in a few regards, with it being entirely customizable with custom animations, presets, and weapon configuration and attributes that make using your weapons when fighting monsters more expressive, while introducing a few new mechanics that alter the combat system.
One of these things is the attribute "Two-Handed". As the name implies, weapons with this attribute can only be wielded in the main hand and, notably for this issue, Disable the offhand slot functionality entirely, as your offhand is being used to hold the bugger.
The issue here should be somewhat self-explanatory, but to ensure I get the message across: as a result of this mechanic, applying Anointments to weapons with this property is impossible, as it disables the offhand, including USE functionality. Swapping the weapon to the offhand to apply it won't work either, as the weapon can only be held in the main hand and (with how it's coded) will be disabled in the offhand slot.
I'm not sure how you would go about fixing this (including a curio slot to apply them, like what Corail did for Corail Tombstone with magic books) or include a crafting recipe. But for the time being (for 1.20.1), after HOURS of my trial and error method of learning and tinkering, I have created a "band-aid" script for KubeJS that crudely restores this functionality by mimicking the data-application, consumption, and sound (no particles though, Idk their color Hex codes damnit!) anointment application on these weapons.
BetterCombat Two-handed weapon Anointment applicator workaround (brought to you by me and KubeJS)
How I did this was to (quite painfully) use an item and apply every Anointment I could and establish a pattern through observing the NBT data that gets added to the weapon and essentially mimic its application based on what is being used. This was possible because each anointment has a name, and the way I did it was to have it check the ID of the item and "translate" it into the corresponding data for the anointment using regex to recognize parts of the ID to translate it into NBT that will be applied to the target item.
But while I could have stop there, I didnt and went the extra mile to make this as much as a 1:1 mimic as possible, including Anointment restrictions on certain weapons, mutual exclusivity, re-aplication of the same Anointment, and even writing over existing ones for a better Anointment while also maintining the one-way applicaton heiarchy (normal -> L -> XL -> II -> III). This was hell, but it was worth it, as after extensive tests, I was able to get it working and behave flawlessly.
TLDR: I made a kubeJS script to mimic what the mod does, but with a method to apply them when the offhand is disabled with Two-Handed weapons.
As for how I got around this, I hooked up this mammoth of code I just described to an event that will detect client inputs instead of registering use, IIRC, its was the only way for me to detect the freaking USE input :/
For those who wish to use this or to see my handywork, download the Script Below! This is a SERVER script, so put it in the server script folder after you unzip it.
(Requirements: Blood Magic (obviously), Better Combat, KubeJS (to run the script) [made using KubeJS 1.20.1 format]
BCxBM Two-Handed Appliation Fix.zip
(Fixed missing Debug variable, set to default by false, switch to true to have readouts whenever you trigger the script via attempting to apply an Anointment on a Two-Handed weapon)
Summary: BC mechanic prevents application of Anointments on weapons that bear the Two-Handed Attribute. Made a "fix script" to bandaid this till a coded fix is made (if ever)
For those with questions about the script, here's a small Q&A. I'm a bit proud of this as I'm not someone who knows how to code Java, so being able to make this with JavaScript is something I take in stride :D
Q: Why are you using the specific event?
A: Because it was one of the two events that I found that will still fire with two-handed weapons (and while working with right-click charge properties like some of those added by Simply Swords)
Q: Why are you referencing the player instead of getting it directly through the event
A: One of the issues I had was the damn thing firing twice, as it will run for both the main and offhand (ifthere'ss something used in the offhand). Because the offhand is disabled the main-hand item USE will be triggered twice or something or (as I remember more clearly) that it wont be able to get the item in the offhand if its disabled, but it still exists in the inventory; so to fix these two issues, I have to grab the items from the player inventory rather than what is being used by the event.
Q: Wouldn't it be easier just to apply the data as a pre-existing NBT instead of trying to interpret the Data through the regex of the appointment item ID?
A: Maybe, I chose this way and stuck with it; it was what took the most time to tweak and test to get right lol. The way I did it is also unique because the names are mostly the same with the difference being in the length or strength being different, so checking for matches in the name and then transforming it into a blank Anoitment NBT string I figured would be easier and cooler if not more efficient as I wouldnt have to run so many if-else checks for each anointment. Plus it's (theoretically) made to work if more anointments are added, provided the names stay consistent, I'm looking at you Honing Oil, AKA the only one whose name is different from its anointment ID in item NBT)
Q: So this is supposed to be like using Anointment on normal weapons
A: yep, I put a lot of effort into making it as 1:1 as possible while learning a lot in the process, the only thing missing is the particles that spawn when applying it, as I don't know the HEX color for the particles.
Q: It's not working
A: This script was a part of a larger script where I made other tweaks and other "Script Patches" so I removed what was not relelent to this, I had in the process cut out the ScriptDebug varable I use to toggle the debug readout (hence why theres quite a few lines that send messages to the client when enabled). OOPS! Should be fixed in the re-upload.
Q: How do I use this?
A: Use it just like you would apply Anointments, hold it in the offhand while the target item is in the mainhand. If you can't see it in the offhand slot, that's just because of how BetterCombat works; it's still there in the inventory. Just right-click to apply. If it doesn't work, then try it again while not targeting a block and check if the Anointment you're trying to apply is compatible and can be applied (as the script fully mimics the same application rules as the mechanic)