Posted March 4, 20205 yr I am making a mod for 1.15 that alters the growth rate of wheat, cocoa beans, etc. based on the biome they are growing in and affects the max height of cacti and sugarcane depending on the biome and the maximum number of mushrooms that can spread in an area depending on the biome. The brute force way to do it would be to replace mushrooms, crops, etc. with custom blocks, but I want my world to still be playable even if I remove the mod. I've looked at the source code and the method I am interested in is called tick and I am interested specifically when it is called from the following classes: Spoiler BambooBlock BambooSapling BeetRootBlock CactusBlock ChorusFlowerBlock ChorusPlantBlock CocoaBlock CropsBlock KelpBlock KelpTopBlock MushroomBlock NetherwartBlock Sapling Block SweetBerryBlock StemBlock SugarCaneBlock VineBlock There are many other blocks that use the tick method (such as redstone ore and leaves) that I don't care about. The way I was planning to do this is look for an event that fires whenever the tick method runs and then check if the block in the event is one of the blocks I am interested in. If it is, then I cancel the event and run my own custom tick method that accounts for higher max height, growth rate, and/or maximum mushroom density. The problem that I am having is that I cannot find an event that fires whenever the tick method is called. I expected that the TickEvent would work but it didn't seem to do what I wanted (I want an event to include the world and the position of the block that is trying to grow). If there is a method that works specifically when the tick event fires for all the blocks I listed but not for all blocks in general, then that's even better. I don't want the event to fire only when the plant grows, I want it to fire every time the plant tries to grow. Thanks, Andrew Murdza
March 5, 20205 yr Author I found that beetroots, carrots, wheat, potatoes, cacti, sugarcane, chorus flowers, cocoa beans, kelp, nether wart, sweet berries, pumpkin and melon stems when they grow in age, and pumpkin and melon stems when they grow pumpkins and melons all call the ForgeHooks onCropsGrowPre event which is related to the BlockEvent.CropGrowEvent.Pre event. This leaves Bamboo, Mushrooms, Saplings, and Vines. I am especially interested in the mushroom block. The only three methods that are called when deciding when there are too many mushrooms in the area are BlockPos.getAllInBoxMutable, the getBlockState method of ServerWorld, and the getBlock method of BlockState. All of these methods do not seem to lead to any forge events. Is some way to involve events? If not, is there a way I can either work with the ServerWorld or introduce a fake replica of the mushroom block with my tick method that will not cause the mushrooms to disappear if I unload the mod? The code is below: Spoiler if (rand.nextInt(25) == 0) { int i = 5; int j = 4; for(BlockPos blockpos : BlockPos.getAllInBoxMutable(pos.add(-4, -1, -4), pos.add(4, 1, 4))) { if (worldIn.getBlockState(blockpos).getBlock() == this) { --i; if (i <= 0) { return; } } } I would like to change the number 25 in the nextInt method and the value of i depending on the biome, with the value of i being most important. Edited March 5, 20205 yr by Andrew Murdza
March 5, 20205 yr Author I also just realized that the max growth heights for cacti and sugarcane are determined before the onCropsGrowPre is called. So I'm hoping there is a solution for cacti and sugarcane as well.
March 8, 20205 yr Author I figured out how to make the changes I wanted by overriding the vanilla blocks with my own blocks. Even if I unload the mod, the blocks are still there and they function as normal.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.