Mods / Manual Tool Crafting / SpecializedBags Revived Compatibility Patch

Category:
Author: ghotiboy
Side: Both
Created: 4 days ago
Last modified: 4 days ago
Downloads: 42
Follow Unfollow 3

Latest file for v1.20.3:
ManualCrafting_SpecialtyBags_CompatibilityPatch_1.0.0.zip 1-click install


Quick and dirty compatibility patch for SaltyWater's Manual Tool Crafting and SpeciallyCrafted's SpecializedBags Revived

Both mods overwrite the default stick and bone storageFlags to make them off-hand items (Manual Tool Crafting) or for storage type purposes (SpecializedBags), but since that's just a bitfield, all this patch needs to do is OR the values together.

Version For Game version Downloads Release date Changelog Download 1-click mod install*
v1.0.0 42 4 days ago Show ManualCrafting_SpecialtyBags_CompatibilityPatch_1.0.0.zip Install now

5 Comments (oldest first | newest first)

💬 SpeciallyCrafted, 3 days ago

ghotiboy I have the bags set to 65536 and unless I make the flag on the item 65537 it wouldn't work in the bag and generic storage (1) on the game. Hence the +1 on the storage flag of the item. Then again, still very new at the storage flags thing. I am a networking person, not a coder but my husband and I are talking about taking some classes. 

I appreciate the explanation, it does make more sense!

💬 ghotiboyAuthor, 3 days ago

SpeciallyCrafted I tried to join your Discord from the link on your mod page, but it wouldn't let me.  Dunno what's up with that, maybe your invite link expired or something?  Feel free to shoot me an invite; same username there as on here :)

Anyways, I said 65537 and 257 were suspicious because 65536 and 256 are both powers of 2 that come up all the time in programming.  Specifically, 256 is 2^8, and 65536 is 2^16, and since data is usually organized in groups of 8-bit bytes, 256 comes up when you're dealing with a single byte, and 65536 comes up when you've got a number that fits in 2 bytes.  So 257 and 65537 are both (to me) very obviously <some power of 2> + 1.

See, the thing with storageflags is that it's not really a number per se; it's 32 light switches in a trenchcoat pretending to be a number. If we look at the EnumItemStorageFlags, you'll notice the values go 1, 2, 4, 8, 16, 32...  all powers of 2.  What this means is that, in binary, each of these numbers is represented by a single bit being 1:

1 = 0000 0001

2 = 0000 0010

4 = 0000 0100

8 = 0000 1000

16 = 0001 0000

32 = 0010 0000

etc.

So (and this is the important part), if we add any combination of these numbers together, what we get will be a number that (in binary) has 1's in the same positions as the numbers we added to get it.  For example, if we add 2 and 16, we get 18, which in binary is 0001 0010, with a 1 in the second bit (= 2) and a 1 in the 5th bit (= 16).  The benefit of that is that because binary is the "native language" of computers, it is very easy to check if a particular bit is "on" (1) or "off" (0), so when I try to, say, put a stick in my off-hand, the game checks the storageflags to see if the 9th bit (= 256) is "on," and if I try to put a stick in my forestry bag, it checks to see if the 17th bit (= 65536) is "on."  If I want both behaviors, I can just add 256 and 65536 (and 1 for "General," since that's also in the mix) together, and know that both pieces of functionality will continue to work as intended.

This is why I say it's not really a number: it's not there to do math with, it's just there as a collection of bits to check against individually in different circumstances.

💬 SpeciallyCrafted, 3 days ago

ghotiboy Why are they suspicious? Happy to talk via Discord if you have it. I would love to learn more. 

💬 ghotiboyAuthor, 4 days ago

bringitonwimps Yeah, that'd be great!  You guys should be able to just make a "compatibility" directory under assets/specialexpandedbags within your mod, then copy the "manualtoolcrafting" directory from my mod into it verbatim (you don't need the specialexpandedbags directory from my mod, because you don't need to make your own mod compatible with itself :P ).

Yeah, the storageflags would seem a bit weird if you don't have much development experience, but it follows a very common pattern you see all the time in "real" code.  You guys setting the flags on the stick to 65537 and Salty setting them to 257 are both very suspicious numbers once you've been around the block a few times.  You're turning "on" the "General" (1) and "Custom6" (65536) flags (1 + 65536 = 65537), and he's turning "on" the "General" (1) and "Offhand" (256) flags (= 257), so to make them work together, we just need to turn "on" all 3 flags, "General," "Offhand," and "Custom6" (1 + 256 + 65536 = 65793).

💬 bringitonwimps, 4 days ago

cool, hey my wife does the specialty bag mod, we would gladly build this in if its poosible and someone shows her how so we dont need an extra patch.  The storage flags system is very odd and silly to me..lol

(edit comment delete)