[1.19.x] Add IForgeBlock#onTreeGrow to replace IForgeBlock#onPlantGrow from 1.16 (#8999)

This commit is contained in:
thedarkcolour authored and GitHub committed 2022-09-03 20:07:09 +01:00
1 parent 2a4230868f
commit 4e2d656e9d
16 files changed
+190

No files matched your search

@@ -6,6 +6,7 @@
package net.minecraftforge.common.extensions;
import java.util.Optional;
import java.util.function.BiConsumer;
import net.minecraft.client.Camera;
import net.minecraft.util.RandomSource;
@@ -24,6 +25,7 @@ import net.minecraft.world.item.*;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.pathfinder.BlockPathTypes;
@@ -326,6 +328,30 @@ public interface IForgeBlock
*/
boolean canSustainPlant(BlockState state, BlockGetter level, BlockPos pos, Direction facing, IPlantable plantable);
/**
* Called when a tree grows on top of this block and tries to set it to dirt by the trunk placer.
* An override that returns true is responsible for using the place function to
* set blocks in the world properly during generation. A modded grass block might override this method
* to ensure it turns into the corresponding modded dirt instead of regular dirt when a tree grows on it.
* For modded grass blocks, returning true from this method is NOT a substitute for adding your block
* to the #minecraft:dirt tag, rather for changing the behaviour to something other than setting to dirt.
*
* NOTE: This happens DURING world generation, the generation may be incomplete when this is called.
* Use the placeFunction when modifying the level.
*
* @param state The current state
* @param level The current level
* @param placeFunction Function to set blocks in the level for the tree, use this instead of the level directly
* @param randomSource The random source
* @param pos Position of the block to be set to dirt
* @param config Configuration of the trunk placer. Consider azalea trees, which should place rooted dirt instead of regular dirt.
* @return True to ignore vanilla behaviour
*/
default boolean onTreeGrow(BlockState state, LevelReader level, BiConsumer<BlockPos, BlockState> placeFunction, RandomSource randomSource, BlockPos pos, TreeConfiguration config)
{
return false;
}
/**
* Checks if this soil is fertile, typically this means that growth rates
* of plants on this soil will be slightly sped up.
@@ -6,6 +6,7 @@
package net.minecraftforge.common.extensions;
import java.util.Optional;
import java.util.function.BiConsumer;
import net.minecraft.client.Camera;
import net.minecraft.util.RandomSource;
@@ -18,6 +19,7 @@ import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.FishingHook;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.pathfinder.BlockPathTypes;
@@ -275,6 +277,29 @@ public interface IForgeBlockState
return self().getBlock().canSustainPlant(self(), level, pos, facing, plantable);
}
/**
* Called when a tree grows on top of this block and tries to set it to dirt by the trunk placer.
* An override that returns true is responsible for using the place function to
* set blocks in the world properly during generation. A modded grass block might override this method
* to ensure it turns into the corresponding modded dirt instead of regular dirt when a tree grows on it.
* For modded grass blocks, returning true from this method is NOT a substitute for adding your block
* to the #minecraft:dirt tag, rather for changing the behaviour to something other than setting to dirt.
*
* NOTE: This happens DURING world generation, the generation may be incomplete when this is called.
* Use the placeFunction when modifying the level.
*
* @param level The current level
* @param placeFunction Function to set blocks in the level for the tree, use this instead of the level directly
* @param randomSource The random source
* @param pos Position of the block to be set to dirt
* @param config Configuration of the trunk placer. Consider azalea trees, which should place rooted dirt instead of regular dirt.
* @return True to ignore vanilla behaviour
*/
default boolean onTreeGrow(LevelReader level, BiConsumer<BlockPos, BlockState> placeFunction, RandomSource randomSource, BlockPos pos, TreeConfiguration config)
{
return self().getBlock().onTreeGrow(self(), level, placeFunction, randomSource, pos, config);
}
/**
* Checks if this soil is fertile, typically this means that growth rates
* of plants on this soil will be slightly sped up.