NeoForge icon indicating copy to clipboard operation
NeoForge copied to clipboard

Replace PlantType system with SpecialPlantable interface and canSustainPlant block method

Open TelepathicGrunt opened this issue 1 month ago • 3 comments

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.

  1. 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 and spawnPlantAtPosition 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?
  2. 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 call canSustainPlant 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 overrides mayPlace method, they will still respect canSustainPlant because the patches tries to target the canSurvive 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's getGrowthSpeed method had its first parameter changed from Block to BlockStatein order to pass in the correct crop block's blockstate to canSustainPlant. 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.
  3. 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.

TelepathicGrunt avatar May 17 '24 22:05 TelepathicGrunt