Jump to content

[SOLVED] My custom apple tree is not growing


trollworkout

Recommended Posts

Not with bonemeal or anything

 

My custom sapling block

 

package com.technorcery.common.blocks;

import java.util.Random;

import com.technorcery.common.ModData;
import com.technorcery.common.blocks.PlankBlock.WoodType;
import com.technorcery.common.worldgen.WorldGenTree;

import net.minecraft.block.BlockBush;
import net.minecraft.block.IGrowable;
import net.minecraft.block.SoundType;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;

public class SaplingBlock extends BlockBush implements IGrowable {
private final WoodType type;
    public static final PropertyInteger STAGE = PropertyInteger.create("stage", 0, 1);
    protected static final AxisAlignedBB SAPLING_AABB = new AxisAlignedBB(0.09999999403953552D, 0.0D, 0.09999999403953552D, 0.8999999761581421D, 0.800000011920929D, 0.8999999761581421D);
    
    public SaplingBlock(String name, WoodType type)
    {
    	this.type = type;
	this.setUnlocalizedName(name);
	this.setRegistryName(name);
        this.setSoundType(SoundType.PLANT);
        this.setHardness(0.0F);
        this.setTickRandomly(true);
        this.setDefaultState(this.blockState.getBaseState().withProperty(STAGE, Integer.valueOf(0)));
	this.setCreativeTab(ModData.CREATIVE_TAB);
    }
    
    @Override
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
    {
        if (!worldIn.isRemote)
        {
            super.updateTick(worldIn, pos, state, rand);

            if (worldIn.getLightFromNeighbors(pos.up()) >= 9 && rand.nextInt(7) == 0)
            {
                this.grow(worldIn, pos, state, rand);
            }
        }
    }
    
    public void grow(World worldIn, BlockPos pos, IBlockState state, Random rand)
    {
        if (((Integer)state.getValue(STAGE)).intValue() == 0)
        {
            worldIn.setBlockState(pos, state.cycleProperty(STAGE), 4);
        }
        else
        {
            this.generateTree(worldIn, pos, state, rand);
        }
    }
    
    @SuppressWarnings("unused")
    public void generateTree(World worldIn, BlockPos pos, IBlockState state, Random rand)
    {
        if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(worldIn, rand, pos)) return;
	WorldGenerator worldgenerator = new WorldGenTree(true, false, type);
        worldIn.setBlockState(pos, state, 4);
    }
    
    @Override
    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
    {
        return SAPLING_AABB;
    }

@Override
public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient) {
	return true;
}

@Override
public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state) {
	return (double)worldIn.rand.nextFloat() < 0.45D;
}

@Override
public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state) {
	this.grow(worldIn, pos, state, rand);
}


    @Override
    public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(STAGE, Integer.valueOf((meta &  >> 3));
    }

    @Override
    public int getMetaFromState(IBlockState state)
    {
        int i = 0;
        i = i | ((Integer)state.getValue(STAGE)).intValue() << 3;
        return i;
    }
    
    @Override
    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {STAGE});
    }
}

 

 

My custom tree worldgen class

 

package com.technorcery.common.worldgen;

import java.util.Random;

import com.technorcery.common.ModBlocks;
import com.technorcery.common.blocks.PlankBlock.WoodType;

import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenAbstractTree;

public class WorldGenTree extends WorldGenAbstractTree {
private final WoodType type;
    private final boolean useExtraRandomHeight;

public WorldGenTree(boolean notify, boolean useExtraRandomHeightIn, WoodType type) {
	super(notify);
        this.type = type;
        this.useExtraRandomHeight = useExtraRandomHeightIn;
}

@Override
public boolean generate(World worldIn, Random rand, BlockPos position)
    {
        int i = rand.nextInt(3) + 5;
        IBlockState LOG = ModBlocks.LOG_APPLE.getDefaultState();
        IBlockState LEAF = ModBlocks.LEAF_APPLE.getDefaultState();
        
        if (type == WoodType.ELDER)
        {
        	LOG = ModBlocks.LOG_ELDER.getDefaultState();
        	LEAF = ModBlocks.LEAF_ELDER.getDefaultState();
        }

        if (this.useExtraRandomHeight)
        {
            i += rand.nextInt(2);
        }

        boolean flag = true;

        if (position.getY() >= 1 && position.getY() + i + 1 <= 256)
        {
            for (int j = position.getY(); j <= position.getY() + 1 + i; ++j)
            {
                int k = 1;

                if (j == position.getY())
                {
                    k = 0;
                }

                if (j >= position.getY() + 1 + i - 2)
                {
                    k = 2;
                }

                BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();

                for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l)
                {
                    for (int i1 = position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1)
                    {
                        if (j >= 0 && j < worldIn.getHeight())
                        {
                            if (!this.isReplaceable(worldIn, blockpos$mutableblockpos.setPos(l, j, i1)))
                            {
                                flag = false;
                            }
                        }
                        else
                        {
                            flag = false;
                        }
                    }
                }
            }

            if (!flag)
            {
                return false;
            }
            else
            {
                BlockPos down = position.down();
                IBlockState state = worldIn.getBlockState(down);
                boolean isSoil = state.getBlock().canSustainPlant(state, worldIn, down, net.minecraft.util.EnumFacing.UP, (net.minecraft.block.BlockSapling)Blocks.SAPLING);

                if (isSoil && position.getY() < worldIn.getHeight() - i - 1)
                {
                    state.getBlock().onPlantGrow(state, worldIn, down, position);

                    for (int i2 = position.getY() - 3 + i; i2 <= position.getY() + i; ++i2)
                    {
                        int k2 = i2 - (position.getY() + i);
                        int l2 = 1 - k2 / 2;

                        for (int i3 = position.getX() - l2; i3 <= position.getX() + l2; ++i3)
                        {
                            int j1 = i3 - position.getX();

                            for (int k1 = position.getZ() - l2; k1 <= position.getZ() + l2; ++k1)
                            {
                                int l1 = k1 - position.getZ();

                                if (Math.abs(j1) != l2 || Math.abs(l1) != l2 || rand.nextInt(2) != 0 && k2 != 0)
                                {
                                    BlockPos blockpos = new BlockPos(i3, i2, k1);
                                    IBlockState state2 = worldIn.getBlockState(blockpos);

                                    if (state2.getBlock().isAir(state2, worldIn, blockpos) || state2.getBlock().isAir(state2, worldIn, blockpos))
                                    {
                                        this.setBlockAndNotifyAdequately(worldIn, blockpos, LEAF);
                                    }
                                }
                            }
                        }
                    }

                    for (int j2 = 0; j2 < i; ++j2)
                    {
                        BlockPos upN = position.up(j2);
                        IBlockState state2 = worldIn.getBlockState(upN);

                        if (state2.getBlock().isAir(state2, worldIn, upN) || state2.getBlock().isLeaves(state2, worldIn, upN))
                        {
                            this.setBlockAndNotifyAdequately(worldIn, position.up(j2), LOG);
                        }
                    }

                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
        else
        {
            return false;
        }
    }

}

 

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

Is it cause I need to register something? Maybe tree worldgen needs registering??

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

Is it cause I need to register something? Maybe tree worldgen needs registering??

Yes you need to register WorldGenerators.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

But how do I register it?

 

The GameRegistry.RegisterWorldGenerator only registers IWorldGenerator and not WorldGenerator for my custom tree gen.

 

Seems other mods don't register their custom tree gen.

 

I'm thinking my problem may be somewhere else maybe my grow function in my sapling is broken.

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

But how do I register it?

 

The GameRegistry.RegisterWorldGenerator only registers IWorldGenerator and not WorldGenerator for my custom tree gen.

 

Seems other mods don't register their custom tree gen.

 

I'm thinking my problem may be somewhere else maybe my grow function in my sapling is broken.

Doesn't WorldGenAbstractTree implement IWorldGenerator and you never call the generation method you just create a new instance then never do anything.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

WorldGenAbstractTree extends WorldGenerator

 

Nope it implements WorldGenerator not IWorldGenerator.

 

 

Whatever code I have up there it does not bonemeal and will not grow ever. There's some issue somewhere. I have a feeling the sapling is broken.

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

WorldGenAbstractTree extends WorldGenerator

 

Nope it implements WorldGenerator not IWorldGenerator.

And WorldGenerator implements IWorldGenerator

 

Whatever code I have up there it does not bonemeal and will not grow ever. There's some issue somewhere. I have a feeling the sapling is broken.

 

you never call the generation method you just create a new instance then never do anything.

Here I meant in your growTreeMethod(...).

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

And WorldGenerator implements IWorldGenerator
No, it doesn't.

Really? Wow, is IWorldGenerator just provided by forge as a better alternative? I have never looked at WorldGenerator as I have not needed it.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

IWorldGenerator

is added by Forge to make custom world generation easier. Vanilla code is generated in

BiomeDecorator

, and the custom generation is called from

Chunk#populateChunk

.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

IWorldGenerator

is added by Forge to make custom world generation easier. Vanilla code is generated in

BiomeDecorator

, and the custom generation is called from

Chunk#populateChunk

.

Good to know. Still shows that I have much more to learn.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

WorldGenerator does not implements or extends anything. IWorldGenerator and WorldGenerator are not compatible.

 

 

So how do I fix my custom tree?

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

I figured it out guys.  I was right my sapling was incorrect.

 

Gen tree was wrong. I fixed it like so

 

   public void generateTree(World worldIn, BlockPos pos, IBlockState state, Random rand)
    {
        if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(worldIn, rand, pos)) return;
	WorldGenerator worldgenerator = new WorldGenTree(true, false, type);

        IBlockState iblockstate2 = Blocks.AIR.getDefaultState();
        worldIn.setBlockState(pos, iblockstate2, 4);
        
        if (!worldgenerator.generate(worldIn, rand, pos.add(0, 0, 0)))
        {
        	 worldIn.setBlockState(pos, state, 4);
        }
    }

 

 

Note the

        IBlockState iblockstate2 = Blocks.AIR.getDefaultState();

        worldIn.setBlockState(pos, iblockstate2, 4);

       

        if (!worldgenerator.generate(worldIn, rand, pos.add(0, 0, 0)))

        {

        worldIn.setBlockState(pos, state, 4);

        }

 

seems like you need to set the state of air block to 4 before you can spawn the tree.

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • why when I launch the forge version of minecraft in full screen and turn on screen recording, only the first static image of the launch is recorded and the gameplay itself is not recorded
    • As a software developer from Sakha Republic, Russia. and like many in my field, I am quite tech-savvy. However, I recently became a victim of a cryptocurrency scam that cost me more than 10 million in my currency. The experience was not only financially devastating but also emotionally draining. I reported the crime to the authorities, hoping for a swift resolution, but I was frustrated and lacked results. It felt like I was in a maze with no exit. Feeling stuck and desperate, I turned to fellow developers for advice. One of them recommended a company called Muyern Trust Hacker. Initially, I was hesitant; I had heard mixed reviews about recovery services and I was concerned about falling victim to another scam. However, after speaking with their team, I was impressed by their professionalism and the clarity of their recovery methods. The team at Muyern Trust Hacker was dedicated and responsive, providing regular updates on their progress. It was refreshing to work with professionals who genuinely cared about my situation and were committed to helping me recover my lost funds. To my astonishment, they managed to recover most of my lost funds. The experience taught me valuable lessons about the risks of cryptocurrency investments and the importance of vigilance in the digital space.
    • Hello! I am the leader of this rp community for a Minecraft rp server and I would like to lend out an invitation to you all to join! We are on a rp server meaning we are going to do some rp and have characters, lore, stories and more! If you want to join just click the discord link below and I’ll help guide you through the process in joining the server and joining us on the server which should be easy. (NOTE: server requires you have to be 16 years old or older) (Java only!) Discord: https://discord.gg/V9uxjKQ7dB
    • these are the errors at startup [06nov2024 19:13:37.566] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--launchTarget, forgeserver, --fml.forgeVersion, 47.3.11, --fml.mcVersion, 1.20.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20230612.114412] [06nov2024 19:13:37.570] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 10.0.9+10.0.9+main.dcd20f30 starting: java version 23.0.1 by Oracle Corporation; OS Windows 11 arch amd64 version 10.0 [06nov2024 19:13:39.173] [main/INFO] [net.minecraftforge.fml.loading.ImmediateWindowHandler/]: ImmediateWindowProvider not loading because launch target is forgeserver [06nov2024 19:13:39.178] [main/INFO] [mixin-transmog/]: Mixin Transmogrifier is definitely up to no good... [06nov2024 19:13:39.398] [main/INFO] [mixin-transmog/]: Redefining 5 mixin classes [06nov2024 19:13:39.412] [main/INFO] [mixin-transmog/]: crimes against java were committed [06nov2024 19:13:39.413] [main/INFO] [com.teampotato.redirector.Redirector/]: Redirector CoreMod initialized successfully! [06nov2024 19:13:39.424] [main/INFO] [mixin-transmog/]: Original mixin transformation service successfully crobbed by mixin-transmogrifier! [06nov2024 19:13:39.453] [main/INFO] [mixin/]: SpongePowered MIXIN Subsystem Version=0.8.5 Source=union:/C:/Users/zappi/OneDrive/Desktop/server%20forge/mods/Connector-1.0.0-beta.18+1.20.1-full.jar%23386%23390!/ Service=ModLauncher Env=SERVER [06nov2024 19:13:40.424] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\zappi\OneDrive\Desktop\server forge\libraries\net\minecraftforge\fmlcore\1.20.1-47.3.11\fmlcore-1.20.1-47.3.11.jar is missing mods.toml file [06nov2024 19:13:40.427] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\zappi\OneDrive\Desktop\server forge\libraries\net\minecraftforge\javafmllanguage\1.20.1-47.3.11\javafmllanguage-1.20.1-47.3.11.jar is missing mods.toml file [06nov2024 19:13:40.430] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\zappi\OneDrive\Desktop\server forge\libraries\net\minecraftforge\lowcodelanguage\1.20.1-47.3.11\lowcodelanguage-1.20.1-47.3.11.jar is missing mods.toml file [06nov2024 19:13:40.433] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\zappi\OneDrive\Desktop\server forge\libraries\net\minecraftforge\mclanguage\1.20.1-47.3.11\mclanguage-1.20.1-47.3.11.jar is missing mods.toml file [06nov2024 19:13:41.061] [main/WARN] [net.minecraftforge.jarjar.selection.JarSelector/]: Attempted to select two dependency jars from JarJar which have the same identification: Mod File:  and Mod File: . Using Mod File:  [06nov2024 19:13:41.062] [main/WARN] [net.minecraftforge.jarjar.selection.JarSelector/]: Attempted to select two dependency jars from JarJar which have the same identification: Mod File:  and Mod File: . Using Mod File:  [06nov2024 19:13:41.063] [main/WARN] [net.minecraftforge.jarjar.selection.JarSelector/]: Attempted to select a dependency jar for JarJar which was passed in as source: curios. Using Mod File: C:\Users\zappi\OneDrive\Desktop\server forge\mods\curios-forge-5.10.0+1.20.1.jar [06nov2024 19:13:41.063] [main/WARN] [net.minecraftforge.jarjar.selection.JarSelector/]: Attempted to select a dependency jar for JarJar which was passed in as source: terrablender. Using Mod File: C:\Users\zappi\OneDrive\Desktop\server forge\mods\TerraBlender-forge-1.20.1-3.0.1.7.jar [06nov2024 19:13:41.063] [main/WARN] [net.minecraftforge.jarjar.selection.JarSelector/]: Attempted to select a dependency jar for JarJar which was passed in as source: aeroblender. Using Mod File: C:\Users\zappi\OneDrive\Desktop\server forge\mods\aeroblender-1.20.1-1.0.1-neoforge.jar [06nov2024 19:13:41.063] [main/INFO] [net.minecraftforge.fml.loading.moddiscovery.JarInJarDependencyLocator/]: Found 97 dependencies adding them to mods collection [06nov2024 19:13:42.637] [main/INFO] [dev.su5ed.sinytra.connector.locator.DependencyResolver/]: Dependency resolution found 11 candidates to load [06nov2024 19:13:43.954] [main/INFO] [Configured Defaults/]: Applying default files...
  • Topics

×
×
  • Create New...

Important Information

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