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
  On 9/16/2020 at 1:15 PM, 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,

Expand  

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.

 

  On 9/16/2020 at 1:32 PM, 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.

Expand  

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
  On 9/16/2020 at 2:29 PM, 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.

Expand  

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

    • inicie un mundo donde instale Croptopia y Farmer's Delight, entonces instale el addon Croptopia Delight pero no funciona. es la version 1.18.2
    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
    • sorry, I might be stupid, but how do I open it? because the only options I have are too X out, copy it, which doesn't work and send crash report, which doesn't show it to me, also, sorry for taking so long.
    • Can you reproduce this with version 55.0.21? A whole lot of plant placement issues were just fixed in this PR.
  • Topics

×
×
  • Create New...

Important Information

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