Jump to content

Block replace while generating a tree


Rizen

Recommended Posts

Good day Gentlemen,

 

I'm programming a Mod for 1.16. and I've created a custom tree, 

futhermore I wanted to use a event (SaplingGrowTreeEvent) to change a block in the trunk.

 

Sadly I haven't found a solution to actually get it to work,

the problem I'm facing, which I pressume is that the event is executed before the tree is grown, thuse hindering the tree to actually grow.

 

If anyone know a way to fix it I would be very gratefull.

 

Here the code:

 

@Mod.EventBusSubscriber(modid = AdvancedIndustries.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value =  Dist.CLIENT)
public class ModClientEvents {      

			@SubscribeEvent
            public static void onRubberTreeGrown(SaplingGrowTreeEvent event) {

            BlockPos blockPos = event.getPos();
            IWorld world = event.getWorld();



            if (!(event.getWorld().getBlockState(event.getPos()).getBlock() instanceof RubberTreeSapling))
                return;

            if (event.hasResult()) {
                
                 if (world.getBlockState(blockPos).getBlock() == RegistryHandler.RUBBER_TREE_SAPLING.get()) {

                    AdvancedIndustries.LOGGER.info("Generator running");
                     world.setBlockState(blockPos.add(0,2,0), Blocks.DIAMOND_BLOCK.getDefaultState(), 1);

            }
        }
    }
}

 

If you required more inedepth view to my code, notfiy me please.

 

Yours truthfully

Rizen

 

Link to comment
Share on other sites

There are two questions I would like you to ask yourself. First, is there a point to using this event? If you are creating the class RubberTreeSapling, you can just as easily override the method SaplingBlock#placeTree and return your own tree growth. Second, if you're passing in an instance of the Tree to place when the sapling grows, is there any need for checking in manually instead of making your own tree instance that returns exactly what you're looking for?

 

If your answer to either of these questions are yes, I would reevaluate how you are doing this. The event shouldn't really be used for your purpose as it's called directly before the sapling attempts to create the tree and is more of a cancelable type setting. Hopefully I have answered your question.

Link to comment
Share on other sites

Thank you for the fast respond

 

Well the reason to why I want to use this event, is that I want to replace a block in the trunk, because I don't know if there is a way to already implement that into the growing of the tree,

for the seconed one, it's just there because of my previouse test and I would have probably removed that.

Link to comment
Share on other sites

23 minutes ago, Rizen said:

Well the reason to why I want to use this event, is that I want to replace a block in the trunk, because I don't know if there is a way to already implement that into the growing of the tree,

You are given an abstract class for the tree so you can make it do anything. If I wanted to, I could spawn a woodland mansion on tree growth. You just need to define the tree such that it allows it to happen.

 

7 minutes ago, Luminaire said:

I'd like to know the answer to this question, because I am thinking of replacing a block on generation of normal trees as a possible mod.

That is something completely different Luminaire, you should look into either replacing the tree with your own generation or doing something with mixins to replace only the first instance.

Link to comment
Share on other sites

Well I'm not sure if I excactly have the right thing, but for me when it comes to tree generation,

I use the BaseTreeFeatureConfig and this only allowes 5 arguments.

Thuse hindering me of adding a third block.

 

I'm not sure if I have to edit the TreeFeature class.

Edited by Rizen
Link to comment
Share on other sites

34 minutes ago, Rizen said:

Well I'm not sure if I excactly have the right thing, but for me when it comes to tree generation,

I use the BaseTreeFeatureConfig and this only allowes 5 arguments.

Thuse hindering me of adding a third block.

Once again, you are not required to use this. You can make your own that allows this or rewrite it from scratch. That's the beauty of having an abstract class with the required methods being public/protected.

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.

Announcements



×
×
  • Create New...

Important Information

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