Jump to content

i need a genius!!


illusi0n555

Recommended Posts

I'm going to try to make this as detailed as i can, I'm a giant noob when it comes to java but i learn fast. my main language is HTML so u can see I'm probably out of my league trying to make such a mod so soon but i really want this mod and i doubt anyone will make it soon.

 

So basically what I'm doing is i have this block ( GemOreBlock )

and i have these items created already ( FireGem,WaterGem,WindGem,EarthGem )

what i want to do is.. when the elemental ore is broke by pick

i want one of the 6 things to drop RANDOMLY

( 1-4 being the gems, 5 being coal 6 being NOTHING )

 

 

MyCode

 

 

package illusi0n.CreativeBlocks;

 

import java.util.Random;

 

import cpw.mods.fml.common.Mod.Init;

import cpw.mods.fml.common.event.FMLInitializationEvent;

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

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

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

import net.minecraft.creativetab.CreativeTabs;

 

public class GemOreBlock extends Block {

 

 

 

public GemOreBlock(int par1, String texture) {

super(par1, Material.rock);

setCreativeTab(CreativeTabs.tabBlock); //place in creative tabs

 

}

 

//drops when broken with pickaxe

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

{

return illusi0nsCreativeBlocks.Firegem.itemID;

}

public int quantityDropped(Random random)

{

return 1;

}

 

 

 

//texure the block (Not sure if it's required)

public String getTextureFile(){

return "/textures/blocks/gemore.png";

}

}

 

 

 

As you can see it only drops the Firegem.

Befor posting on the forums ive searched and searched, i found a mod that does exactly what i want to do, the problem is when i DE-compiled his mod he used modloader instead of forge

 

His Code

 

 

import java.util.Random;

 

public class BlockRandomiteOrePink extends pb

{

  protected BlockRandomiteOrePink(int i, int j)

  {

    super(i, j, acn.e);

  }

 

  public int a(int i, Random random, int j)

  {

    int k = random.nextInt(10);

 

    if (k == 0)

    {

      return yr.m.bQ;

    }

 

    if (k == 1)

    {

      return yr.m.bQ;

    }

 

    if (k == 2)

    {

      return yr.m.bQ;

    }

 

    if (k == 3)

    {

      return yr.m.bQ;

    }

 

    if (k == 4)

    {

      return pb.H.bO;

    }

 

    if (k == 5)

    {

      return pb.H.bO;

    }

 

    if (k == 6)

    {

      return pb.H.bO;

    }

 

    if (k == 7)

    {

      return pb.G.bO;

    }

 

    if (k == 8)

    {

      return pb.G.bO;

    }

 

    if (k == 9)

    {

      return yr.n.bQ;

    }

 

    return 0;

  }

 

  public int a(Random random)

  {

    return 1;

  }

}

 

 

 

How can i go about doing this in forge?

Link to comment
Share on other sites

 

Try this:

 

 

public int idDropped(int par1, Random random, int par3)
    {
  int k = random.nextInt(6);

    if (k == 0)
    {
      return Block.gem.blockID; //the id of the 1st gem
    }

    if (k == 1)
    {
      return yr.m.bQ; //the id of the 2nd etc.
    }

    if (k == 2)
    {
      return yr.m.bQ;
    }

    if (k == 3)
    {
      return yr.m.bQ;
    }

    if (k == 4)
    {
      return pb.H.bO;
    }

    if (k == 5)
    {
      return 0; // nothing
    }
    return 0;

    }

Link to comment
Share on other sites

The de-compiled mod clearly should not work because I don't know of any instances in which k will ever equal  8)...

;D

 

Often times it is very easy to use code already made in Minecraft and back-track using that.

For instance, I've never messed with drops in my mod, but I know that lapis lazuli drops a random number of ores. So I went to the Block class, found where lapis lazuli was instantiated, and followed that to the BlockOre class and looked at the quantityDropped method to see how that was done.

 

You are completely right to use the idDropped method. Here you want to use the random passed to you to generate a random integer ranging 0-5. A small framework for you...

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

{

    int drop = par2Random.nextInt(6);

    if (drop == 0)

        return illusi0nsCreativeBlocks.Firegem.itemID;

    if (drop == 1)

        return illusi0nsCreativeBlocks.Watergem.itemID;

    if (drop == 2)

        return illusi0nsCreativeBlocks.Windgem.itemID;

    if (drop == 3)

        return illusi0nsCreativeBlocks.Earthgem.itemID;

    if (drop == 4)

        return Item.coal.itemID;

    return ...

}

Unfortunately, I haven't played with this at all and I'm not sure what you want to do to make it drop nothing. Maybe make it always drop one of those 5 items and override the quantityDropped method and use the random variable passed in to make it have a 1 in 6 chance of dropping 0, and drop 1 the other 5 times, similar to what we did in idDropped. If you want help with that let me know but I bet you can figure it out.

Read my thoughts on my summer mod work and tell me what you think!

http://www.minecraftforge.net/forum/index.php/topic,8396.0.html

 

I absolutely love her when she smiles

Link to comment
Share on other sites

Dawars I tried that way befor posting lol tons of errors.... Ty for the idea though

 

Redria7 your post put a smile on my face... I will try that tomorrow because its getting late but I have good faith in what you just showed me hopefully tomorrow will bring success :)

 

Thank you both

Link to comment
Share on other sites

Unfortunately, I haven't played with this at all and I'm not sure what you want to do to make it drop nothing. Maybe make it always drop one of those 5 items and override the quantityDropped method and use the random variable passed in to make it have a 1 in 6 chance of dropping 0, and drop 1 the other 5 times, similar to what we did in idDropped. If you want help with that let me know but I bet you can figure it out.

 

Actually you need to return -1 in the idDropped method if you don't want to drop anything.

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

Unfortunately, I haven't played with this at all and I'm not sure what you want to do to make it drop nothing. Maybe make it always drop one of those 5 items and override the quantityDropped method and use the random variable passed in to make it have a 1 in 6 chance of dropping 0, and drop 1 the other 5 times, similar to what we did in idDropped. If you want help with that let me know but I bet you can figure it out.

 

Actually you need to return -1 in the idDropped method if you don't want to drop anything.

BUT my method would work (right?). It is harder, slower, and less logical, but you should get the same result. Unless the random variables are identically seeded in which case it would fail catastrophically.

Just return -1.  :)

Read my thoughts on my summer mod work and tell me what you think!

http://www.minecraftforge.net/forum/index.php/topic,8396.0.html

 

I absolutely love her when she smiles

Link to comment
Share on other sites

Unfortunately, I haven't played with this at all and I'm not sure what you want to do to make it drop nothing. Maybe make it always drop one of those 5 items and override the quantityDropped method and use the random variable passed in to make it have a 1 in 6 chance of dropping 0, and drop 1 the other 5 times, similar to what we did in idDropped. If you want help with that let me know but I bet you can figure it out.

 

Actually you need to return -1 in the idDropped method if you don't want to drop anything.

BUT my method would work (right?). It is harder, slower, and less logical, but you should get the same result. Unless the random variables are identically seeded in which case it would fail catastrophically.

Just return -1.  :)

 

Yes, this works perfectly fine.

You could make it a switch-case block instead of several if statements, though, but it's not necessary.

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

wanted to thank everyone for there support... if it werent for people like you guys people like me would not be able to put our creativity out there :) redria ur method worked exactly how i wanted it too... for that sir you win the genius award!!!! :D and san andreas thanks for the helpfull -1 trick

Link to comment
Share on other sites

You can do it like this:

Lines marked with #: those you should add

your file:

package illusi0n.CreativeBlocks;

import java.util.Random;

import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;

public class GemOreBlock extends Block {


Random r = new Random();  //# Declares a random number generator 

public GemOreBlock(int par1, String texture) {
super(par1, Material.rock);
setCreativeTab(CreativeTabs.tabBlock); //place in creative tabs

}

//drops when broken with pickaxe
public int idDropped(int par1, Random par2Random, int par3)
{
      public int rNum = r.nextInt(5)       //# sets rNum variable to random nuber of 0-5 generated by random generator declared  above
   
  if (rNum == 0)                           //# Those are cases of number: 0-3 - gems (replace [item_1/2/3/4] with 
     return [item_1];                     //    YourModBaseFile.YourItem 4 - coal 5 - null (total nothing) 
  if (rNum == 1)                             
    return [item_2];
  if (rNum == 2)
    return [item_3];
  if (rNum == 3)
    return [item_4];
  if (rNum == 4)
    return Item.coal;
  if (rNum == 5)
    return null;
  
}
public int quantityDropped(Random random)
{
return 1;
}

 

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.