Jump to content

Recommended Posts

Posted

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

 

Posted

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.

Posted

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.

Posted
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.

Posted (edited)

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
Posted
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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

×
×
  • Create New...

Important Information

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