Jump to content

How can I code this ?


Phenolphtaleine

Recommended Posts

Hi everyone,

I'm currently making a tech-mod and I'm locked at a point where i'd need some help.

I'd like to know how could I make a tree generates, and when I break the logs, I could get the rubber from my mod.

Thanks for the help ! Tongue

EDIT: I'm in 1.9.4

R-EDIT: I think i will change this topic to be my new mod help topic :P

Link to comment
Share on other sites

In the blocks clads override a method i believe it is called getDrops() don't quote me on that...

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

Pheno I know this is kind of an random question. And keep in mind im not trying to make you do this. But im always looking for a partner to make a mod with. I know its a bit random but im trying to find a conpanion. And as for your rubber drop. It should be what he said. Thanks. And if you would like to make a mod togther Email me. Again not making you but my email is [email protected]

Are You Feeling it now Mr.Krabs?

 

GitHub

https://github.com/nuclearelectricity/Nuclear-Electricity

Link to comment
Share on other sites

You would do it the same way you would ores, but instead of WorldGenMinable you need to make your own for trees, or you might be able to use a vanilla one.

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 actually, I can't find any tutorial to code a type of tree that would generate in the overworld in 1.9.4

Do you know how to do it ?

Thanks :)

 

The vanilla trees are placed in worldgen by various classes (WorldGenTrees (oak by default), WorldGenBirchTree, WorldGenSavannaTree etc) which all extend WorldGenAbstractTree, which extends WorldGenerator already.

 

You can take a shortcut, and call WorldGenTrees with the constructor of

boolean notify, int minHeight, IBlockState logBlock, IBlockState leafBlock, boolean haveVines

. (Notify should be "true", otherwise clients won't see the tree) It will create a normal oak-structured tree for you, with the specified blocks already. This is of course unless you want your tree to have a custom appearance (Like Thaumcraft's or Forestry's trees, for example). For that, you would have to lookup said WorldGen____ classes and see how they use the WorldGenAbstractTree methods.

 

To actually implement the actual worldgen, I would advice you to create a class that implements IWorldGenerator, and then register it in the

init phase

with

GameRegistry.registerWorldGenerator(new NameOfWorldGenClass(), weight);

where

weight

is an integer that states in what approximate order it falls into during worldgen, where low numbers usually go first, high numbers gets placed last.

I have an IWorldGenerator that places several different vanilla trees, you can view it here:

https://github.com/Matryoshika/Underworld/blob/master/src/main/java/se/Matryoshika/Underworld/WorldGen/Dirty/DirtyTreeGen.java

You cannot simply copy paste though (Not saying I thought you would, just that you cannot) because it is used in wordgen that uses a different WorldProvider & BiomeProvider entirely. Ignore the code that references those.

 

I'd advice you to use the

generate

method to get a blockpos first, using World#getTopSolidOrLiquidBlock(pos) where pos only uses the x & z blockpos gained from the method's chunkX & chunkZ coords.

Then, see if the tree can spawn with a boolean method (If the blockpos gained contains grass/dirt (hardcoded check into the WorldGenTree classes, if there's not grass/dirt, it doesnt spawn)). Then, you call your actual generateTree method, that places the tree at the pos#up() coord.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

Aight Big thanks to both of you !

But now i've got another problem :/

I did an ore generation for my ore (allium).

All is running correctly, but when I make a new world to see if the ore generates, it crashes ;-;.

Here's the report :[embed=425,349]WARNING: coremods are present:

  IC2core (industrialcraft-2-2.5.63-ex19-dev.jar)

Contact their authors BEFORE contacting forge

 

// I just don't know what went wrong :(

 

Time: 28/08/16 12:33

Description: Exception in server tick loop

 

java.lang.NullPointerException: Exception in server tick loop

at init.worldgen.WorldGen.runGenerator(WorldGen.java:59)

at init.worldgen.WorldGen.generate(WorldGen.java:34)

at net.minecraftforge.fml.common.registry.GameRegistry.generateWorld(GameRegistry.java:113)

at net.minecraft.world.chunk.Chunk.populateChunk(Chunk.java:1075)

at net.minecraft.world.chunk.Chunk.populateChunk(Chunk.java:1057)

at net.minecraft.world.gen.ChunkProviderServer.provideChunk(ChunkProviderServer.java:163)

at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:335)

at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:106)

at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:123)

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:494)

at java.lang.Thread.run(Unknown Source)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- System Details --

Details:

Minecraft Version: 1.9.4

Operating System: Windows 8.1 (amd64) version 6.3

Java Version: 1.8.0_31, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 712922584 bytes (679 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

IntCache: cache: 1, tcache: 1, allocated: 12, tallocated: 94

FML: MCP 9.28 Powered by Forge 12.17.0.2051 5 mods loaded, 5 mods active

States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

UCHIJAA mcp{9.19} [Minecraft Coder Pack] (minecraft.jar)

UCHIJAA FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.9.4-12.17.0.2051.jar)

UCHIJAA Forge{12.17.0.2051} [Minecraft Forge] (forgeSrc-1.9.4-12.17.0.2051.jar)

UCHIJAA advancedic2{0.1-alpha} [Advanced IC2] (bin)

UCHIJAA IC2{2.5.63-ex19} [industrialCraft 2] (industrialcraft-2-2.5.63-ex19-dev.jar)

Loaded coremods (and transformers):

IC2core (industrialcraft-2-2.5.63-ex19-dev.jar)

 

GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.

Profiler Position: N/A (disabled)

Player Count: 0 / 8; []

Type: Integrated Server (map_client.txt)

Is Modded: Definitely; Client brand changed to 'fml,forge'

[12:33:18] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:649]: #@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2016-08-28_12.33.16-server.txt

[12:33:18] [Client Shutdown Thread/INFO]: Stopping server

[12:33:18] [Client Shutdown Thread/INFO]: Saving players

[12:33:18] [Client Shutdown Thread/INFO]: Saving worlds

AL lib: (EE) alc_cleanup: 1 device not closed

Java HotSpot 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release[/embed]

Link to comment
Share on other sites

Post the all OreGeneration Code and please use spoilers for things like crash reports and code tags for code.

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

[3:06:11 PM] Adam: ...

[3:06:26 PM] Adam: Wtf

[3:07:17 PM] Adam: Dude you gotta trust me I'm not going to do anything. Teamviewer was so we could see each others screens

[3:07:26 PM] Adam: ill give you my username and password

[3:07:36 PM] Adam: 948 955 252

[3:07:41 PM] Adam: 13js1s

Im sorry guys but i have no other way of contacting him hes scared of me doing something to his computer

There are things called PM's and I assume he emailed you.

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

Post the all OreGeneration Code and please use spoilers for things like crash reports and code tags for code.

 

Aight, here's the oregen code WITH SPOILER :

 

That's the WorldGenMineable.java

 

 

package init.worldgen;

 

import java.util.Random;

 

import com.google.common.base.Predicate;

 

import net.minecraft.block.state.IBlockState;

import net.minecraft.block.state.pattern.BlockMatcher;

import net.minecraft.init.Blocks;

import net.minecraft.util.math.BlockPos;

import net.minecraft.util.math.MathHelper;

import net.minecraft.world.World;

import net.minecraft.world.gen.feature.WorldGenerator;

 

public class WorldGenMineable extends WorldGenerator

{

    private final IBlockState oreBlock;

    /** The number of blocks to generate. */

    private final int numberOfBlocks;

    private final Predicate<IBlockState> predicate;

 

    public WorldGenMineable(IBlockState alliumore, int blockCount)

    {

        this(alliumore, blockCount, BlockMatcher.forBlock(Blocks.STONE));

    }

 

    public WorldGenMineable(IBlockState state, int blockCount, Predicate<IBlockState> p_i45631_3_)

    {

        this.oreBlock = state;

        this.numberOfBlocks = blockCount;

        this.predicate = p_i45631_3_;

    }

 

public boolean generate(World worldIn, Random rand, BlockPos position)

    {

        float f = rand.nextFloat() * (float)Math.PI;

        double d0 = (double)((float)(position.getX() + 8) + MathHelper.sin(f) * (float)this.numberOfBlocks / 8.0F);

        double d1 = (double)((float)(position.getX() + 8) - MathHelper.sin(f) * (float)this.numberOfBlocks / 8.0F);

        double d2 = (double)((float)(position.getZ() + 8) + MathHelper.cos(f) * (float)this.numberOfBlocks / 8.0F);

        double d3 = (double)((float)(position.getZ() + 8) - MathHelper.cos(f) * (float)this.numberOfBlocks / 8.0F);

        double d4 = (double)(position.getY() + rand.nextInt(3) - 2);

        double d5 = (double)(position.getY() + rand.nextInt(3) - 2);

 

        for (int i = 0; i < this.numberOfBlocks; ++i)

        {

            float f1 = (float)i / (float)this.numberOfBlocks;

            double d6 = d0 + (d1 - d0) * (double)f1;

            double d7 = d4 + (d5 - d4) * (double)f1;

            double d8 = d2 + (d3 - d2) * (double)f1;

            double d9 = rand.nextDouble() * (double)this.numberOfBlocks / 16.0D;

            double d10 = (double)(MathHelper.sin((float)Math.PI * f1) + 1.0F) * d9 + 1.0D;

            double d11 = (double)(MathHelper.sin((float)Math.PI * f1) + 1.0F) * d9 + 1.0D;

            int j = MathHelper.floor_double(d6 - d10 / 2.0D);

            int k = MathHelper.floor_double(d7 - d11 / 2.0D);

            int l = MathHelper.floor_double(d8 - d10 / 2.0D);

            int i1 = MathHelper.floor_double(d6 + d10 / 2.0D);

            int j1 = MathHelper.floor_double(d7 + d11 / 2.0D);

            int k1 = MathHelper.floor_double(d8 + d10 / 2.0D);

 

            for (int l1 = j; l1 <= i1; ++l1)

            {

                double d12 = ((double)l1 + 0.5D - d6) / (d10 / 2.0D);

 

                if (d12 * d12 < 1.0D)

                {

                    for (int i2 = k; i2 <= j1; ++i2)

                    {

                        double d13 = ((double)i2 + 0.5D - d7) / (d11 / 2.0D);

 

                        if (d12 * d12 + d13 * d13 < 1.0D)

                        {

                            for (int j2 = l; j2 <= k1; ++j2)

                            {

                                double d14 = ((double)j2 + 0.5D - d8) / (d10 / 2.0D);

 

                                if (d12 * d12 + d13 * d13 + d14 * d14 < 1.0D)

                                {

                                    BlockPos blockpos = new BlockPos(l1, i2, j2);

 

                                    IBlockState state = worldIn.getBlockState(blockpos);

                                    if (state.getBlock().isReplaceableOreGen(state, worldIn, blockpos, this.predicate))

                                    {

                                        worldIn.setBlockState(blockpos, this.oreBlock, 2);

                                    }

                                }

                            }

                        }

                    }

                }

            }

        }

 

        return true;

    }

}

 

 

And that's the world gen

 

 

 

package init.worldgen;

 

import java.util.Random;

 

import com.google.common.base.Predicate;

 

import net.minecraft.util.math.BlockPos;

import net.minecraft.world.World;

import net.minecraft.world.chunk.IChunkGenerator;

import net.minecraft.world.chunk.IChunkProvider;

import net.minecraft.world.gen.feature.WorldGenerator;

import net.minecraftforge.fml.common.IWorldGenerator;

import phenolphtaleine.advancedic2.Reference.aIC2Blocks;

 

public class WorldGen implements IWorldGenerator

{

 

//OverWorldOres

private WorldGenerator ALLIUMORE;

 

public WorldGen()

{

 

}

 

@Override

public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator,

IChunkProvider chunkProvider)

{

switch(world.provider.getDimension())

{

case 0: //OverWorld

 

this.runGenerator(this.ALLIUMORE, world, random, chunkX, chunkZ, 40, 0, 40);

 

break;

 

case -1: //Nether

 

break;

   

case 1:  //EndWorld

 

break;

}

}

 

private void runGenerator(WorldGenerator generator, World world, Random random, int chunkX, int chunkZ, int chanceToSpawn, int minHeight, int maxHeight)

{

if(minHeight < 0 || maxHeight >256 || minHeight > maxHeight)

throw new IllegalArgumentException("Minimum or Max height out of bounds");

 

int heightDiff = maxHeight = minHeight +1;

for(int i = 0; i < chanceToSpawn; i++)

{

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

int y = minHeight + random.nextInt(heightDiff);

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

generator.generate(world, random, new BlockPos(x, y, z));

}

}

 

 

}

 

 

 

Here we go

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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