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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • There are a few Forge specific mods that I would dearly love to use on my new server, but my friend whom I'm setting up the new server with has expressed concerns that Forge may break or change some core mechanics that might make some farms/contraptions/Redstone devices that work in Vanilla or Fabric not work in Forge. They have sent me a few links to some Twitch minecrafters that have commented that "Forge changes Redstone behavior" or "Certain farms are broken on Forge but not Vanilla", however, I've never experienced this myself, and haven't found or seen any actual examples of this being the case.  I've scoured Youtube and can't find anyone saying "This contraption doesn't work on Forge Ole777".  I spoke to a mod developer who mentioned that there may have been small bugs where this might have been the case in extremely complicated builds, but he is not of aware of this still being an issue or concern. And he mentioned that any instance where something might break would definitely be considered a bug and should be reported and it would/could be fixed, as Forge explicitly doesn't intend to change any vanilla behavior. It just seems much more rumor than fact that Forge might break things, and just wanted to see if anyone had any input. Thank you!
    • This is a costume block whit the shape of a zombie is not a full block its flamable when ignited  the flames just burn on top or by a aside  that dint seems right  // ########## ########## ########## ########## @Override public int getFlammability(BlockState state, BlockGetter level, BlockPos pos, Direction direction) {     return 300;//((FireBlock)Blocks.FIRE).getBurnOdds(state); //300 } it just seems like check to know if a fire block could despawn mi block    ########### i want mi block to look more like this      what could i use  i was thinking on something like onNeigbourgChange() check for nearby fire or lava blocks   then using the falling block entity spawn a fire block in the same position than mi dead body block  thanks for your readings             
    • LINK DAFTAR AKUN GACOR VVIP BAMBUHOKI88 LINK LOGIN RESMI BAMBUHOKI88 LINK KLAIM BONUS 100% BAMBUHOKI88 Bambuhoki88 Merupakan kumpulan pilihan link situs rekomendasi slot bank bri di tahun 2024 di rekomendasi oleh para slotter deposit bank bri di indonesia dengan tingkat peluang kemenangan tinggi untuk setiap bet mudah menang maxwin.
    • LINK DAFTAR AKUN GACOR VVIP BAMBUHOKI88 LINK LOGIN RESMI BAMBUHOKI88   LINK KLAIM BONUS 100% BAMBUHOKI88 BAMBUHOKI88 Merupakan Pilihan Terbaik Situs Slot Bank Bca Yang Gampang Menang Maxwin Dan Jackpot Besar Dengan Deposit Bank Bca Yang Online 24Jam Auto Dapat Wd Gede.  
    • So I've been trying to make an mob that can have multiple textures, and the mob has the Witch model, and I can put a texture on it but I don't know how to make it spawn with a random texture. I tried searching through mobs that have multiple textures like the fox, rabbit, and stuff but I wasn't able to find out how to do it and I kept getting errors when i tried compiling: error: method createKey in class net.minecraft.network.datasync.EntityDataManager cannot be applied to given types; private static final DataParameter<Integer> ALCHEMIST_TYPE = EntityDataManager.createKey(AlchemistEntity.class, DataSerializers.VARINT); ^ required: java.lang.Class<? extends net.minecraft.entity.Entity>,net.minecraft.network.datasync.IDataSerializer<T> found: java.lang.Class<net.newblocks.entity.AlchemistEntity>,net.minecraft.network.datasync.IDataSerializer<java.lang.Integer> reason: cannot infer type-variable(s) T (argument mismatch; java.lang.Class<net.newblocks.entity.AlchemistEntity> cannot be converted to java.lang.Class<? extends net.minecraft.entity.Entity>) 1 error   And sorry there isn't much info, this was the only error that appears when I tried to copy the same thing from one of those mobs with multiple textures (plus imports). I already tried searching on the site and didn't find much. I can provide more info if needed
  • Topics

×
×
  • Create New...

Important Information

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