Hello!
I am w00tious, and i tried to get help on my throwable entities, with no success.
then i figured it out by some small amount of code, and what kind of selfish man i am to not explain it to all of us?
so here it is guys! THIS IS A TUTORIAL FOR MODLOADER.
i assume you already made it up to the renderer, but let's think you didn't.
if you did, skip this part.
So let's start our mod:
package net.minecraft.src;
public class mod_throwMod extends BaseMod
{
public mod_throwMod( )
{
}
@Override
public String getVersion( )
{
return "1.3.2";
}
@Override
public void load( )
{
}
}
right.
now let's add in the item:
public static Item throwItem;
now, we want to assign the item:
throwItem = new ItemThrowing(332).setItemName( "Throw Item" );
we'll get back to that ItemThrowing in a bit.
for now, we want to add the texture.
in the load function write this:
or whatever image you want to use.
next we add the ItemThrowing class:
package net.minecraft.src;
public class ItemThrowing extends Item
{
public ItemThrowing( int par1 )
{
super( par1 );
}
}
and add the throw Item from the snowball code that looks like this:
/**
* 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 EntitySnowball(par2World, par3EntityPlayer));
}
return par1ItemStack;
}
to OUR item:
package net.minecraft.src;
public class ItemThrowing extends Item
{
public ItemThrowing( int par1 )
{
super( par1 );
}
/**
* 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 EntitySnowball(par2World, par3EntityPlayer));
}
return par1ItemStack;
}
}
and then, we change the entity to our entity:
if (!par2World.isRemote)
{
par2World.spawnEntityInWorld(new EntityThrowing(par2World, par3EntityPlayer));
}
now we make our entityThrowing.
about that, i have to say that if you're using Eclipse, in the quick fix of the error of the EntityThrowing, choose "Create class 'EntityThrowing'" and in the dialog, where it says 'superclass' instead of 'net.minecraft.src.Entity' write 'net.minecraft.src.EntityThrowable'
and tick in 'Constructors from superclass' and 'Inherited abstract methods'.
then make the class. it will make JUST what you need:
package net.minecraft.src;
public class EntityThrowing extends EntityThrowable
{
public EntityThrowing( World par1World )
{
super( par1World );
// TODO Auto-generated constructor stub
}
public EntityThrowing( World par1World, EntityLiving par2EntityLiving )
{
super( par1World, par2EntityLiving );
// TODO Auto-generated constructor stub
}
public EntityThrowing( World par1World, double par2, double par4,
double par6 )
{
super( par1World, par2, par4, par6 );
// TODO Auto-generated constructor stub
}
@Override
protected void onImpact( MovingObjectPosition var1 )
{
// TODO Auto-generated method stub
}
}
now remove the comments.
Alright, back to the tutorial, we add in the onImpact function what we want to happen when it hits.
in our case, just simply destroy the ball without doing anything.
weight is the weight.(DUH!)
the default gravity is 0.03F.
lower values are lighter!
higher values are heavier!
0.0F has no gravity at all, thus it will just keep going in a straight line to outer space!
and I haven't tried negatives, but it will probably just rocket up.
now here is where most tutorials end, when it is wrong to end.
there are some more things to do before you will be able to see the entity.
first, add the SpawnEntity function in your mod_ThrowMod class:
what it does is give you an ID, and you return the entity to match that ID.
(Isn't that weird it can't do it by itself?)
in our case, entityThrowing's ID is 497, so we say if it's 497, then give the entityThrowing.
else, we're not responsible for that, and we return null.
next add the getSpawnPacket function:
public Packet23VehicleSpawn getSpawnPacket(Entity var1, int var2)
{
if(var1 instanceof EntityThrowing)
{
return new Packet23VehicleSpawn( var1, 138 );
}
else
{
return null;
}
}
the exact opposite of spawnEntity.
it gives an entity, and if it's an entityThrowing, we return it along with its ID, 138.
else, we're not responsible for that, and we return null.
now all left to do is add the entity to the tracker.
under the registerEntityID in the load function, put this line:
what this is, is a code to add it to the tracker.
now the parameters are:
this:the Mod to add this for.
EntityThrowing.class: the class of the entity to track.
138: the ID of the entity.
64: the view distance; if more than 64 blocks away from this entity, you won't see it.
1: the number of ticks to update it.(It will update every 1 tick)
and true: Track the Motion? (pretty sure, have seen moving entities with this as false)
and that's it!
now if you throw your entity in-game, you'll see a ball shaped like your item being thrown!
if you don't, reply and tell me what has happened.
if you do, please click that green arrow
hope this helped.
THANK YOU SO MUCH!
Due to this, I was able to finish parts of my mod for my little competition with my friend. Again, thank you!
Since you seem to be up to the challenge, and enjoy sharing, here's a tutorial challenge for you...
Something rideable, that flies. Even duplicating the Minecart or Boat, and making it so it flies would be incredible. I would be indebted to you!
THANK YOU SO MUCH!
Due to this, I was able to finish parts of my mod for my little competition with my friend. Again, thank you!
Since you seem to be up to the challenge, and enjoy sharing, here's a tutorial challenge for you...
Something rideable, that flies. Even duplicating the Minecart or Boat, and making it so it flies would be incredible. I would be indebted to you!
Your welcome,
And OK, I'll take that challenge.
I'll tell you if I had found something.
Nice Tutorial but you shouldn't use Entity Ids greater than 255. I see you are using 497 as one. Here is an explanation of why http://www.minecraft...0#entry17786787 Yes it will work but errors may occur later on. Also as a note there are two Ids involved, Entity Id and the Tracker Id(Vehicle Id). I made a helper class to get unique Vehicle and Entity Ids if you guys want to use it. http://pastebin.com/TSLCaD48 Just call the static methods. Other than that great tutorial.
Rollback Post to RevisionRollBack
Same ****, different day - Modification Development Section
Nice Tutorial but you shouldn't use Entity Ids greater than 255. I see you are using 497 as one. Here is an explanation of why http://www.minecraft...0#entry17786787 Yes it will work but errors may occur later on. Also as a note there are two Ids involved, Entity Id and the Tracker Id(Vehicle Id). I made a helper class to get unique Vehicle and Entity Ids if you guys want to use it. http://pastebin.com/TSLCaD48 Just call the static methods. Other than that great tutorial.
Oh i see what you mean.
this is how to fix.
I'll first assume the error:
you did this:
//Two classes: EntityFirst & EntitySecond
public mod_MOD
{
}
public void addRenderer(Map map)
{
map.put(EntityFirst.class);
}
public void addRenderer(Map map)
{
map.put(EntitySecond.class);
}
public Entity spawnEntity(int var1, World var2, double var3, double var5, double var7)
{
if(var1 == EntityFirstID)
{
return new EntityFirst(Details);
}
else
{
return null;
}
}
public Entity spawnEntity(int var1, World var2, double var3, double var5, double var7)
{
if(var1 == EntitySecondID)
{
return new EntitySecond(Details);
}
else
{
return null;
}
}
public Packet23VehicleSpawn getSpawnPacket(Entity var1, int var2)
{
if (var1 instanceof EntityFirst)
{
return new Packet23VehicleSpawn(var1, EntityFirstID);
}
else
{
return null;
}
}
public Packet23VehicleSpawn getSpawnPacket(Entity var1, int var2)
{
if (var1 instanceof EntitySecond)
{
return new Packet23VehicleSpawn(var1, EntitySecondID);
}
else
{
return null;
}
}
is that right?
than this is how to fix!
instead of TWO functions, put both statements into one!
so instead you'll have in addRenderer:
map.put(EntityFirst...);
map.put(EntitySecond...);
in getSpawnPacket:
if (var1 instanceof EntityFirst)
{
return new Packet23VehicleSpawn(var1, EntityFirstID);
}
ELSE IF (var1 instanceof EntitySecond)
{
return new Packet23VehicleSpawn(var1, EntitySecondID);
}
and the same for spawnEntity.
Was i right?
Thank you soooooooooo much Now i just have to find how to make lightning spawn at the impact point, do you know how ? :/
of course, i also did that in my mod
in the onImpact method of the entity add this line:
worldObj.spawnEntityInWorld( new EntityLightningBolt( worldObj, i, j, k ) );
and i, j and k are your X, Y and Z.
here's a helper method, because it is either the XYZ of the block it hit or the XYZ of the ENTITY it hit:
int i = var1.blockX;
int j = var1.blockY;
int k = var1.blockZ;
double x = 0;
double y = 0;
double z = 0;
try
{
x = var1.entityHit.posX;
y = var1.entityHit.posY;
z = var1.entityHit.posZ;
}
catch(Exception e){}
then if it hit a block use i, j and k, or x, y and z for an entity.
did this help?
Wow! Many thanks!
This issue has been stumping me for literally two weeks now. I would've never guessed it was over something so small as this little bit of coding!
For the person above, is your entity named Throwing? If it isn't, change EntityThrowing.class to Entity(your entity name here).class and it should work then, from what I understand.
Also be sure, that if it isn't, to also change ( throwItem.iconIndex ) ); from throwItem to whatever the class file name of the item you are using is. (So it may be something as small as changing around Item and throw, if you used a similar name but put Item first!)
I am w00tious, and i tried to get help on my throwable entities, with no success.
then i figured it out by some small amount of code, and what kind of selfish man i am to not explain it to all of us?
so here it is guys!
THIS IS A TUTORIAL FOR MODLOADER.
i assume you already made it up to the renderer, but let's think you didn't.
if you did, skip this part.
So let's start our mod:
right.
now let's add in the item:
now, we want to assign the item:
we'll get back to that ItemThrowing in a bit.
for now, we want to add the texture.
in the load function write this:
or whatever image you want to use.
next we add the ItemThrowing class:
and add the throw Item from the snowball code that looks like this:
to OUR item:
and then, we change the entity to our entity:
now we make our entityThrowing.
about that, i have to say that if you're using Eclipse, in the quick fix of the error of the EntityThrowing, choose "Create class 'EntityThrowing'" and in the dialog, where it says 'superclass' instead of 'net.minecraft.src.Entity' write 'net.minecraft.src.EntityThrowable'
and tick in 'Constructors from superclass' and 'Inherited abstract methods'.
then make the class. it will make JUST what you need:
now remove the comments.
Alright, back to the tutorial, we add in the onImpact function what we want to happen when it hits.
in our case, just simply destroy the ball without doing anything.
alright. now all we need is to add the addRenderer and registerEntityId function in our mod_throwMod class:
what it does is render the icon of the throwItem, when the entity is thrown.
and the registerEntityID:
the parameters are the class, the name and the unique ID.
BONUS!!
some people need their throwables heavier or lighter. there is an integrated way to do this!
in your entity class, add the following:
weight is the weight.(DUH!)
the default gravity is 0.03F.
lower values are lighter!
higher values are heavier!
0.0F has no gravity at all, thus it will just keep going in a straight line to outer space!
and I haven't tried negatives, but it will probably just rocket up.
now here is where most tutorials end, when it is wrong to end.
there are some more things to do before you will be able to see the entity.
first, add the SpawnEntity function in your mod_ThrowMod class:
what it does is give you an ID, and you return the entity to match that ID.
(Isn't that weird it can't do it by itself?)
in our case, entityThrowing's ID is 497, so we say if it's 497, then give the entityThrowing.
else, we're not responsible for that, and we return null.
next add the getSpawnPacket function:
the exact opposite of spawnEntity.
it gives an entity, and if it's an entityThrowing, we return it along with its ID, 138.
else, we're not responsible for that, and we return null.
now all left to do is add the entity to the tracker.
under the registerEntityID in the load function, put this line:
what this is, is a code to add it to the tracker.
now the parameters are:
this:the Mod to add this for.
EntityThrowing.class: the class of the entity to track.
138: the ID of the entity.
64: the view distance; if more than 64 blocks away from this entity, you won't see it.
1: the number of ticks to update it.(It will update every 1 tick)
and true: Track the Motion? (pretty sure, have seen moving entities with this as false)
and that's it!
now if you throw your entity in-game, you'll see a ball shaped like your item being thrown!
if you don't, reply and tell me what has happened.
if you do, please click that green arrow
hope this helped.
Due to this, I was able to finish parts of my mod for my little competition with my friend. Again, thank you!
Since you seem to be up to the challenge, and enjoy sharing, here's a tutorial challenge for you...
Something rideable, that flies. Even duplicating the Minecart or Boat, and making it so it flies would be incredible. I would be indebted to you!
http://www.youtube.com/user/006ruler
Your welcome,
And OK, I'll take that challenge.
I'll tell you if I had found something.
http://www.minecraftforum.net/topic/1506682-132modloader-and-forge-i-herd-u-liek-mudkipz-mod-shiny-mudkipz-update/
Noted. Thanks!
Oh i see what you mean.
this is how to fix.
I'll first assume the error:
you did this:
is that right?
than this is how to fix!
instead of TWO functions, put both statements into one!
so instead you'll have in addRenderer:
map.put(EntityFirst...);
map.put(EntitySecond...);
in getSpawnPacket:
if (var1 instanceof EntityFirst)
{
return new Packet23VehicleSpawn(var1, EntityFirstID);
}
ELSE IF (var1 instanceof EntitySecond)
{
return new Packet23VehicleSpawn(var1, EntitySecondID);
}
and the same for spawnEntity.
Was i right?
of course, i also did that in my mod
in the onImpact method of the entity add this line:
worldObj.spawnEntityInWorld( new EntityLightningBolt( worldObj, i, j, k ) );
and i, j and k are your X, Y and Z.
here's a helper method, because it is either the XYZ of the block it hit or the XYZ of the ENTITY it hit:
then if it hit a block use i, j and k, or x, y and z for an entity.
did this help?
public void addRenderer(Map var1)
{
var1.put( EntityThrowing.class, new RenderSnowball( throwItem.iconIndex ) );
}
it says throwItem cannot be resolved to a variable
please help
This issue has been stumping me for literally two weeks now. I would've never guessed it was over something so small as this little bit of coding!
For the person above, is your entity named Throwing? If it isn't, change EntityThrowing.class to Entity(your entity name here).class and it should work then, from what I understand.
Also be sure, that if it isn't, to also change ( throwItem.iconIndex ) ); from throwItem to whatever the class file name of the item you are using is. (So it may be something as small as changing around Item and throw, if you used a similar name but put Item first!)
other than that I have hit a brick wall...