1

Throwable Item

ThatRandomGuy296 6/26/13 6:18 pm
1.2k
6/28/2013 5:11 pm
Hello, my I made an item to be throw able following a tutorial from 1.3.2, it doesn't work but can anyone look at it and tell me what needs to be updated? I've tried a lot and I can't find anything to make this item be thrown.

Mod file
Click to reveal

package net.minecraft.src;
import java.util.Map;

public class mod_duckPresents extends BaseMod
{ public static final Item GoldenEggs = new Item(3000).setCreativeTab(CreativeTabs.tabMaterials).setUnlocalizedName("goldenegg");

public void load() {
ModLoader.addName(GoldenEggs, "Gold Egg");
ModLoader.registerEntityID( EntityGoldenEggs.class, "Goldeneggs", 100);
ModLoader.addEntityTracker( this, EntityGoldenEggs.class, 138, 64, 1, true );

}


public void addRenderer(Map var1)
{
var1.put(EntityGoldenEggs.class, new RenderSnowball(GoldenEggs));
}

public Entity spawnEntity(int var1, World var2, double var3, double var5, double var7)
{
if(var1 == 100)
{
return new EntityGoldenEggs( var2, var3, var5, var7 );
}
else
{
return null;
}
}

public Packet23VehicleSpawn getSpawnPacket(Entity var1, int var2)
{
if(var1 instanceof EntityGoldenEggs)
{
return new Packet23VehicleSpawn( var1, 100 );
}
else
{
return null;
}
}

public String getVersion() {
return "v.1.0.0";
}


}


Item File
Click to reveal

package net.minecraft.src;
import java.util.Random;
public class ItemGoldenEggs extends Item
{
public void registerIcons(IconRegister par1IconRegister)
{
this.itemIcon = par1IconRegister.registerIcon("goldenegg");
}

public ItemGoldenEggs(int par1)
{
super(par1);
this.maxStackSize = 16;


}




public void RegisterIcons(IconRegister par1IconRegister)
{
this.itemIcon = par1IconRegister.registerIcon("goldenegg");
}


/**
* 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 EntityGoldenEggs(par2World, par3EntityPlayer));
}
return par1ItemStack;
}
}


Entity File
Click to reveal

package net.minecraft.src;
public class EntityGoldenEggs extends EntityThrowable
{
public EntityGoldenEggs( World par1World )
{
super( par1World );
}
public EntityGoldenEggs( World par1World, EntityLiving par2EntityLiving )
{
super( par1World, par2EntityLiving );
}
public EntityGoldenEggs( World par1World, double par2, double par4,
double par6 )
{
super( par1World, par2, par4, par6 );
}
@Override
protected void onImpact( MovingObjectPosition var1 )
{
setDead( );
}
}


Thanks in advance!
Posted by
ThatRandomGuy296
Level 13 : Journeyman System
2

  Have something to say?

JoinSign in

13

HyJaffa
06/28/2013 4:55 pm
Level 43 : Master Modder
Just a heads up, Make your variables start with lower cases
1
bmanrules
06/28/2013 5:11 pm
Level 57 : Grandmaster Programmer
Using upper-cases won't affect your code in anyway, It's just general house-keeping to have variables start with lower cases
1
ThatRandomGuy296
06/28/2013 4:45 pm
Level 13 : Journeyman System
It splits into two and goes back to one when it goes really far but it works I doubt many people will throw to far. Thank You very much!
1
bmanrules
06/28/2013 12:17 pm
Level 57 : Grandmaster Programmer
Oh yeah, Froghog found a fix for this while we were working on it. The problem is that the item being thrown spawns on the server side and takes a moment to update to the client.

Find this line:
if (!par2World.isRemote)

and change it to:

if (!par2World.isRemote || par2World.isRemote)

This will spawn 2 thrown items, one on the client and one on the server, but you won't notice it and it will make the item appear faster.
1
ThatRandomGuy296
06/28/2013 12:15 pm
Level 13 : Journeyman System
Nvm it works!!!! I just can't see the item till it's farther away from me ty so much
1
ThatRandomGuy296
06/28/2013 11:51 am
Level 13 : Journeyman System
changed it but it still doesn't throw for some reason
1
bmanrules
06/27/2013 7:55 pm
Level 57 : Grandmaster Programmer
No problem I had a look at the code, and

case 3000:

Should be the Entity ID, not the item ID, so in your case, you chose -2000 as the Entity id,(Like me ) so you should instead use case -2000:

Also, for anyone else who uses that thread as a tutorial, the -2000 is the ID for the Entity that you are creating. I recommend choosing your own number as picking the same number as another mod will cause compatibilities.
1
ThatRandomGuy296
06/27/2013 7:12 pm
Level 13 : Journeyman System
Checked out the thread, my code looks almost exactly the same but it still doesn't work. Mind taking a fast look?

Mod File
Click to reveal

package net.minecraft.src;
import java.util.Map;

public class mod_duckPresents extends BaseMod
{ public static final Item GoldenEggs = new ItemGoldenEggs(3000).setCreativeTab(CreativeTabs.tabMaterials).setUnlocalizedName("goldenegg");

public void load() {
ModLoader.addName(GoldenEggs, "Gold Egg");
ModLoader.registerEntityID(EntityGoldenEggs.class, "Grenade", -2000);
ModLoader.addEntityTracker(this, EntityGoldenEggs.class, -2000, 20, 5, true);
}



public Entity spawnEntity(int var1, World var2, double var3, double var5, double var7) { switch (var1) { case 3000: return new EntityGoldenEggs(var2); default: return null; } } public Packet23VehicleSpawn getSpawnPacket(Entity var1, int var2) { return var1 instanceof EntityGoldenEggs ? new Packet23VehicleSpawn(var1, var2) : null; } public void addRenderer(Map var1) { var1.put(EntityGoldenEggs.class, new RenderSnowball(GoldenEggs)); }

public String getVersion() {
return null;
}


}


Item File
Click to reveal

package net.minecraft.src;
import java.util.Random;
public class ItemGoldenEggs extends Item
{
public void registerIcons(IconRegister par1IconRegister)
{
this.itemIcon = par1IconRegister.registerIcon("goldenegg");
}

public ItemGoldenEggs(int par1)
{
super(par1);
this.maxStackSize = 16;


}




public void RegisterIcons(IconRegister par1IconRegister)
{
this.itemIcon = par1IconRegister.registerIcon("goldenegg");
}


/**
* 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 EntityGoldenEggs(par2World, par3EntityPlayer));
}

return par1ItemStack;
}
}


Entity File
Click to reveal

package net.minecraft.src;

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

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

public EntityGoldenEggs(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();
}
}
}
1
ThatRandomGuy296
06/26/2013 10:23 pm
Level 13 : Journeyman System
Thank you for that link! I'll look at that in full detail tomorrow
1
ThatRandomGuy296
06/26/2013 7:55 pm
Level 13 : Journeyman System
I have experimented with the snowball code, but I got nowhere. I usually come to the forums last.
1
bmanrules
06/26/2013 8:35 pm
Level 57 : Grandmaster Programmer
Ok, no problem. I recommend checking out this thread http://www.planetminecraft.com/forums/post2100191.html?hilit=throwable#p2100191 Where I solved this problem before.
1
fyromaster
06/26/2013 6:22 pm
Level 23 : Expert Geek
You're probably wasting your time here. I don't care much for coding and I don't know much beyond basic batch. I would recommend going to Minecraft Forums or the Forge Forums, where there will be people who are more knowledgeable in this topic. I don't think there are too many coders here.
1
bmanrules
06/26/2013 6:40 pm
Level 57 : Grandmaster Programmer
If you don't care much for coding, and therefore cannot and refuse to help, don't bother posting at all. There are plenty of other users on this forum who are actually capable of answering this question....(Just look at the mods section :/)

Anyway, I recommend looking at EntitySnowball and ItemSnowball and using the code there to work on your throwable item. I can post code if you need me to, but it would be better if you tried to figure it out first with our help before we spoonfeed you code. Also, never follow outdated tutorials...
1

Welcome