Jump to content

Recommended Posts

Posted

Hey i am wondering if anyone knows how to generate a custom ore in a a block other than stone.  i am trying to create an ore that will only spawn in the sand. I know i need to make a new worldgen file and i have one written that works for spawning ores in the nether, but i cannot figure out how to get my ore to spawn in sand.  Any help or tips would be much apreciated

Posted

I looked at the mod that contained the oil sands but the world gen file was interlaced with like 10 other files not relted to generating the ores.  in short i couldn't figure it out

Posted

You could post your solution (or a comment how to do it). It's not nice to have a "solved" topic with no information on how to actually do it...

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Posted

Alright so all you have to do is copy the worldgenminable file into a new class called worldgensand or whatever you want to call it.  Then delete this line of code at the bottom:

 

 

        if (var39 * var39 + var42 * var42 + var45 * var45 < 1.0D && (block != null &&        block.isGenMineableReplaceable(par1World, var38, var41, var44)))

 

 

And replace it with this:

 

 

      if (var39 * var39 + var42 * var42 + var45 * var45 < 1.0D && par1World.getBlockId(var38, var41, var44) == Block.sand.blockID)

 

Then you can change the block.sand to whatever block youd like! This also works for the worldgennether class or worldgenend class needed to spawn ores in the nether or end, just change the block.sand to netherrack or end stone.  It can also be used to spawn ores at the bottom of oceans and such things by placing this piece of code at the top of the public boolean generate constructer.

 

          if (par1World.getBlockMaterial(par3, par4, par5) != Material.water)

        {

            return false;

        }

        else

 

 

Telling the block to check if it is touching water and if not to not generate.

if it dosent work or i was to confusing let me know and ill try to explain it better! Hope this helps

Posted

so do you just create a copycat world gen minable class? with that one line changed ?

because when i do i cant get my world gen file to recognise it

for(int i = 0; i < 40; i++){
	int xCoord = chunkX + random.nextInt(80);
	int yCoord = random.nextInt(64);
	int zCoord = chunkZ + random.nextInt(80);
	(new ashtonsmod.WorldGenMinableSand(ashtonsmod.AmethystOre.blockID, 5)).generate(world, random, xCoord, yCoord, zCoord);

}

an error appears under the ashtonsmod.WorldGenMinableSand file saying its not there.

 

I created this file in ashtonsmod.common

package ashtonsmod.common;

import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;

public class WorldGenMinableSand extends WorldGenerator
{
    /** The block ID of the ore to be placed using this generator. */
    private int minableBlockId;
    private int minableBlockMeta = 0;

    /** The number of blocks to generate. */
    private int numberOfBlocks;

    public WorldGenMinableSand(int par1, int par2)
    {
        this.minableBlockId = par1;
        this.numberOfBlocks = par2;
    }

    public WorldGenMinableSand(int id, int meta, int number)
    {
        this(id, number);
        minableBlockMeta = meta;
    }

    public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
    {
        float var6 = par2Random.nextFloat() * (float)Math.PI;
        double var7 = (double)((float)(par3 +  + MathHelper.sin(var6) * (float)this.numberOfBlocks / 8.0F);
        double var9 = (double)((float)(par3 +  - MathHelper.sin(var6) * (float)this.numberOfBlocks / 8.0F);
        double var11 = (double)((float)(par5 +  + MathHelper.cos(var6) * (float)this.numberOfBlocks / 8.0F);
        double var13 = (double)((float)(par5 +  - MathHelper.cos(var6) * (float)this.numberOfBlocks / 8.0F);
        double var15 = (double)(par4 + par2Random.nextInt(3) - 2);
        double var17 = (double)(par4 + par2Random.nextInt(3) - 2);

        for (int var19 = 0; var19 <= this.numberOfBlocks; ++var19)
        {
            double var20 = var7 + (var9 - var7) * (double)var19 / (double)this.numberOfBlocks;
            double var22 = var15 + (var17 - var15) * (double)var19 / (double)this.numberOfBlocks;
            double var24 = var11 + (var13 - var11) * (double)var19 / (double)this.numberOfBlocks;
            double var26 = par2Random.nextDouble() * (double)this.numberOfBlocks / 16.0D;
            double var28 = (double)(MathHelper.sin((float)var19 * (float)Math.PI / (float)this.numberOfBlocks) + 1.0F) * var26 + 1.0D;
            double var30 = (double)(MathHelper.sin((float)var19 * (float)Math.PI / (float)this.numberOfBlocks) + 1.0F) * var26 + 1.0D;
            int var32 = MathHelper.floor_double(var20 - var28 / 2.0D);
            int var33 = MathHelper.floor_double(var22 - var30 / 2.0D);
            int var34 = MathHelper.floor_double(var24 - var28 / 2.0D);
            int var35 = MathHelper.floor_double(var20 + var28 / 2.0D);
            int var36 = MathHelper.floor_double(var22 + var30 / 2.0D);
            int var37 = MathHelper.floor_double(var24 + var28 / 2.0D);

            for (int var38 = var32; var38 <= var35; ++var38)
            {
                double var39 = ((double)var38 + 0.5D - var20) / (var28 / 2.0D);

                if (var39 * var39 < 1.0D)
                {
                    for (int var41 = var33; var41 <= var36; ++var41)
                    {
                        double var42 = ((double)var41 + 0.5D - var22) / (var30 / 2.0D);

                        if (var39 * var39 + var42 * var42 < 1.0D)
                        {
                            for (int var44 = var34; var44 <= var37; ++var44)
                            {
                                double var45 = ((double)var44 + 0.5D - var24) / (var28 / 2.0D);
                                Block block = Block.blocksList[par1World.getBlockId(var38, var41, var44)];

                                if (var39 * var39 + var42 * var42 + var45 * var45 < 1.0D && par1World.getBlockId(var38, var41, var44) == Block.sand.blockID)
                                {
                                    par1World.setBlockAndMetadata(var38, var41, var44, this.minableBlockId, minableBlockMeta);
                                }
                            }
                        }
                    }
                }
            }
        }

        return true;
    }
}

 

 

Use examples, i have aspergers.

Examples make sense to me.

Posted

You should learn how java packets work.

 

(new ashtonsmod.common.WorldGenMinableSand(ashtonsmod.AmethystOre.blockID, 5)).generate(world, random, xCoord, yCoord, zCoord);

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

would like help not be told to go learn java again...

 

I gave you the solution before, just use it :P

 

Lemme explain: you try to access ashtonsmod.WorldGenMinableSand while having the WorldGen in the packet tree ashtonsmod.common

So the solution is to correctly adapt the packet tree, like this: ashtonsmod.common.WorldGenMinableSand

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

ashtonsmod.common cannot be resolved to a type the fix you told me doesnt work.

 

(new ashtonsmod.common.WorldGenMinableSand(ashtonsmod.AmethystOre.blockID, 5)).generate(world, random, xCoord, yCoord, zCoord);

Use examples, i have aspergers.

Examples make sense to me.

Posted

ok so this now throws no errors but im not sure if it works or not as i cannot find any ore in the sand.

 

minable sand class;

package ashtonsmod.common;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;

public class WorldGenMinableSand extends WorldGenerator
{
    /** The block ID of the ore to be placed using this generator. */
    private int minableBlockId;
    private int minableBlockMeta = 0;

    /** The number of blocks to generate. */
    private int numberOfBlocks;

    public WorldGenMinableSand(int par1, int par2)
    {
        this.minableBlockId = par1;
        this.numberOfBlocks = par2;
    }

    public WorldGenMinableSand(int id, int meta, int number)
    {
        this(id, number);
        minableBlockMeta = meta;
    }

    public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
    {
        float var6 = par2Random.nextFloat() * (float)Math.PI;
        double var7 = (double)((float)(par3 +  + MathHelper.sin(var6) * (float)this.numberOfBlocks / 8.0F);
        double var9 = (double)((float)(par3 +  - MathHelper.sin(var6) * (float)this.numberOfBlocks / 8.0F);
        double var11 = (double)((float)(par5 +  + MathHelper.cos(var6) * (float)this.numberOfBlocks / 8.0F);
        double var13 = (double)((float)(par5 +  - MathHelper.cos(var6) * (float)this.numberOfBlocks / 8.0F);
        double var15 = (double)(par4 + par2Random.nextInt(3) - 2);
        double var17 = (double)(par4 + par2Random.nextInt(3) - 2);

        for (int var19 = 0; var19 <= this.numberOfBlocks; ++var19)
        {
            double var20 = var7 + (var9 - var7) * (double)var19 / (double)this.numberOfBlocks;
            double var22 = var15 + (var17 - var15) * (double)var19 / (double)this.numberOfBlocks;
            double var24 = var11 + (var13 - var11) * (double)var19 / (double)this.numberOfBlocks;
            double var26 = par2Random.nextDouble() * (double)this.numberOfBlocks / 16.0D;
            double var28 = (double)(MathHelper.sin((float)var19 * (float)Math.PI / (float)this.numberOfBlocks) + 1.0F) * var26 + 1.0D;
            double var30 = (double)(MathHelper.sin((float)var19 * (float)Math.PI / (float)this.numberOfBlocks) + 1.0F) * var26 + 1.0D;
            int var32 = MathHelper.floor_double(var20 - var28 / 2.0D);
            int var33 = MathHelper.floor_double(var22 - var30 / 2.0D);
            int var34 = MathHelper.floor_double(var24 - var28 / 2.0D);
            int var35 = MathHelper.floor_double(var20 + var28 / 2.0D);
            int var36 = MathHelper.floor_double(var22 + var30 / 2.0D);
            int var37 = MathHelper.floor_double(var24 + var28 / 2.0D);

            for (int var38 = var32; var38 <= var35; ++var38)
            {
                double var39 = ((double)var38 + 0.5D - var20) / (var28 / 2.0D);

                if (var39 * var39 < 1.0D)
                {
                    for (int var41 = var33; var41 <= var36; ++var41)
                    {
                        double var42 = ((double)var41 + 0.5D - var22) / (var30 / 2.0D);

                        if (var39 * var39 + var42 * var42 < 1.0D)
                        {
                            for (int var44 = var34; var44 <= var37; ++var44)
                            {
                                double var45 = ((double)var44 + 0.5D - var24) / (var28 / 2.0D);
                                Block block = Block.blocksList[par1World.getBlockId(var38, var41, var44)];

                                if (var39 * var39 + var42 * var42 + var45 * var45 < 1.0D && par1World.getBlockId(var38, var41, var44) == Block.sand.blockID)
                                {
                                    par1World.setBlockAndMetadata(var38, var41, var44, this.minableBlockId, minableBlockMeta);
                                }
                            }
                        }
                    }
                }
            }
        }

        return true;
    }
}

 

worldgen class;

package ashtonsmod.common;

import java.util.Random;

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

public class WorldGen implements IWorldGenerator{
    
private static final int BlockX = 0;
private int BlockZ;

@Override
public void generate(Random random, int chunkX, int chunkZ, World world,IChunkProvider chunkGenerator, IChunkProvider chunkProvider){
        
  switch(world.provider.dimensionId){
            case 1:
                generateNether(world, random, chunkX * 16, chunkZ * 16);
            case 0:
                generateSurface(world, random, chunkX * 16, chunkZ * 16);
            case -1:
                generateEnd(world, random, chunkX * 16, chunkZ * 16);
  }
  
}
    
private void generateNether(World world, Random random, int chunkX, int chunkZ) {
}

private void generateEnd(World world, Random random, int chunkX, int chunkZ){
}
    
private void generateSurface(World world, Random random, int chunkX,int chunkZ){
   int xCoord = chunkX;
   int yCoord = random.nextInt(64);
   int zCoord = chunkZ;
   (new WorldGenMinable(ashtonsmod.LightSteelOre.blockID, 7)).generate(world, random, (xCoord + random.nextInt(60)), yCoord, (zCoord + random.nextInt(60)));
   (new WorldGenMinable(ashtonsmod.AmethystOre.blockID, 5)).generate(world, random, (xCoord  + random.nextInt(60)), yCoord, (zCoord + random.nextInt(80)));
   (new WorldGenMinableSand(ashtonsmod.AmethystOre.blockID, 5)).generate(world, random, (xCoord  + random.nextInt(60)), yCoord, (zCoord + random.nextInt(10)));
  } 
}
   

 

just had a thought, i would like it to spawn in surface sand and this is where i am looking for it, did i get the y coord wrong for this?

Use examples, i have aspergers.

Examples make sense to me.

Posted

You can check in the console if it's generating at all with using this

System.out.println(String.format("Sand Ore generated at > x:%s | y:%s | z:%s <", var38, var41, var44));

below

par1World.setBlockAndMetadata(var38, var41, var44, this.minableBlockId, minableBlockMeta);

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

I don't think that this forum should serve as a support forum for programming or Java. Imo these topics/posts should be closed/moved/posts deleted, if the problem lies in insufficient knowledge of elemental Java and is not MC/forge/fml specific. Also I don't think that kind souls helping those in need should be posting snippets of code. It would be more logical to just post a description or pseudo-code of how to achieve a solution or fix a problem. If the asker cannot write it on his/her own, he/she should learn Java first.

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Posted

try and follow this,

1. assume i have a complete and utter perfect understanding of java.

2. therefore with a little experimentation i could code anything i liked into minecraft with no need from this forum.

3.therefore this forum is for people who do NOT have a complete understanding of java and cannot code anything they like into minecraft with no help.

4. therefore you should stop telling me to go learn more java because i came here because i didnt know enough and am seeking help.

Use examples, i have aspergers.

Examples make sense to me.

Posted

so can someone help me make the ore that spawns in sand spawn higher? like on surface sand in deserts and stuff? not just lower down?

i need to do this without raising the other two ores up and the y coord specifications are written before the ores are set.

 

package ashtonsmod.common;

import java.util.Random;

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

public class WorldGen implements IWorldGenerator{
    
private static final int BlockX = 0;
private int BlockZ;

@Override
public void generate(Random random, int chunkX, int chunkZ, World world,IChunkProvider chunkGenerator, IChunkProvider chunkProvider){
        
  switch(world.provider.dimensionId){
            case 1:
                generateNether(world, random, chunkX * 16, chunkZ * 16);
            case 0:
                generateSurface(world, random, chunkX * 16, chunkZ * 16);
            case -1:
                generateEnd(world, random, chunkX * 16, chunkZ * 16);
  }
  
}
    
private void generateNether(World world, Random random, int chunkX, int chunkZ) {
}

private void generateEnd(World world, Random random, int chunkX, int chunkZ){
}
    
private void generateSurface(World world, Random random, int chunkX,int chunkZ){
   int xCoord = chunkX;
   int yCoord = random.nextInt(64);
   int zCoord = chunkZ;
   (new WorldGenMinable(ashtonsmod.LightSteelOre.blockID, 7)).generate(world, random, (xCoord + random.nextInt(60)), yCoord, (zCoord + random.nextInt(60)));
   (new WorldGenMinable(ashtonsmod.AmethystOre.blockID, 5)).generate(world, random, (xCoord  + random.nextInt(60)), yCoord, (zCoord + random.nextInt(80)));
   (new WorldGenMinableSand(ashtonsmod.AmethystOre.blockID, 15)).generate(world, random, (xCoord  + random.nextInt(40)), yCoord, (zCoord + random.nextInt(40)));
  } 
}
   

Use examples, i have aspergers.

Examples make sense to me.

Posted

Ok first off i am going to say that a complete understanding of java is not necessary to be able to make mods for minecraft.  I used minecraft as a tool to learn java and it worked quite well.  i now have a pretty solid base understanding of how java operates.  So if You have questions please ask and the people that understand it a little better should try to help you learn.  Now to fix your spawn height problem you need separate generation parameters for each ore, like this:

 

 

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

{

int xCoord = X + random.nextInt(16);

int yCoord = random.nextInt(30);

int zCoord = Z + random.nextInt(16);

//vein max size

(new WorldGenMinable(mod_wac.oreWaconium.blockID, 4)).generate(world, random, xCoord, yCoord, zCoord);

 

 

 

}

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

{

int xCoord = X + random.nextInt(16);

int yCoord = random.nextInt(120);

int zCoord = Z + random.nextInt(16);

//vein max size

(new WorldGenMinable(mod_wac.oreEnder.blockID, 10)).generate(world, random, xCoord, yCoord, zCoord);

 

 

 

}

 

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

{

int xCoord = X + random.nextInt(16);

int yCoord = random.nextInt(48);

int zCoord = Z + random.nextInt(16);

//vein max size

(new WorldGenAqua(mod_wac.oreAqua.blockID, 15)).generate(world, random, xCoord, yCoord, zCoord);

 

 

 

this will allow you to change the spawn features of each ore individually so your sand ore will spawn higher

Posted

try and follow this,

1. assume i have a complete and utter perfect understanding of java.

2. therefore with a little experimentation i could code anything i liked into minecraft with no need from this forum.

not true, even with perfect understanding of java (which I have not) I wouldn't necessarily know all about MC code. but on the other hand, majority of question being asked here has either been already answered on the forum in older topic(s) or are described on the wiki. a lot of askers expect to post code here and wait until someone else fixes their code...

 

3.therefore this forum is for people who do NOT have a complete understanding of java and cannot code anything they like into minecraft with no help.

4. therefore you should stop telling me to go learn more java because i came here because i didnt know enough and am seeking help.

as diesieben07 wrote, you don't need complete or perfect understanding of java, you need BASIC understanding of Java (e.g. what static means, how to use packages, read crash log, what null means and so on). if you came here to seek infomation about basics of programming and/or Java, you're at a wrong place. this not Java support forum, this is support forum for Minecraft modders working with Forge.

 

it's been written many times, firstly learn basics of java then start modding. if you have programming background from similar OOP language (e.g. C++, C#, Python) it's pretty easy to start modding even without reading much about Java itself.

 

PS: At a start I tried to help many people on this forum, but after some time I realized that most of my replies were just "look at this older topic which solves what you want" or "look at the wiki". Rest of the time I just spent explaining how to use loops to get every block in a cube or why static members in proxy don't work <- I should have just wrote "learn java". I feel that more I help people without basics of Java the less motivation for them to actually understand/learn Java and more useless topics appear here, burying those few with interesting question or elegant soltuions of common problems... :-\

 

@bwrobinson13: I recommned using code tags or forge's pastebin, it's much more readable ;).

 

also the numbers next to the chunk generation? are they frequency or maxheight or what?

i know thier something like that.

If I'm not mistaken the number in constructor stands for number of blocks you want to be generated(~ size of vein). Parameter of a random number generation in yCoord determines maximal height and a number of iterations denotes count of veins per chunk.

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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