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
NOTE: i am using MCP and ModLoader. minecraft 1.5.2
33
Locked.
Recommend moving to forge it has a bit more advanced system which helps a real lot....
dont ask me bout modloader no idea
dont ask me bout modloader no idea
EntitySnowball code + RenderSnowball code (Obv make the item instance) + EntityTNT code that makes things blow up :3
We already worked it all out in the last few comments and in a pm, He has it working perfectly now
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
Thanks! No problem If you ever need more help, feel free to post here or PM me
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!
To make it explode, add the following code into Entityorantiumsphere under where I left the //you can add particles here:
The 1.0F is the strength of the explosion
this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 1.0F, true);The 1.0F is the strength of the explosion
ok
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
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
I just realised I'd completely forgotten a chunk of code
Add this into your mod_ after addRenderer:
Don't forget to replace Grenade with orantiumsphere!
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!
when i throw it there is no texture though
EntitySnowball+EntityTNTPrimed = Grenade.
Recommend moving to forge it has a bit more advanced system which helps a real lot....
dont ask me bout modloader no idea
dont ask me bout modloader no idea
Forge is a lot more difficult when starting off. It's better to start with Modloader and move up to Forge.
yes
And did you move the addRenderer?
what i hold in my hand does indeed have a texture, yes
Wait, does your actual item that you hold in your hand have a texture or is it invisible?
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
this is the item file
and then there is the snowball render
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();
}
}
}
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;
}
}
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
froghogsureClick to revealpackage 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
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;
}
}
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;
}
}
Can you show me your mod_?
so i have everything, but in the game when i right click, nothing happens
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:
After the load() function add:
public void addRenderer(Map var1)
{
var1.put(EntityGrenade.class, new RenderSnowball(mod_YourModHere.Grenade));
}
ok but i didnt know that i needed a model file
Sorry I'm pretty bad at explaining stuff
You probably have something along the lines of
or something similar to that right? Instead, change it to:
For the Entity, use:
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:
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));
}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?
i actually would like you to post the code. i dont know what i need to put in the mod_ file
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:
ItemGrenade:
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;
}
}
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
bump
