Skip to content

Instantly share code, notes, and snippets.

@Shadows-of-Fire
Last active August 25, 2019 08:51
Show Gist options
  • Save Shadows-of-Fire/9c1699d061754bb97056ec7a0a65b00f to your computer and use it in GitHub Desktop.
Save Shadows-of-Fire/9c1699d061754bb97056ec7a0a65b00f to your computer and use it in GitHub Desktop.
Plants
-Block Methods
--getPlantTypes() @Nullable Set<PlantType>, null type represents not a plant.
--canBePlanted(IBlockReader, BlockPos) boolean, Plant's authority on if it can be placed here. Equal authority with canPlantOn
--canHarvest(IBlockReader, BlockPos, @Nullable PlayerEntity) boolean, if the plant can be harvested
--harvest(IWorld, BlockPos, @Nullable PlayerEntity) List<ItemStack>, harvests the plant into a List<ItemStacK>. Updates the state in the world.
--placePlant(IWorld, BlockPos, @Nullable PlayerEntity, ItemStack) boolean, places the plant into the world. Returns true for success.
--getSeed() Item, returns the seed for this plant.
--getGrowthProgress(BlockState) float, returns [0, 1] for plant growth.
-Growing
--Handled by IGrowable.
--IGrowable needs an ItemStack context for what the fertilizer is.
Soils
-Block Methods
--canPlantHere(Block plant, IBlockReader world, BlockPos pos) boolean, Soil's authority on if a plant can be planted here. Equal authority with canBePlanted
--getSupportedPlantTypes() Set<PlantType>, less contextul method that gets what types this plant should supports.
Seeds
-Item Methods
--canBePlanted(IBlockReader, BlockPos), delegates to Block
--placePlant(IWorld, BlockPos, @Nullable PlayerEntity, ItemStack), delegates to Block
--getPlantState(IBlockReader, BlockPos, @Nullable PlayerEntity, ItemStack) BlockState, gets the state this plant will place. Not always accurate due to doubleplants etc.
--getPlant() Block, returns the Plant associated with this Seed
@HenryLoenwind
Copy link

HenryLoenwind commented Aug 23, 2019

canHarvest/harvest: I would like to see an ItemStack instead of EntityPlayer version. Then machines don't need a FakePlayer just to pass on the harvesting tool.

canBePlanted: Maybe return a reason why not? enum { OTHER, LIGHT, SPACE, DIMENSION, SOIL, NEEDS_TILLING }? The NEEDS_TILLING is something machines can fix themselves, some are permanent so a machine can eject the seed, some are temporary so the machine can show a useful message to the user.

harvest: A "boolean simulate" would be nice---but would also need a seeded Random to have stable results. This is about machines not having to drop items if the harvesting provides more than they can store in their inventory. Also, stating that the plant is NOT allowed to mess with the given player's inventory aside from the hand item would really be nice. This has been a major pain point for us.

harvest: Maybe return Pair<NonNullList<ItemStack>, Integer> so experience drops can be handled my machines, too.

harvest: Maybe add a boolean to specify "harvest fruit" or "harvest and remove plant"? Re-planting from a dropped seed is PITA code, too. Especially the isSeed(stack) logic is hard to get right, just think seeds with lot of data (is seed "item_xyz_seed{nbt:type=wheat,strength=7}" the same seed as "item_xyz_seed{nbt:type=peas,strength=7}" or "item_xyz_seed{nbt:type=wheat,strength=8}"?)...

placePlant: Need to specify that the method should shrink() the given ItemStack. Actually, all methods should specify that/if parameter objects are to be modified or if the caller is responsible for e.g. damaging the tool.

getGrowthProgress: Any thoughts on plants that have plant growth and fruit growth separated? (tbh, I personally don't care about progress at all because Ender IO's Farming Station doesn't need it.)

About fertilizing: Fertilizing is hard, even more so when 3+ mods are involved. The Farmer doesn't know which items are fertilizer, nor which item any plant accepts as fertilizer. The plant may not recognize another mod's fertilizer as being equivalent to bonemeal or ModXYMagicDung. So this would actually need some kind of registry for "fertilizing type", a way for items and fluids to specify that they provide that type and a way to check which types a plant takes. And then fluids have amounts, which needs to be mapped to "1 item", but then items may have different strength, too. So a fluid may provide 0.000876 units of bonemealing per mB, item_xyz may provide 0.0023 units of bonemealing per item and vanilla bonemeal (the reference item) would provide 1.0f units. But item_xyz may also provide 1.0f units of "magical_flower_fertilizing"...

@temp1011
Copy link

--getPlantTypes() @Nullable Set<PlantType>, null type represents not a plant.
It would be better if things that aren't plants just return an empty set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment