Jump to content

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


Recommended Posts

Posted

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. :)

Posted

What have you tried? Also, post the crash logs.

 

Sorry, I've recently updated my mod to 1.7.10 so I don't have access to the crash logs. But if this helps it was saying something about an ArrayIndexOutOfBoundsException.

Posted

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.

Posted

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.

Posted

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?

Posted

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.

Posted

To answer the question in your edit, WorldGenCanopyTree is the "big" oak trees' generation algorithm.

Oh ok :)

 

I'll try using the code in WorldGenTrees.

Posted

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.

Posted

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

Posted

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.

Posted

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

Posted

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.

Posted

	@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);

Posted

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){
        
    }
}

Posted

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!

Posted

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

Posted

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);
}

Posted

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.

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

    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
    • Okay, but does the modpack works with 1.12 or just with 1.12.2, because I need the Forge client specifically for Minecraft 1.12, not 1.12.2
    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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