1

Grenade-like mod help

froghog 6/4/13 1:28 am
1.4k
7/10/2013 4:06 am
i am just experimenting with modding, i am not really a FULL noob at it but still kind of. i know how to add items and blocks and generate ores and i have even made 2 mobs. what i wanted to do next is figure out how to make my own throwable item, and maybe make it explode. there are probably a lot of tutorials on how to do this but i cant find the right one.
NOTE: i am using MCP and ModLoader. minecraft 1.5.2
Posted by
froghog
Level 63 : High Grandmaster Modder
127

  Have something to say?

JoinSign in

33

Reec3ty
07/10/2013 4:06 am
Level 18 : Journeyman Archer
Locked.
1
Modz4U
07/10/2013 2:55 am
Level 1 : New Miner
Recommend moving to forge it has a bit more advanced system which helps a real lot....


dont ask me bout modloader no idea
1
HyJaffa
06/28/2013 4:56 pm
Level 43 : Master Modder
EntitySnowball code + RenderSnowball code (Obv make the item instance) + EntityTNT code that makes things blow up :3
1
bmanrules
06/28/2013 5:05 pm
Level 57 : Grandmaster Programmer
We already worked it all out in the last few comments and in a pm, He has it working perfectly now
1
froghog
06/04/2013 7:47 pm
Level 63 : High Grandmaster Modder
i have everything good, but if anyone knows how to make the texture/throw work just like a snowball. that would be great. i cant see it until it explodes
1
bmanrules
06/04/2013 3:37 pm
Level 57 : Grandmaster Programmer
Thanks! No problem If you ever need more help, feel free to post here or PM me
1
froghog
06/04/2013 3:21 pm
Level 63 : High Grandmaster Modder
it works!!! im so happy thanks to all of you! i am still kind of new to this webstie, so the only thing i can give back is a subscribe!
1
bmanrules
06/04/2013 3:14 pm
Level 57 : Grandmaster Programmer
To make it explode, add the following code into Entityorantiumsphere under where I left the //you can add particles here:

this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 1.0F, true);

The 1.0F is the strength of the explosion
1
froghog
06/04/2013 3:11 pm
Level 63 : High Grandmaster Modder
ok
1
froghog
06/04/2013 2:55 pm
Level 63 : High Grandmaster Modder
now the texture shows up, but only after a second. it throws, then about 5 blocks away from me it will then show up, invisible before that
1
bmanrules
06/04/2013 2:57 pm
Level 57 : Grandmaster Programmer
I'm pretty sure that's just a problem with the latest version of Modloader, as I get the exact same problem with my Airship mod. We'll just have to wait for 1.6 and hope Rigusami fixes it.. If I find a fix in the meantime I'll let you know
1
bmanrules
06/04/2013 2:51 pm
Level 57 : Grandmaster Programmer
I just realised I'd completely forgotten a chunk of code

Add this into your mod_ after addRenderer:

public Entity spawnEntity(int var1, World var2, double var3, double var5, double var7)
{
switch (var1)
{
case -2000:
return new EntityGrenade(var2);

default:
return null;
}
}

public Packet23VehicleSpawn getSpawnPacket(Entity var1, int var2)
{
return var1 instanceof EntityGrenade ? new Packet23VehicleSpawn(var1, var2) : null;
}


Don't forget to replace Grenade with orantiumsphere!
1
froghog
06/04/2013 2:48 pm
Level 63 : High Grandmaster Modder
when i throw it there is no texture though
1
HyJaffa
06/04/2013 2:46 pm
Level 43 : Master Modder
EntitySnowball+EntityTNTPrimed = Grenade.
1
nickfromgreece
06/04/2013 2:42 pm
Level 54 : Grandmaster Programmer
Recommend moving to forge it has a bit more advanced system which helps a real lot....


dont ask me bout modloader no idea
1
bmanrules
06/04/2013 2:44 pm
Level 57 : Grandmaster Programmer
Forge is a lot more difficult when starting off. It's better to start with Modloader and move up to Forge.
1
froghog
06/04/2013 2:40 pm
Level 63 : High Grandmaster Modder
yes
1
bmanrules
06/04/2013 2:39 pm
Level 57 : Grandmaster Programmer
And did you move the addRenderer?
1
froghog
06/04/2013 2:36 pm
Level 63 : High Grandmaster Modder
what i hold in my hand does indeed have a texture, yes
1
bmanrules
06/04/2013 2:34 pm
Level 57 : Grandmaster Programmer
Wait, does your actual item that you hold in your hand have a texture or is it invisible?
1
froghog
06/04/2013 2:33 pm
Level 63 : High Grandmaster Modder
lol i tested it now and when i throw it it makes the ncp's mad, but i dont see the item in the air so ill post all the code.

this is the entity code
Click to reveal
package net.minecraft.src;

public class Entityorantiumsphere extends EntityThrowable
{
public Entityorantiumsphere(World par1World)
{
super(par1World);
}

public Entityorantiumsphere(World par1World, EntityLiving par2EntityLiving)
{
super(par1World, par2EntityLiving);
}

public Entityorantiumsphere(World par1World, double par2, double par4, double par6)
{
super(par1World, par2, par4, par6);
}

/**
* Called when this EntityThrowable hits a block or entity.
*/
protected void onImpact(MovingObjectPosition par1MovingObjectPosition)
{
if (par1MovingObjectPosition.entityHit != null)
{
byte var2 = 0;

if (par1MovingObjectPosition.entityHit instanceof EntityBlaze)
{
var2 = 3;
}

par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), var2);
}

for (int var3 = 0; var3 < 8; ++var3)
{
//You can set particles here, such as "flame" or "smoke"
this.worldObj.spawnParticle("snowballpoof", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
}

if (!this.worldObj.isRemote)
{
this.setDead();
}
}
}


this is the item file

Click to reveal
package net.minecraft.src;

public class Itemorantiumsphere extends Item
{
public Itemorantiumsphere(int par1)
{
super(par1);
this.maxStackSize = 16;

}

/**
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
*/
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
if (!par3EntityPlayer.capabilities.isCreativeMode)
{
--par1ItemStack.stackSize;
}

par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

if (!par2World.isRemote)
{
par2World.spawnEntityInWorld(new Entityorantiumsphere(par2World, par3EntityPlayer));
}

return par1ItemStack;
}
}


and then there is the snowball render
1
bmanrules
06/04/2013 2:28 pm
Level 57 : Grandmaster Programmer
froghogsure
Click to reveal
package net.minecraft.src;

import java.util.Map;
import java.util.Random;

public class mod_Orantium extends BaseMod {



public static final Item oriantum_ore = new Item(176).setCreativeTab(CreativeTabs.tabMaterials).setUnlocalizedName("orantium_ore");
public static final Item orantiumsphere = new Itemorantiumsphere(178).setCreativeTab(CreativeTabs.tabCombat).setUnlocalizedName("orantiumSphere");
public static final Block oreorantium = new Block(177, Material.rock).setHardness(3.0F).setResistance(5.0F).setCreativeTab(CreativeTabs.tabBlock).setUnlocalizedName("oreorantium_1");

public void addRenderer(Map var1)
{
var1.put(Entityorantiumsphere.class, new RenderSnowball(mod_Orantium.orantiumsphere));
}





public void load(){

ModLoader.registerBlock(oreorantium);
ModLoader.addName(oreorantium, "Orantium Ore");

ModLoader.registerEntityID(Entityorantiumsphere.class, "Orantium Sphere", -2000);
ModLoader.addEntityTracker(this, Entityorantiumsphere.class, -2000, 20, 5, true);

ModLoader.addName(oriantum_ore, "Orantium");
ModLoader.addSmelting(oreorantium.blockID, new ItemStack(oriantum_ore), 0.1F);

ModLoader.addName(orantiumsphere, "Orantium Sphere");
ModLoader.addRecipe(new ItemStack(orantiumsphere, 1), new Object[] {"###", "#@#","###", '#', Block.glass, '@', oriantum_ore});
}



public void generateSurface(World world,Random random, int x, int z){

for(int rarity = 0; rarity < 15; rarity++){

int xCoord = x + random.nextInt(16);
int yCoord = random.nextInt(70);
int zCoord = z + random.nextInt(16);
new WorldGenMinable(oreorantium.blockID, 15).generate(world, random, xCoord, yCoord, zCoord);

}
}




public String getVersion(){
return null;
}

}


Try placing addRenderer after Load(), like I said earlier. If this doesn't work paste all the files and I'll look at them
1
froghog
06/04/2013 2:23 pm
Level 63 : High Grandmaster Modder
sure
Click to reveal
package net.minecraft.src;

import java.util.Map;
import java.util.Random;

public class mod_Orantium extends BaseMod {



public static final Item oriantum_ore = new Item(176).setCreativeTab(CreativeTabs.tabMaterials).setUnlocalizedName("orantium_ore");
public static final Item orantiumsphere = new Itemorantiumsphere(178).setCreativeTab(CreativeTabs.tabCombat).setUnlocalizedName("orantiumSphere");
public static final Block oreorantium = new Block(177, Material.rock).setHardness(3.0F).setResistance(5.0F).setCreativeTab(CreativeTabs.tabBlock).setUnlocalizedName("oreorantium_1");

public void addRenderer(Map var1)
{
var1.put(Entityorantiumsphere.class, new RenderSnowball(mod_Orantium.orantiumsphere));
}





public void load(){

ModLoader.registerBlock(oreorantium);
ModLoader.addName(oreorantium, "Orantium Ore");

ModLoader.registerEntityID(Entityorantiumsphere.class, "Orantium Sphere", -2000);
ModLoader.addEntityTracker(this, Entityorantiumsphere.class, -2000, 20, 5, true);

ModLoader.addName(oriantum_ore, "Orantium");
ModLoader.addSmelting(oreorantium.blockID, new ItemStack(oriantum_ore), 0.1F);

ModLoader.addName(orantiumsphere, "Orantium Sphere");
ModLoader.addRecipe(new ItemStack(orantiumsphere, 1), new Object[] {"###", "#@#","###", '#', Block.glass, '@', oriantum_ore});
}



public void generateSurface(World world,Random random, int x, int z){

for(int rarity = 0; rarity < 15; rarity++){

int xCoord = x + random.nextInt(16);
int yCoord = random.nextInt(70);
int zCoord = z + random.nextInt(16);
new WorldGenMinable(oreorantium.blockID, 15).generate(world, random, xCoord, yCoord, zCoord);

}
}




public String getVersion(){
return null;
}

}
1
bmanrules
06/04/2013 2:18 pm
Level 57 : Grandmaster Programmer
Can you show me your mod_?
1
froghog
06/04/2013 2:17 pm
Level 63 : High Grandmaster Modder
so i have everything, but in the game when i right click, nothing happens
1
bmanrules
06/04/2013 2:10 pm
Level 57 : Grandmaster Programmer
You don't really, you can use RenderSnowball to make it look like an item, which is what snowballs/enderpearls do
After the load() function add:


public void addRenderer(Map var1)
{
var1.put(EntityGrenade.class, new RenderSnowball(mod_YourModHere.Grenade));
}

1
froghog
06/04/2013 2:06 pm
Level 63 : High Grandmaster Modder
ok but i didnt know that i needed a model file
1
bmanrules
06/04/2013 2:03 pm
Level 57 : Grandmaster Programmer
Sorry I'm pretty bad at explaining stuff

You probably have something along the lines of
public static final Item Grenade = (new Item(200)).setUnlocalizedName("Grenade");

or something similar to that right? Instead, change it to:

public static final Item Grenade = (new ItemGrenade(200)).setUnlocalizedName("Grenade");


For the Entity, use:

ModLoader.registerEntityID(EntityGrenade.class, "Grenade", -2000);
ModLoader.addEntityTracker(this, EntityGrenade.class, -2000, 20, 5, true);


The -2000 is the Entity ID, for my mod I happened to choose -2000 to play it safe though. Mods with the same numbers will have compatibility errors, so be warned

and then after the load() function add:

public void addRenderer(Map var1)
{
var1.put(EntityGrenade.class, new RenderSnowball(mod_YourModHere.Grenade));
}
1
froghog
06/04/2013 1:59 pm
Level 63 : High Grandmaster Modder
i am still kindof confused at what i put in the mod_file..... i have the item created, but how do i connect it to the Item file?
1
froghog
06/04/2013 1:41 pm
Level 63 : High Grandmaster Modder
i actually would like you to post the code. i dont know what i need to put in the mod_ file
1
bmanrules
06/04/2013 1:48 pm
Level 57 : Grandmaster Programmer
I probably should have posted it, but I was in a bit of a rush at the time You said you've made mobs and items before, so simply add a new item and entity to your mod_ file, and as the render file for your entity use renderitem to make it render as an item, or make a model for a grenade in a program such as Techne.

EntityGrenade:
package net.minecraft.src;

public class EntityGrenade extends EntityThrowable
{
public EntityGrenade(World par1World)
{
super(par1World);
}

public EntityGrenade(World par1World, EntityLiving par2EntityLiving)
{
super(par1World, par2EntityLiving);
}

public EntityGrenade(World par1World, double par2, double par4, double par6)
{
super(par1World, par2, par4, par6);
}

/**
* Called when this EntityThrowable hits a block or entity.
*/
protected void onImpact(MovingObjectPosition par1MovingObjectPosition)
{
if (par1MovingObjectPosition.entityHit != null)
{
byte var2 = 0;

if (par1MovingObjectPosition.entityHit instanceof EntityBlaze)
{
var2 = 3;
}

par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), var2);
}

for (int var3 = 0; var3 < 8; ++var3)
{
//You can set particles here, such as "flame" or "smoke", or add explosion code
this.worldObj.spawnParticle("snowballpoof", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
}

if (!this.worldObj.isRemote)
{
this.setDead();
}
}
}


ItemGrenade:
package net.minecraft.src;

public class ItemGrenade extends Item
{
public ItemGrenade(int par1)
{
super(par1);
this.maxStackSize = 16;
this.setCreativeTab(CreativeTabs.tabMisc);
}

/**
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
*/
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
if (!par3EntityPlayer.capabilities.isCreativeMode)
{
--par1ItemStack.stackSize;
}

par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

if (!par2World.isRemote)
{
par2World.spawnEntityInWorld(new EntityGrenade(par2World, par3EntityPlayer));
}

return par1ItemStack;
}
}
1
bmanrules
06/04/2013 1:38 pm
Level 57 : Grandmaster Programmer
You should look at the code for snowballs. Create a new item that extends ItemSnowball and a new Entity that extends EntitySnowball or EntityThrowable To save time you could copy the code directly from Item/EntitySnowball and replace all references to Snowball with the name of your class files. If you're still not sure what to do, I can paste the code here, but it shouldn't be too difficult
1
froghog
06/04/2013 1:19 pm
Level 63 : High Grandmaster Modder
bump
1

Welcome