Jump to content

Make ore spawn in certain blocks besides stone? (sand)


bwrobinson13

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • !warudo.isClientSide() still not a gui not an error just a simple message [06:44:39] [Render thread/WARN] [minecraft/MenuScreens]: Failed to create screen for menu type: mercmod:gem_polishing_menu Not a hint of what the problem is  this silent simple error dont tell much about the problem the code i made don't show errors highlighted   in mi old code 1.19.4 i launch the menu part from client side  but now i recheck the video and kapenjoe does it server side         
    • Hey, for getting your model to show up in Forge, double-check the way you've set up your model registration. Sometimes, it's just a tiny mix-up with where you've put your model file or maybe missing the right event to hook it up. Also, peek at your @Mod.EventBusSubscriber setup; it's gotta be listening in the right place. And don't forget to place your model file in the exact right spot with the correct naming. If in doubt, the Forge docs or forum threads can be super helpful.
    • Since flying mobs like bees and flies aren't affected, the problem likely lies with how ground mob AI interacts with the server environment. Checking the server logs, as you've done, is a good step. You might want to look for errors related to mob AI or pathfinding. Consider removing or updating mods one at a time to isolate the issue. Additionally, ensure your server's performance isn't being overly taxed by the modpack, as this can sometimes lead to unusual behavior with entity AI.
    • I'm having the same issue rn. Hostile mobs wont move until attacked but peaceful land mobs wont move at all. If it swims or flies its unaffected until it touches blocks.
    • Im trying to register model for my item but it doesn't works. First I Created a class where i declared all my items.   public class ModItems { public static final List<Item> ITEMS = new ArrayList<Item>(); public static final Item MY_ITEM = new MyItemClass(); } Then I created the MyItemClass where i describe my item. public class MyItemClass extends Item { public MyItemClass() { this.setRegistryName("my_item"); this.setUnlocalizedName("my_item"); this.setCreativeTab(CreativeTabs.COMBAT); ModItems.ITEMS.add(this); } } And The i created a class where i was trying register the model and where i registered my item @Mod.EventBusSubscriber public class EventsHandler { @SubscribeEvent public void registerItems(RegistryEvent.Register<Item> event) { event.getRegistry().register(new MyItemClass()); } @SubscribeEvent @SideOnly(Side.CLIENT) public static void onRegistryModel(ModelRegistryEvent event) { registryModel(new MyItemClass()); } @SideOnly(Side.CLIENT) private static void registryModel(Item item) { final ResourceLocation regName = item.getRegistryName(); final ModelResourceLocation mr1 = new ModelResourceLocation(regName, "inventory"); ModelBakery.registerItemVariants(item, mr1); ModelLoader.setCustomModelResourceLocation(item, 0, mr1); } } The registerItems method just registers my items. Then im catching ModelRegistryEvent to register my model. And in the last private method im registering models. In The game iitem still has purple-black cube instead of texture. I dont forgot to create the models\item folder and my_item.json file im sorry if this text has a grammatical errors. My english is very low  
  • Topics

×
×
  • Create New...

Important Information

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