NeoForge
NeoForge copied to clipboard
Replace PlantType system with SpecialPlantable interface and canSustainPlant block method
It is well known the old PlantType system used in past is quite clunky and broken in many areas. It does not even cover some important vanilla plants such as Cocoa.
Basically, it tried to be many things at once and failed at all of them. It tried to allow for blocks to define what plant it can keep as well as control what modded crops villagers can place.
This PR splits the two goals into separate systems.
-
SpecialPlantable interface (any suggestions of different name?)
- This replaces the
IPlantable
interface and instead of being on blocks, you would put the SpecialPlantable interface on your own custom item classes. - The interface will force you to define
canPlacePlantAtPosition
andspawnPlantAtPosition
methods.villagerCanPlantItem
is optional to override. - Other mods will instanceof check for the interface on an item and if present, will call these two methods to check if the item can place a plant at a spot and if so, call the other method to spawn the plant. This allows for the item to spawn larger or more complex plants through mod interactions instead of just a normal BlockItem.
- Vanilla items are untouched as they are BlockItems. Mods can still find those crop items by checking if in ItemTags.VILLAGER_PLANTABLE_SEEDS tag and then call the BlockItem's method for placing the crop. Again, the interface is for crops that are more complex than a BlockItem.
- If an item has this interface and has overridden
villagerCanPlantItem
to return true, Villagers can pick up this item and put it into the Villager's inventory. Then the Villager will now be able to plant this item on nearby block that extend FarmBlock! - Thoughts? Any way to improve this interface? Or is it not a good idea?
- This replaces the
-
Changed canSustainPlant to return a Tristate and patched it into more blocks
- Modded soil blocks will override
canSustainPlant
and return TRUE, FALSE, or DEFAULT enum. If DEFAULT, the plant block will continue to run it's normal logic for checking survivability. If TRUE or FALSE is returned, it will override the plant's survivability checks to what the soil block wants. - Modded plant blocks that override
canSurvive
method should callcanSustainPlant
on the block the plant is attaching to and respect the enum result that comes out. Basically, modded plants will have to "opt-in" into this system. If the pklant overridesmayPlace
method, they will still respectcanSustainPlant
because the patches tries to target thecanSurvive
methods where-ever it makes sense - The patches to the vanilla blocks to support
canSustainPlant
are in places where vanilla is doing block type checks or light checks. Any check for block shape was ignored to keep patch size down and because those kinds of plants technically support any block as long as the block's shape is good for supporting the plant. -
CropBlock
'sgetGrowthSpeed
method had its first parameter changed fromBlock
toBlockState
in order to pass in the correct crop block's blockstate tocanSustainPlant
. No idea why mojang passed only the Block in but this is an annoying breaking change to a vanilla method param type I ended up doing. Any suggestions around this? - Support far more vanilla blocks than the old PlantType system did. It includes Cocoa, Chorus Plant, and more! Even Hanging Mangrove Propagule! Let me know if there's any specific plant that needs the hook.
- Modded soil blocks will override
-
Added GameTests for all kinds of plants
- I added gametests for each kind of plant to make sure there's no regression on logic in future and catch missed patches much easier.
- Note: I was not able to make gametest that test the plant's survivability in the dark because the lighting engine is too problematic to handle during gametests. Darkness survivability checking will have to be done manually for Red/Brown mushroom blocks on non-myclium and making sure crops cannot be planted in the dark.
Feed back welcomed as there's a lot of improvements that can be done to this PR.