Jump to content

updateTick Forge Event


Andrew Murdza

Recommended Posts

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

Link to comment
Share on other sites

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 by Andrew Murdza
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.