Jump to content

[SOLVED]Ore not generating and not accepting texture


crystalhero05

Recommended Posts

I have a problem with my ore being generated and it doesn't accept the texture code. First it was only the texture but I thought I will deal with it later. Then when I added water generation (like the clay generation code) it wouldn't generate.

 

Main class:

 

 

package first.mod;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.item.EnumArmorMaterial;

import net.minecraft.item.EnumToolMaterial;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

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

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

import net.minecraftforge.common.EnumHelper;

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.registry.GameRegistry;

import cpw.mods.fml.common.registry.LanguageRegistry;

import first.mod.armor.RedArmor;

import first.mod.block.BlockRedBlock;

import first.mod.block.RedOre;

import first.mod.creativetabs.CreativeTabsRed;

import first.mod.item.ItemRedThing;

import first.mod.item.ItemRedaxe;

import first.mod.item.ItemRedpick;

import first.mod.item.ItemRedshovel;

import first.mod.item.ItemRedsword;

import first.mod.placeholder.RedPlaceHolder;

import first.mod.worldgeneration.RedOreWorldGeneration;

 

 

@Mod(modid = "FirstMod", name ="FirstMod", version = "0.1")

 

public class Base{

 

//EnumToolMaterial

public static EnumToolMaterial toolRed = EnumHelper.addToolMaterial("RED", 3, 1000, 10.0F, 4.0F, 30);

public static EnumArmorMaterial armorRed = EnumHelper.addArmorMaterial("Red", 66, new int[]{6, 9, 9, 6}, 30);

 

//registration

public static Item Redpick = new ItemRedpick(2000, toolRed).setUnlocalizedName("Redpick");

public static Item Redsword = new ItemRedsword(2001, toolRed).setUnlocalizedName("Redsword");

public static Item Redshovel = new ItemRedshovel(2002, toolRed).setUnlocalizedName("Redshovel");

public static Item Redaxe = new ItemRedaxe(2003, toolRed).setUnlocalizedName("Redaxe");

public static Block RedBlock = new BlockRedBlock(1000, Material.iron).setUnlocalizedName("RedBlock");

public static Item RedThing = new ItemRedThing(2004).setUnlocalizedName("RedThing");

public static Item RedPlaceHolder = new RedPlaceHolder(3000).setUnlocalizedName("RedPlaceHolder");

public static CreativeTabs TabRed = new CreativeTabsRed(CreativeTabs.getNextID(), "Red Mod");

public static Item RedHelmet = new RedArmor(2005, armorRed, 0, 0, "red").setUnlocalizedName("Red Helmet");

public static Item RedChestplate = new RedArmor(2006, armorRed, 0 ,1, "red").setUnlocalizedName("Red Chestplate");

public static Item RedLeggings = new RedArmor(2007, armorRed, 0, 2, "red").setUnlocalizedName("Red Leggings");

public static Item RedBoots = new RedArmor(2008, armorRed, 0 ,3, "red").setUnlocalizedName("Red Boots");

public static Block RedOre = new RedOre(2009, Material.rock).setUnlocalizedName("RedOre");

 

 

//World Generation

public WorldGenerator redOreGen = new RedOreWorldGeneration(2);

 

public Base()  {

 

GameRegistry.registerBlock(RedBlock, "Red Block");

GameRegistry.registerBlock(RedOre, "Red Ore");

 

 

LanguageRegistry.addName(Redpick, "Red Pickaxe");

LanguageRegistry.addName(Redsword, "Red Sword");

LanguageRegistry.addName(Redshovel, "Red Shovel");

LanguageRegistry.addName(Redaxe, "Red Axe");

LanguageRegistry.addName(RedBlock, "Red Block");

LanguageRegistry.addName(RedThing, "Red Thing");

LanguageRegistry.addName(RedPlaceHolder, "Red Mod");

LanguageRegistry.addName(RedHelmet, "Red Helmet");

LanguageRegistry.addName(RedChestplate, "Red Chest");

LanguageRegistry.addName(RedLeggings, "Red Legs");

LanguageRegistry.addName(RedBoots, "Red Boots");

LanguageRegistry.addName(RedOre, "Red Ore");

 

GameRegistry.addRecipe(new ItemStack(Redpick, 1), new Object[]{

"XXX", " Y ", " Y ", 'X', Item.redstone, 'Y', Item.stick

});

 

GameRegistry.addRecipe(new ItemStack(Redsword, 1), new Object[]{

" X ", " X ", " Y ", 'X', Item.redstone, 'Y', Item.stick

});

 

GameRegistry.addRecipe(new ItemStack(Redshovel, 1), new Object[]{

" X ", " Y ", " Y ", 'X', Item.redstone, 'Y', Item.stick

});

 

GameRegistry.addRecipe(new ItemStack(Redaxe, 1), new Object[]{

"XX ", "XY ", " Y ", 'X', Item.redstone, 'Y', Item.stick

});

 

GameRegistry.addRecipe(new ItemStack(RedBlock, 10), new Object [] {

"XXX" , "XXX" , "XXX", 'X', RedThing

});

 

GameRegistry.addRecipe(new ItemStack(RedThing, 5), new Object[]{

"XX ", "XX ", "  ", 'X', Item.redstone

});

 

 

GameRegistry.addRecipe(new ItemStack(RedChestplate, 1), new Object [] {

"XXX" , "X X" , 'X', RedThing

});

 

GameRegistry.addRecipe(new ItemStack(RedLeggings, 1), new Object [] {

"XXX" , "X X" , "X X", 'X', RedThing

});

GameRegistry.addRecipe(new ItemStack(RedBoots, 1), new Object [] {

"X X" , "X X", 'X', RedThing

});

GameRegistry.addRecipe(new ItemStack(RedChestplate, 1), new Object [] {

"X X" , "XXX" , "XXX", 'X', RedThing

});

 

 

}

 

 

 

}

 

 

 

Ore class

 

 

package first.mod.block;

 

import java.util.Random;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.client.renderer.texture.IconRegister;

import net.minecraft.item.Item;

import first.mod.Base;

 

public class RedOre extends Block{

 

public RedOre(int par1, Material par2Material) {

super(par1, par2Material);

this.setCreativeTab(Base.TabRed);

this.setHardness(10);

this.setResistance(5);

}

 

public void RegisterIcons(IconRegister iconRegister){

blockIcon = iconRegister.registerIcon("FirstMod:RedOre");

}

 

    public int idDropped(int par1, Random par2Random, int par3)

    {

        return Base.RedThing.itemID;

    }

}

 

 

 

 

Ore generation class

 

 

package first.mod.worldgeneration;

 

import java.util.Random;

 

import first.mod.Base;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.world.World;

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

 

public class RedOreWorldGeneration extends WorldGenerator{

 

private int numberOfBlocks;

 

private int RedOreId;

 

  public RedOreWorldGeneration(int i) {

  this.RedOreId = Base.RedOre.blockID;

  this.numberOfBlocks = i;

}

 

 

 

public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)

    {

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

        {

            return false;

        }

        else

        {

        System.out.println("Spawned");

            int l = par2Random.nextInt(this.numberOfBlocks - 2) + 2;

            byte b0 = 1;

 

            for (int i1 = par3 - l; i1 <= par3 + l; ++i1)

            {

                for (int j1 = par5 - l; j1 <= par5 + l; ++j1)

                {

                    int k1 = i1 - par3;

                    int l1 = j1 - par5;

 

                    if (k1 * k1 + l1 * l1 <= l * l)

                    {

                        for (int i2 = par4 - b0; i2 <= par4 + b0; ++i2)

                        {

                            int j2 = par1World.getBlockId(i1, i2, j1);

 

                            if (j2 == Block.dirt.blockID || j2 == Base.RedOre.blockID)

                            {

                                par1World.setBlock(i1, i2, j1, this.RedBlockId, 0, 2);

                            }

                        }

                    }

                }

            }

 

            return true;

        }

    }

 

}

 

 

 

Link to comment
Share on other sites

To fix the texture bug, instead of RegisterIcons (), add this.setTextureName("FirstMod:RedOre") under this.setResistance

The more advanced way of doing that is adding this method to your block class. It allows more control for all the sides and stuff, just for later purpose.

package first.mod.block;

// imports

public class RedOre extends Block{

   public RedOre(int par1, Material par2Material) {
      super(par1, par2Material);
      this.setCreativeTab(Base.TabRed);
      this.setHardness(10);
      this.setResistance(5);
   }
   
  @SideOnly( Side.CLIENT )
   public void RegisterIcons(IconRegister iconRegister){
      blockIcon = iconRegister.registerIcon("FirstMod:RedOre");
   }
   
   @SideOnly( Side.CLIENT )
   public Icont getIcon(int side, int meta ) {
       return this.blockIcon;
   }
   
    public int idDropped(int par1, Random par2Random, int par3)
    {
        return Base.RedThing.itemID;
    }
}

this.setTextureName does this automatically, but I still wanted to point that out.

 

And for the not generating part.. just check this really nice tutorial for that, I mean you need IWorldGenerator and you need to register it with GameRegistry.registerWorldGenerator( x.class ); in your FMLInitializationEvent.

 

Anyway, just check this tutorial out for that.

I am fairly new to Java and modding, so my answers are not always 100% correct. Sorry for that!

Link to comment
Share on other sites

OK so it is spawning and accepting texture now only 1 more thing. I set up this code so it would generate in the ocean but I didn't found it anywhere. It didn't generate. Why?

System.out.println is only for validating it spawned it prints it but I can't find it.

private void generateSurface(World world, Random rand, int chunkX, int chunkZ) {
        if (world.getBiomeGenForCoords(chunkX, chunkZ) == BiomeGenBase.ocean){
        for(int k = 0; k < 10; k++){
        	int firstBlockXCoord = chunkX + rand.nextInt(16);
        	int firstBlockYCoord = rand.nextInt(32);
        	int firstBlockZCoord = chunkZ + rand.nextInt(16);
        	
        	(new WorldGenMinable(Base.RedOre.blockID, 15)).generate(world, rand, firstBlockXCoord, firstBlockYCoord, firstBlockZCoord);
        	System.out.println("spawned");
        }
	}
	}

Link to comment
Share on other sites

Would this workout?

private void generateSurface(World world, Random rand, int chunkX, int chunkZ) {
		int firstBlockXCoord = chunkX + rand.nextInt(16);
        	int firstBlockYCoord = rand.nextInt(32);
        	int firstBlockZCoord = chunkZ + rand.nextInt(16);
        	
		if (world.getBiomeGenForCoords(firstBlockXCoord, firstBlockZCoord) == BiomeGenBase.ocean){
        for(int k = 0; k < 10; k++){
        	 firstBlockXCoord = chunkX + rand.nextInt(16);
        	 firstBlockYCoord = rand.nextInt(32);
        	 firstBlockZCoord = chunkZ + rand.nextInt(16);
        	
        	(new WorldGenMinable(Base.RedOre.blockID, 15)).generate(world, rand, firstBlockXCoord, firstBlockYCoord, firstBlockZCoord);
        	System.out.println("spawned");
        }
	}
	}

 

The ocean is huge so I don't know how much time would it take to find it.

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.