Crossroads-Development / Crossroads

Crossroads is a mod for Minecraft. It adds a lot of content, and has the design philosophy of "simple pieces, complex contraptions".
MIT License
29 stars 18 forks source link

Fix Edible Blob bugs #218

Closed The-Minecraft-Scientist closed 1 year ago

The-Minecraft-Scientist commented 1 year ago

As noted in #105 , the current Edible Blob implementation is quite buggy since most Vanilla/Forge methods that involve foods work with FoodProperties', which are never provided by the Edible Blob code since it uses a custom, NBT-based food system that never touches Vanilla code. My implementation takes advantage of the fact that Forge allows you to override the getFoodProperties() method in IForgeItem to return a vanilla/mod friendly FoodProperties that is built on-the-fly with hunger and saturation values from the ItemStack of blobs (as well as an identifier that allows you to feed dogs with them). This along with a simple override of the isEdible() method (the default method would always return false since our FoodProperties aren't hardcoded into the item) allows for improved mod compatibility, fixes the bugs when feeding dogs all while simplifying the code drastically (since we can remove all of the custom hunger management code and allow Vanilla to do it for us)

Edit: The code in this PR will throw an NPE if the "food" or "sat" NBT tags are missing, but that can easily be fixed with a couple of null checks, and NBT-less edible blobs are unobtainable without commands anyways.

Da-Technomancer commented 1 year ago

The saturation values for this PR is incorrect. FoodProperties uses a different (float-based) definition of 'saturation' from the NBT value (int) on the edible blob. The int in nbt is the total points of saturation restored, full stop. The FoodProperties float definition of saturation is 'points of saturation restored as a fraction of hunger. So a saturation of 1 with hunger 9 would actually restore 9 points of saturation. Because you don't convert the value before setting it as saturation, (for example) a hunger 8, saturation 4 blob would actually restore 32 saturation (4F * 8). This float definition of saturation doesn't support 0 hunger, non-zero saturation (because you'd need an infinite saturation modifier); this could be fixed by forcing edible blocks to restore at least 1 point of hunger.

The-Minecraft-Scientist commented 1 year ago

Fixed the issue with incorrect saturation and added documentation for the necessary changes to the Fat Congealer (new Blobs cannot have 0 hunger)