Patch VillagerTrades.EmeraldsForVillagerTypeItem to allow modders to make Custom VillagerTypes #1875
+22
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently if you make a custom Villager type the game will crash when you Load into or Create a world, since mc throws an exception when a VillagerType has no Trades, This makes sense in Vanilla's case but makes it impossible for modders to make there own villager types without extreme difficulty.
The first change in the patch simply removes the check completely, preventing the crash. (The other option would be to leave the check but make the list empty so it never throws the exception, I decided against this as then the check here would just be pointless code to run but I am willing to do it this way if need be)
The second change in the patch makes sure that the item cost itemstack isn't empty since there will be no trades of this type for Modded VillagerTypes, if it is empty we return null, if we don't include this check we would get air trades
Fabric has a very similar mixin to allow this:
https://github.com/FabricMC/fabric/blob/1.21.4/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/mixin/object/builder/TradeOffersTypeAwareBuyForOneEmeraldFactoryMixin.java