Jump to content

[1.7.10] [Resolved] Help with creating custom tree generation.


Awesome_Spider

Recommended Posts

I've hit yet ANOTHER snag in my mod. I need to know how generate a simple tree. I have attempted this a few times but to know avail. Minecraft has always crashed, stopped generating chucks, or corrupted worlds all the time I've tried. So I came here once again :). Thanks in advance.

 

Edit: Well it still isn't working. It crashes now. Here is the mod log.

 

[17:20:59] [main/INFO] [GradleStart]: No arguments specified, assuming client.
[17:21:00] [main/INFO] [GradleStart]: Extra: []
[17:21:00] [main/INFO] [GradleStart]: Running with arguments: [--userProperties, {}, --assetsDir, C:/Users/Wyatt/.gradle/caches/minecraft/assets, --assetIndex, 1.7.10, --accessToken, {REDACTED}, --version, 1.7.10, --tweakClass, cpw.mods.fml.common.launcher.FMLTweaker]
[17:21:00] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.FMLTweaker
[17:21:00] [main/INFO] [LaunchWrapper]: Using primary tweak class name cpw.mods.fml.common.launcher.FMLTweaker
[17:21:00] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLTweaker
[17:21:01] [main/INFO] [FML]: Forge Mod Loader version 7.10.85.1232 for Minecraft 1.7.10 loading
[17:21:01] [main/INFO] [FML]: Java is Java HotSpot(TM) Client VM, version 1.8.0_11, running on Windows 8.1:x86:6.3, installed at C:\Users\Wyatt\Documents\eclipse\jre
[17:21:01] [main/INFO] [FML]: Managed to load a deobfuscated Minecraft name- we are in a deobfuscated environment. Skipping runtime deobfuscation
[17:21:01] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker
[17:21:01] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.FMLDeobfTweaker
[17:21:01] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker
[17:21:01] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker
[17:21:01] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper
[17:21:05] [main/ERROR] [FML]: The binary patch set is missing. Either you are in a development environment, or things are not going to work!
[17:21:13] [main/ERROR] [FML]: FML appears to be missing any signature data. This is not a good thing
[17:21:13] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper
[17:21:13] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLDeobfTweaker
[17:21:15] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.TerminalTweaker
[17:21:15] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.TerminalTweaker
[17:21:15] [main/INFO] [LaunchWrapper]: Launching wrapped minecraft {net.minecraft.client.main.Main}
[17:21:20] [main/ERROR] [LaunchWrapper]: Unable to launch
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_11]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_11]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_11]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_11]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_11]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_11]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_11]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_11]
at GradleStart.bounce(GradleStart.java:107) [start/:?]
at GradleStart.startClient(GradleStart.java:100) [start/:?]
at GradleStart.main(GradleStart.java:55) [start/:?]
Caused by: java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source) ~[?:1.8.0_11]
at java.lang.Runtime.loadLibrary0(Unknown Source) ~[?:1.8.0_11]
at java.lang.System.loadLibrary(Unknown Source) ~[?:1.8.0_11]
at org.lwjgl.Sys$1.run(Sys.java:73) ~[lwjgl-2.9.1.jar:?]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_11]
at org.lwjgl.Sys.doLoadLibrary(Sys.java:66) ~[lwjgl-2.9.1.jar:?]
at org.lwjgl.Sys.loadLibrary(Sys.java:95) ~[lwjgl-2.9.1.jar:?]
at org.lwjgl.Sys.<clinit>(Sys.java:112) ~[lwjgl-2.9.1.jar:?]
at net.minecraft.client.Minecraft.getSystemTime(Minecraft.java:2807) ~[Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:79) ~[Main.class:?]
... 13 more
Exception in thread "main" [17:21:20] [main/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: java.lang.ArrayIndexOutOfBoundsException: 0
[17:21:20] [main/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: 	at GradleStart.main(GradleStart.java:59)
Java HotSpot(TM) Client VM warning: Using incremental CMS is deprecated and will likely be removed in a future release

 

Here is the generation code:

 

package com.awsp8.wizardry.Gen;

import java.util.Random;

import com.awsp8.wizardry.Wizardry;

import cpw.mods.fml.common.IWorldGenerator;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSapling;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraft.util.Direction;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenAbstractTree;
import net.minecraft.world.gen.feature.WorldGenBigTree;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.common.util.ForgeDirection;

public class MaztrixTreeGen 
			extends WorldGenAbstractTree implements IWorldGenerator{

/** The minimum height of a generated tree. */
    private final int minTreeHeight;
    /** True if this tree should grow Vines. */
    private final boolean vinesGrow;
    /** The metadata value of the wood to use in tree generation. */
    private final int metaWood;
    /** The metadata value of the leaves to use in tree generation. */
    private final int metaLeaves;
    private static final String __OBFID = "CL_00000438";

    public MaztrixTreeGen(boolean p_i2027_1_)
    {
        this(p_i2027_1_, 4, 0, 0, false);
    }

    public MaztrixTreeGen(boolean doBlockNotify, int treeHeight, int wood, int leaves, boolean vines)
    {
        super(doBlockNotify);
        this.minTreeHeight = treeHeight;
        this.metaWood = wood;
        this.metaLeaves = leaves;
        this.vinesGrow = vines;
    }

    public boolean generate(World p_76484_1_, Random p_76484_2_, int p_76484_3_, int p_76484_4_, int p_76484_5_)
    {
        int l = p_76484_2_.nextInt(3) + this.minTreeHeight;
        boolean flag = true;

        if (p_76484_4_ >= 1 && p_76484_4_ + l + 1 <= 256)
        {
            byte b0;
            int k1;
            Block block;

            for (int i1 = p_76484_4_; i1 <= p_76484_4_ + 1 + l; ++i1)
            {
                b0 = 1;

                if (i1 == p_76484_4_)
                {
                    b0 = 0;
                }

                if (i1 >= p_76484_4_ + 1 + l - 2)
                {
                    b0 = 2;
                }

                for (int j1 = p_76484_3_ - b0; j1 <= p_76484_3_ + b0 && flag; ++j1)
                {
                    for (k1 = p_76484_5_ - b0; k1 <= p_76484_5_ + b0 && flag; ++k1)
                    {
                        if (i1 >= 0 && i1 < 256)
                        {
                            block = p_76484_1_.getBlock(j1, i1, k1);

                            if (!this.isReplaceable(p_76484_1_, j1, i1, k1))
                            {
                                flag = false;
                            }
                        }
                        else
                        {
                            flag = false;
                        }
                    }
                }
            }

            if (!flag)
            {
                return false;
            }
            else
            {
                Block block2 = p_76484_1_.getBlock(p_76484_3_, p_76484_4_ - 1, p_76484_5_);

                boolean isSoil = block2.canSustainPlant(p_76484_1_, p_76484_3_, p_76484_4_ - 1, p_76484_5_, ForgeDirection.UP, (BlockSapling)Blocks.sapling);
                if (isSoil && p_76484_4_ < 256 - l - 1)
                {
                    block2.onPlantGrow(p_76484_1_, p_76484_3_, p_76484_4_ - 1, p_76484_5_, p_76484_3_, p_76484_4_, p_76484_5_);
                    b0 = 3;
                    byte b1 = 0;
                    int l1;
                    int i2;
                    int j2;
                    int i3;

                    for (k1 = p_76484_4_ - b0 + l; k1 <= p_76484_4_ + l; ++k1)
                    {
                        i3 = k1 - (p_76484_4_ + l);
                        l1 = b1 + 1 - i3 / 2;

                        for (i2 = p_76484_3_ - l1; i2 <= p_76484_3_ + l1; ++i2)
                        {
                            j2 = i2 - p_76484_3_;

                            for (int k2 = p_76484_5_ - l1; k2 <= p_76484_5_ + l1; ++k2)
                            {
                                int l2 = k2 - p_76484_5_;

                                if (Math.abs(j2) != l1 || Math.abs(l2) != l1 || p_76484_2_.nextInt(2) != 0 && i3 != 0)
                                {
                                    Block block1 = p_76484_1_.getBlock(i2, k1, k2);

                                    if (block1.isAir(p_76484_1_, i2, k1, k2) || block1.isLeaves(p_76484_1_, i2, k1, k2))
                                    {
                                        this.setBlockAndNotifyAdequately(p_76484_1_, i2, k1, k2, Wizardry.maztrixLeaf, this.metaLeaves);
                                    }
                                }
                            }
                        }
                    }

                    for (k1 = 0; k1 < l; ++k1)
                    {
                        block = p_76484_1_.getBlock(p_76484_3_, p_76484_4_ + k1, p_76484_5_);

                        if (block.isAir(p_76484_1_, p_76484_3_, p_76484_4_ + k1, p_76484_5_) || block.isLeaves(p_76484_1_, p_76484_3_, p_76484_4_ + k1, p_76484_5_))
                        {
                            this.setBlockAndNotifyAdequately(p_76484_1_, p_76484_3_, p_76484_4_ + k1, p_76484_5_, Wizardry.maztrixLog, this.metaWood);

                            if (this.vinesGrow && k1 > 0)
                            {
                                if (p_76484_2_.nextInt(3) > 0 && p_76484_1_.isAirBlock(p_76484_3_ - 1, p_76484_4_ + k1, p_76484_5_))
                                {
                                    this.setBlockAndNotifyAdequately(p_76484_1_, p_76484_3_ - 1, p_76484_4_ + k1, p_76484_5_, Blocks.vine, ;
                                }

                                if (p_76484_2_.nextInt(3) > 0 && p_76484_1_.isAirBlock(p_76484_3_ + 1, p_76484_4_ + k1, p_76484_5_))
                                {
                                    this.setBlockAndNotifyAdequately(p_76484_1_, p_76484_3_ + 1, p_76484_4_ + k1, p_76484_5_, Blocks.vine, 2);
                                }

                                if (p_76484_2_.nextInt(3) > 0 && p_76484_1_.isAirBlock(p_76484_3_, p_76484_4_ + k1, p_76484_5_ - 1))
                                {
                                    this.setBlockAndNotifyAdequately(p_76484_1_, p_76484_3_, p_76484_4_ + k1, p_76484_5_ - 1, Blocks.vine, 1);
                                }

                                if (p_76484_2_.nextInt(3) > 0 && p_76484_1_.isAirBlock(p_76484_3_, p_76484_4_ + k1, p_76484_5_ + 1))
                                {
                                    this.setBlockAndNotifyAdequately(p_76484_1_, p_76484_3_, p_76484_4_ + k1, p_76484_5_ + 1, Blocks.vine, 4);
                                }
                            }
                        }
                    }

                    if (this.vinesGrow)
                    {
                        for (k1 = p_76484_4_ - 3 + l; k1 <= p_76484_4_ + l; ++k1)
                        {
                            i3 = k1 - (p_76484_4_ + l);
                            l1 = 2 - i3 / 2;

                            for (i2 = p_76484_3_ - l1; i2 <= p_76484_3_ + l1; ++i2)
                            {
                                for (j2 = p_76484_5_ - l1; j2 <= p_76484_5_ + l1; ++j2)
                                {
                                    if (p_76484_1_.getBlock(i2, k1, j2).isLeaves(p_76484_1_, i2, k1, j2))
                                    {
                                        if (p_76484_2_.nextInt(4) == 0 && p_76484_1_.getBlock(i2 - 1, k1, j2).isAir(p_76484_1_, i2 - 1, k1, j2))
                                        {
                                            this.growVines(p_76484_1_, i2 - 1, k1, j2, ;
                                        }

                                        if (p_76484_2_.nextInt(4) == 0 && p_76484_1_.getBlock(i2 + 1, k1, j2).isAir(p_76484_1_, i2 + 1, k1, j2))
                                        {
                                            this.growVines(p_76484_1_, i2 + 1, k1, j2, 2);
                                        }

                                        if (p_76484_2_.nextInt(4) == 0 && p_76484_1_.getBlock(i2, k1, j2 - 1).isAir(p_76484_1_, i2, k1, j2 - 1))
                                        {
                                            this.growVines(p_76484_1_, i2, k1, j2 - 1, 1);
                                        }

                                        if (p_76484_2_.nextInt(4) == 0 && p_76484_1_.getBlock(i2, k1, j2 + 1).isAir(p_76484_1_, i2, k1, j2 + 1))
                                        {
                                            this.growVines(p_76484_1_, i2, k1, j2 + 1, 4);
                                        }
                                    }
                                }
                            }
                        }

                        if (p_76484_2_.nextInt(5) == 0 && l > 5)
                        {
                            for (k1 = 0; k1 < 2; ++k1)
                            {
                                for (i3 = 0; i3 < 4; ++i3)
                                {
                                    if (p_76484_2_.nextInt(4 - k1) == 0)
                                    {
                                        l1 = p_76484_2_.nextInt(3);
                                        this.setBlockAndNotifyAdequately(p_76484_1_, p_76484_3_ + Direction.offsetX[Direction.rotateOpposite[i3]], p_76484_4_ + l - 5 + k1, p_76484_5_ + Direction.offsetZ[Direction.rotateOpposite[i3]], Blocks.cocoa, l1 << 2 | i3);
                                    }
                                }
                            }
                        }
                    }

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

    /**
     * Grows vines downward from the given block for a given length. Args: World, x, starty, z, vine-length
     */
    private void growVines(World p_76529_1_, int p_76529_2_, int p_76529_3_, int p_76529_4_, int p_76529_5_)
    {
        this.setBlockAndNotifyAdequately(p_76529_1_, p_76529_2_, p_76529_3_, p_76529_4_, Blocks.vine, p_76529_5_);
        int i1 = 4;

        while (true)
        {
            --p_76529_3_;

            if (!p_76529_1_.getBlock(p_76529_2_, p_76529_3_, p_76529_4_).isAir(p_76529_1_, p_76529_2_, p_76529_3_, p_76529_4_) || i1 <= 0)
            {
                return;
            }

            this.setBlockAndNotifyAdequately(p_76529_1_, p_76529_2_, p_76529_3_, p_76529_4_, Blocks.vine, p_76529_5_);
            --i1;
        }
}

@Override
public void generate(Random random, int chunkX, int chunkZ, World world,
		IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
	int x = random.nextInt(16);
	int z = random.nextInt(16);

	this.generate(world, random, x, world.getHeightValue(x, z), z);
}
}

 

Here is what I used to register the terrain generator:

 

GameRegistry.registerWorldGenerator(new MaztrixTreeGen(true, 4, 0, 0, false), 1);

 

Any further help would be great. :)

Link to comment
Share on other sites

Code is always more informative than a crash report alone, even if you remember what the exception was.

 

You said you're trying to generate a "simple" tree, but I assume you're trying to accomplish something beyond what the vanilla tree generation methods provide, as in, a different shape, or different blocks than vanilla leaves and logs?

 

Even if not, it might be worth a while to poke around in the vanilla methods, all in net.minecraft.world.gen.feature, to see how they're doing things. Spoiler: it's just huge mess of if statements and loops.

Link to comment
Share on other sites

Code is always more informative than a crash report alone, even if you remember what the exception was.

 

You said you're trying to generate a "simple" tree, but I assume you're trying to accomplish something beyond what the vanilla tree generation methods provide, as in, a different shape, or different blocks than vanilla leaves and logs?

 

Even if not, it might be worth a while to poke around in the vanilla methods, all in net.minecraft.world.gen.feature, to see how they're doing things. Spoiler: it's just huge mess of if statements and loops.

 

I'm trying to generate a tree with a custom leaf type and log type (already implemented). Oh, also I will look at the tree generation classes again, but which class is that generates oak trees? I can't find it :) There is just WorldGenAbstractTree and WorldGenBigTree that I can find.

 

Edit: Oh, and on doing more digging in net.minecraft.world.gen.feature, I also found WorldGenCanopyTree. That might beit, but I just need confirmation.

Link to comment
Share on other sites

The "minor" trees are handled by the WorldGenTrees class. This does the 1x1 trunk oak, birch, and jungle trees.

 

Did you mean you already had the custom leaf block and log block implemented, or that you had the generation method itself implemented?

 

I have the leaves and log implemented. Sorry for the confusion.

Link to comment
Share on other sites

At first you have to make a class that implements IWorldGenerator and register it. Let's call it Generate.java:

 

Generate.java

 

package your.package;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.MapGenBase;
import net.minecraft.world.gen.feature.WorldGenMinable;
import cpw.mods.fml.common.IWorldGenerator;

public class Generate implements IWorldGenerator
{
    public void generate(Random random, int x, int z, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
    {
        switch (world.provider.dimensionId)
        {
        case -1:
            generateNether(world, random, x * 16, z * 16);
        case 0:
            generateSurface(world, random, x * 16, z * 16);
        case 1:
            generateEnd(world, random, x * 16, z * 16);
        }
    }

    private void generateEnd(World world, Random random, int x, int z)
    {

    }

    private void generateSurface(World world, Random random, int x, int z)
    {

    }

    private void generateNether(World world, Random random, int x, int z)
    {
    	
    }
}

 

 

 

Then create a var to register it:

Main mod class:

Generate generate = new Generate();

 

And register it in init():

GameRegistry.registerWorldGenerator(generate, 0);

 

And in Generate.java you can generate your trees

Write this in generateSurface method:

 

 

for(int i = 0; i < 15; i++) // 15 is rarity
{
    int randPosX=x + random.nextInt(16);
    int randPosY=random.nextInt(250); //Max Y coordinate
    int randPosZ=z + random.nextInt(16);
    (new MaztrixTreeGen(false)).generate(world, random, randPosX, randPosY, randPosZ);
}

 

 

 

I hope it helps.

Link to comment
Share on other sites

Is it just me or would your code for the tree Y position have some nasty sideeffects?

int randPosY=random.nextInt(250); //Max Y coordinate

 

afaik, random.nextInt would give a random height from 0 to 250 in this case, and the tree should be on the ground level, not randomly flying or appearing underground which would be the case here.

--Remember to "Thank you" posts that actually helped you, and if a person seems nice, why not give them an applaud while you're at it--

Link to comment
Share on other sites

Is it just me or would your code for the tree Y position have some nasty sideeffects?

int randPosY=random.nextInt(250); //Max Y coordinate

 

afaik, random.nextInt would give a random height from 0 to 250 in this case, and the tree should be on the ground level, not randomly flying or appearing underground which would be the case here.

 

so what you're saying is this:

int randPosY= world.getHeightValue(randPosX, randPosZ);

 

instead of this:

 

int randPosY=random.nextInt(250); //Max Y coordinate

 

Edit: It still has this crash.

Link to comment
Share on other sites

so what you're saying is this:

int randPosY= world.getHeightValue(randPosX, randPosZ);

 

instead of this:

 

int randPosY=random.nextInt(250); //Max Y coordinate

 

Edit: It still has this crash.

 

Well, yea. That's what I'd do, however I do not have even the slightest knowledge how the world generation works in Minecraft but that's how I'd do it.

 

Another thing to note is that you might want to check the max-height there. Afaik the terrain in minecraft can sometimes reach about 240 blocks up (technically I think it may go all the way to 256 but it's not likely) but that means that if your tree is 11 blocks high and you create it at a height of 245 your tree will try to grow outside of the world. This is just a side-note and is doubtfully the cause of your crash but it's noteworthy.

 

Also, just to clarify, does your minecraft run without the generation code?

Caused by: java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path

This seems rather strange to me, though it could be a sideeffect of some other faulty code.

 

 

--Remember to "Thank you" posts that actually helped you, and if a person seems nice, why not give them an applaud while you're at it--

Link to comment
Share on other sites

so what you're saying is this:

int randPosY= world.getHeightValue(randPosX, randPosZ);

 

instead of this:

 

int randPosY=random.nextInt(250); //Max Y coordinate

 

Edit: It still has this crash.

 

Well, yea. That's what I'd do, however I do not have even the slightest knowledge how the world generation works in Minecraft but that's how I'd do it.

 

Another thing to note is that you might want to check the max-height there. Afaik the terrain in minecraft can sometimes reach about 240 blocks up (technically I think it may go all the way to 256 but it's not likely) but that means that if your tree is 11 blocks high and you create it at a height of 245 your tree will try to grow outside of the world. This is just a side-note and is doubtfully the cause of your crash but it's noteworthy.

 

That's true.

 

Also, just to clarify, does your minecraft run without the generation code?

Caused by: java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path

This seems rather strange to me, though it could be a sideeffect of some other faulty code.

 

Well, it did run, but every time I add any form of generation code it doesn't run. However, now it's doing something funny where when I remove all the generation code it still doesn't run. I saw on Minecraft Forum that someone was having this same problem with some other code and it is caused be lack of LWJGL for some reason. I'm running

 gradlew.bat setupDecompWorkspace --refresh-dependencies 

again to see if that solves the problem.

 

Edit: Well, that fixed the crash, I added the generation code back in and it launches now. Yay! The bad news: World Corruption (Aqain!). I was flying through my test world looking for my custom tree, then the chucks stoped loading and the loaded chunks were unloading. I said to myself, "Uh oh." I clicked escape and exited out of the world. The forge took forever to shutdown the world, and once it did, it then took forever to quit the game. I have no idea what's going on.

Link to comment
Share on other sites

	@Override
public void generate(Random random, int chunkX, int chunkZ, World world,
		IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
	int x = random.nextInt(16);
	int z = random.nextInt(16);

	this.generate(world, random, x, world.getHeightValue(x, z), z);
}

 

Umm, this is placing every single tree at chunk 0,0

 

It should be

 

int x = chunkX*16 + random.nextInt(16);
int z = chunkZ*16 + random.nextInt(16);

Link to comment
Share on other sites

What does your world generator look like, Awesome_Spider? Not the tree bit, the one that implements IWorldGenerator.

 

It looks like this:

 

package com.awsp8.wizardry.Gen;

import java.util.Random;

import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import cpw.mods.fml.common.IWorldGenerator;

public class Generate implements IWorldGenerator
{
    public void generate(Random random, int x, int z, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider){
        switch (world.provider.dimensionId){
        case -1:
            generateNether(world, random, x * 16, z * 16);
            break;
        case 0:
            generateSurface(world, random, x * 16, z * 16);
            break;
        case 1:
            generateEnd(world, random, x * 16, z * 16);
            break;
        }
    }

    private void generateEnd(World world, Random random, int x, int z){
        
    }

    private void generateSurface(World world, Random random, int x, int z){
        for(int i = 0; i < 15; i++){ // 15 is rarity
            int randPosX= x + random.nextInt(16);
            int randPosZ= z + random.nextInt(16);
            int randPosY= world.getHeightValue(randPosX, randPosZ);
            (new MaztrixTreeGen(false, 4, 0, 0, false)).generate(world, random, randPosX, randPosY, randPosZ);
        }
    }

    private void generateNether(World world, Random random, int x, int z){
        
    }
}

Link to comment
Share on other sites

I'm going to be blunt here, Awesome_Spider, and I hope you don't find this discouraging. I see a lot of copy-paste going on with little thought given to what the methods you're using actually do or how they function.

 

For instance, I see you directly copy-pasted Kuu's world generation suggestion, which is itself lifted directly from the Forge Wiki's tutorial section. You even preserved the number of iterations in the for-loop and the comment label, erroneously referring to the value 15 as "rarity". If we look at your code however, what it does is call the tree generator 15 times per generateSurface call, which itself is called on every chunk. Is this actually what you want?

 

My advice to you at this point is to set aside a bit of time to go through the code you are using and try to determine how all the pieces fit together. If you must copy-paste, you should at least understand the bits you are using, otherwise, how will you understand what's going on when things don't work? Moreover, how will you know whether the suggestions you are taking are actually what you want?

 

I am certain that if you sit down and sift through your current code and figure out how it is working, the source of the issue you are having will become apparent. You got this far, so I know you can do it! Go forth and conquer!

Link to comment
Share on other sites

Is it just me or would your code for the tree Y position have some nasty sideeffects?

int randPosY=random.nextInt(250); //Max Y coordinate

 

afaik, random.nextInt would give a random height from 0 to 250 in this case, and the tree should be on the ground level, not randomly flying or appearing underground which would be the case here.

 

It won't generate in air because MaztrixTreeGen should check if the block is grass, but i think i've got long world generating because of this, thanks, i'll use

int randPosY= world.getHeightValue(randPosX, randPosZ);

  :D

Link to comment
Share on other sites

Awesome_Spider, I copied all the code from my working mod, so I can't understand what's the problem. Do you use big or small oak tree generation?

 

Hmm, try to remove IWorldGenerator implementation and remove this from MaztrixTreeGen:

@Override
public void generate(Random random, int chunkX, int chunkZ, World world,
		IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
	int x = random.nextInt(16);
	int z = random.nextInt(16);

	this.generate(world, random, x, world.getHeightValue(x, z), z);
}

Link to comment
Share on other sites

I'm going to be blunt here, Awesome_Spider, and I hope you don't find this discouraging. I see a lot of copy-paste going on with little thought given to what the methods you're using actually do or how they function.

 

For instance, I see you directly copy-pasted Kuu's world generation suggestion, which is itself lifted directly from the Forge Wiki's tutorial section. You even preserved the number of iterations in the for-loop and the comment label, erroneously referring to the value 15 as "rarity". If we look at your code however, what it does is call the tree generator 15 times per generateSurface call, which itself is called on every chunk. Is this actually what you want?

 

My advice to you at this point is to set aside a bit of time to go through the code you are using and try to determine how all the pieces fit together. If you must copy-paste, you should at least understand the bits you are using, otherwise, how will you understand what's going on when things don't work? Moreover, how will you know whether the suggestions you are taking are actually what you want?

 

I am certain that if you sit down and sift through your current code and figure out how it is working, the source of the issue you are having will become apparent. You got this far, so I know you can do it! Go forth and conquer!

 

Thanks for the suggestion. I will go through the code. Btw, I don't get discouraged easily.

 

Edit: Ok, I've gone through the generation code, figured out how it works, and figured out what the problem might be. My custom leaf block extends Block instead of BlockLeaves. A lot of the if statements check for if there is leaves in a given location. But my leaf block, MaztrixLeaf wouldn't count as a leaf, causing errors. So if I change it to BlockLeaves it should work. :)

 

Edit Again: It Worked! :D The color of the leaves is a little off but I can fix that.

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

    • Hi! If you have your forge installation file not in the system disc on PC (D, E etc.), drag it to disk C and try to start again. In my case it solved the problem.
    • KILAT77 : Waspada Situs Scam dengan Withdraw Yang Tidak Dibayar Di era digital saat ini, banyak orang yang mencari keberuntungan melalui situs perjudian online. Namun, dibalik gemerlap janji-janji manis kemenangan, ada bahaya yang mengintai. Salah satu situs yang patut diwaspadai adalah KILAT77. Situs ini mendapat reputasi buruk karena banyak laporan dari pengguna yang mengklaim bahwa mereka tidak bisa menarik dana kemenangan mereka. Dalam artikel ini, kita akan membahas mengapa ROTER88 dianggap sebagai situs scam dan bagaimana Anda bisa melindungi diri dari penipuan serupa. Pengalaman Pengguna: Penarikan Tidak Dibayar Beberapa pengguna telah melaporkan pengalaman buruk mereka dengan KILAT77. Mereka mengaku bahwa setelah memenangkan sejumlah uang dan mencoba menariknya, proses penarikan mereka ditolak tanpa alasan yang jelas. Bahkan, beberapa pengguna melaporkan bahwa akun mereka tiba-tiba diblokir setelah mencoba melakukan penarikan, sehingga mereka kehilangan akses ke dana mereka sama sekali.
    • It is a dupe mod issue Remove Rubidium - you are already using Embeddium which is a fork of Rubidium
    • I made a block entity in forge 1.20.1, I want to prevent hopper from taking input slot item, i tried to override the extractItem method, it prevented hopper from taking input slot item, but the player also unable to take/change the item in input slot unless the slot is empty. public class FluidSeparatorBlockEntity extends BlockEntity implements MenuProvider { private static final int INPUT_SLOT = 0; private final CustomItemHandler itemHandler = new CustomItemHandler(3){ @Override protected void onContentsChanged(int slot) { setChanged(); } @Override public boolean isItemValid(int slot, @NotNull ItemStack stack) { return slot == INPUT_SLOT; } @Override public @NotNull ItemStack extractItem(int slot, int amount, boolean simulate) { if (slot == INPUT_SLOT) { return ItemStack.EMPTY; } return super.extractItem(slot, amount, simulate); } }; private LazyOptional<IItemHandler> lazyItemHandler = LazyOptional.empty(); protected final ContainerData data; private int progress = 0; private int maxProgress = 78; public FluidSeparatorBlockEntity(BlockPos pPos, BlockState pBlockState) { super(ModBlockEntities.FLUID_SEPARATOR_BE.get(), pPos, pBlockState); this.data = new ContainerData() { @Override public int get(int pIndex) { return switch (pIndex) { case 0 -> FluidSeparatorBlockEntity.this.progress; case 1, 2 -> FluidSeparatorBlockEntity.this.maxProgress; default -> 0; }; } @Override public void set(int pIndex, int pValue) { switch (pIndex) { case 0 -> FluidSeparatorBlockEntity.this.progress = pValue; case 1, 2 -> FluidSeparatorBlockEntity.this.maxProgress = pValue; } } @Override public int getCount() { return 3; } }; } @Override public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { if(cap == ForgeCapabilities.ITEM_HANDLER) { return lazyItemHandler.cast(); } return super.getCapability(cap, side); } @Override public void onLoad() { super.onLoad(); lazyItemHandler = LazyOptional.of(() -> itemHandler); } @Override public void invalidateCaps() { super.invalidateCaps(); lazyItemHandler.invalidate(); } public void drops() { SimpleContainer inventory = new SimpleContainer(itemHandler.getSlots()); for(int i = 0; i < itemHandler.getSlots(); i++) { inventory.setItem(i, itemHandler.getStackInSlot(i)); } Containers.dropContents(this.level, this.worldPosition, inventory); } @Override public Component getDisplayName() { return Component.translatable("block.chemmaster.fluid_separator"); } @Nullable @Override public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) { return new FluidSeparatorMenu(pContainerId, pPlayerInventory, this, this.data); } @Override protected void saveAdditional(CompoundTag pTag) { pTag.put("inventory", itemHandler.serializeNBT()); pTag.putInt("fluid_separator.progress", progress); super.saveAdditional(pTag); } @Override public void load(CompoundTag pTag) { super.load(pTag); itemHandler.deserializeNBT(pTag.getCompound("inventory")); progress = pTag.getInt("fluid_separator.progress"); } public void tick(Level pLevel, BlockPos pPos, BlockState pState) { ItemStack inputStack = this.itemHandler.getStackInSlot(INPUT_SLOT); if (inputStack.getCount() < 2) { resetProgress(); return; } if(hasRecipe()) { increaseCraftingProgress(); setChanged(pLevel, pPos, pState); if(hasProgressFinished()) { craftItem(); resetProgress(); } } else { resetProgress(); } } private void resetProgress() { progress = 0; } private void craftItem() { Optional<FluidSeparatingRecipe> recipe = getCurrentRecipe(); if (recipe.isPresent()) { List<ItemStack> results = recipe.get().getOutputs(); ItemStack inputStack = this.itemHandler.getStackInSlot(INPUT_SLOT); if (inputStack.getCount() < 2) { // If there are not enough items, do not proceed with crafting return; } // Extract the input item from the input slot this.itemHandler.internalExtractItem(INPUT_SLOT, 2, false); // Loop through each result item and find suitable output slots for (ItemStack result : results) { int outputSlot = findSuitableOutputSlot(result); if (outputSlot != -1) { this.itemHandler.setStackInSlot(outputSlot, new ItemStack(result.getItem(), this.itemHandler.getStackInSlot(outputSlot).getCount() + result.getCount())); } else { // Handle the case where no suitable output slot is found // This can be logging an error, throwing an exception, or any other handling logic System.err.println("No suitable output slot found for item: " + result); } } } } private int findSuitableOutputSlot(ItemStack result) { // Implement logic to find a suitable output slot for the given result // Return the slot index or -1 if no suitable slot is found for (int i = 0; i < this.itemHandler.getSlots(); i++) { // Ensure we do not place the output item in the input slot if (i == INPUT_SLOT) { continue; } ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || (stackInSlot.getItem() == result.getItem() && stackInSlot.getCount() + result.getCount() <= stackInSlot.getMaxStackSize())) { return i; } } return -1; } private boolean hasRecipe() { Optional<FluidSeparatingRecipe> recipe = getCurrentRecipe(); if (recipe.isEmpty()) { return false; } List<ItemStack> results = recipe.get().getOutputs(); for (ItemStack result : results) { if (!canInsertAmountIntoOutputSlot(result) || !canInsertItemIntoOutputSlot(result.getItem())) { return false; } } return true; } private Optional<FluidSeparatingRecipe> getCurrentRecipe(){ SimpleContainer inventory = new SimpleContainer(this.itemHandler.getSlots()); for (int i = 0; i < itemHandler.getSlots(); i++) { inventory.setItem(i, this.itemHandler.getStackInSlot(i)); } return this.level.getRecipeManager().getRecipeFor(FluidSeparatingRecipe.Type.INSTANCE, inventory, level); } private boolean canInsertAmountIntoOutputSlot(ItemStack result) { for (int i = 1; i < this.itemHandler.getSlots(); i++) { ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || (stackInSlot.getItem() == result.getItem() && stackInSlot.getCount() + result.getCount() <= stackInSlot.getMaxStackSize())) { return true; } } return false; } private boolean canInsertItemIntoOutputSlot(Item item) { for (int i = 1; i < this.itemHandler.getSlots(); i++) { ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || stackInSlot.getItem() == item) { return true; } } return false; } private boolean hasProgressFinished() { return progress >= maxProgress; } private void increaseCraftingProgress() { progress++; } }  
  • Topics

×
×
  • Create New...

Important Information

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