Jump to content

  • Curse Sites
Become a Premium Member! Help
Latest News Article

1.2 [modloader] Custom thrown items(intermedate)

spear arrow

  • Please log in to reply
17 replies to this topic

#1

Iamshortman
  • Location: socal
  • Minecraft: iamshortman

Posted 08 April 2012 - 02:25 AM

So i decided to make a tutorial explaining the basics to thrown items. This isn't going to revolutionize anything but just give a good idea on how to make them.
Warning: this will not give you code to copy and paste. You will have to read and ALREADY understand how to program and how to use modloader.


Current
Spear

To be added
Custom bow and arrow
grenade
any other requests


Spear
Spoiler:

No drop in spear/arrow
Spoiler:
Any problems you may have i would be glad to help with, I dont know everthing but i can atleast give it a try.
"Well...... Thats a design flaw" - Me

Register or log in to remove.

#2

YoWazzup
    YoWazzup

    Nether Resident

  • Members
  • 2020 posts
  • Location: Heerhugowaard, The NETHERlands
  • Minecraft: DUDEiFAIL
  • Xbox:XxSeeYourMomxX

Posted 08 April 2012 - 11:44 AM

Nice!
Posted Image
Made By: YoWazzup, me.

#3

hiloser12221
  • Location: Behind you...
  • Minecraft: hiloser12221

Posted 10 April 2012 - 01:22 AM

Doesn't work, the first snippet of code in the onStoppedUsing method gives a static reference to a non-static modifier error.
Check out my Skyrim Let's Play here

tyber13 said:

So Bin Larden is finally dead. It's amazing what the Americans can do when the playstation network is down.

#4

Iamshortman
  • Location: socal
  • Minecraft: iamshortman

Posted 14 April 2012 - 07:36 PM

View Posthiloser12221, on 10 April 2012 - 01:22 AM, said:

Doesn't work, the first snippet of code in the onStoppedUsing method gives a static reference to a non-static modifier error.
Not sure what is wrong, have you had any luck fixing it?
"Well...... Thats a design flaw" - Me

#5

neb1600
    neb1600

    Coal Miner

  • Members
  • 116 posts
  • Location: Australia

Posted 16 April 2012 - 07:28 AM

im not making a spear but do you know how to make it spin in the air
Posted Image

#6

Iamshortman
  • Location: socal
  • Minecraft: iamshortman

Posted 16 April 2012 - 09:30 PM

View Postneb1600, on 16 April 2012 - 07:28 AM, said:

im not making a spear but do you know how to make it spin in the air
No but look at the code that deals with pitch in the Entity arrow(i believe its in the on update function) . ill give it a try some time but if you figure it out i would love to add it to the tutorial.
"Well...... Thats a design flaw" - Me

#7

neb1600
    neb1600

    Coal Miner

  • Members
  • 116 posts
  • Location: Australia

Posted 17 April 2012 - 12:57 PM

thank you the tutorial was very helpfull and i will try looking into that
Posted Image

#8

Iamshortman
  • Location: socal
  • Minecraft: iamshortman

Posted 17 April 2012 - 09:31 PM

View Postneb1600, on 17 April 2012 - 12:57 PM, said:

thank you the tutorial was very helpfull and i will try looking into that
Your welcome, im glad it helped
"Well...... Thats a design flaw" - Me

#9

Speed8Fire
  • Minecraft: Speed8Fire

Posted 18 April 2012 - 04:08 PM

Looks great :D
I don't have much time now, so i don't know if you already said how to, but is it said how to make object fly ... straight ? I mean, without falling down by gravity ^^'
Anyway, i'll try this out as soon as i can :DD

#10

hiloser12221
  • Location: Behind you...
  • Minecraft: hiloser12221

Posted 18 April 2012 - 09:26 PM

No, I couldn't get the code to work...
Check out my Skyrim Let's Play here

tyber13 said:

So Bin Larden is finally dead. It's amazing what the Americans can do when the playstation network is down.

#11

Iamshortman
  • Location: socal
  • Minecraft: iamshortman

Posted 18 April 2012 - 10:30 PM

View Posthiloser12221, on 18 April 2012 - 09:26 PM, said:

No, I couldn't get the code to work...
could i see you code. ill see if i can find whats wrong.
"Well...... Thats a design flaw" - Me

#12

hiloser12221
  • Location: Behind you...
  • Minecraft: hiloser12221

Posted 18 April 2012 - 11:45 PM

View PostIamshortman, on 18 April 2012 - 10:30 PM, said:

could i see you code. ill see if i can find whats wrong.
Yeah sure, here it is (at least the code with the error);
EntitySpear entityspear = new EntitySpear(world, entityplayer, 2.0F);
  world.spawnEntityInWorld(entityspear);

Check out my Skyrim Let's Play here

tyber13 said:

So Bin Larden is finally dead. It's amazing what the Americans can do when the playstation network is down.

#13

Iamshortman
  • Location: socal
  • Minecraft: iamshortman

Posted 19 April 2012 - 03:07 AM

View Posthiloser12221, on 18 April 2012 - 11:45 PM, said:

Yeah sure, here it is (at least the code with the error);
EntitySpear entityspear = new EntitySpear(world, entityplayer, 2.0F);
  world.spawnEntityInWorld(entityspear);
I think that the problem is not in that section of code but in the surrounding area. just send me your whole itemspear. i would be happy to find the problem.
"Well...... Thats a design flaw" - Me

#14

hiloser12221
  • Location: Behind you...
  • Minecraft: hiloser12221

Posted 19 April 2012 - 04:09 AM

Here it is:
package net.minecraft.src;
public class ItemSpear extends Item
{
protected ItemSpear(int par1)
{
  super(par1);
}
public void onPlayerStoppedUsing(ItemStack itemstack, World world, EntityPlayer entityplayer, int i)
	{
  EntitySpear entityspear = new EntitySpear(world, entityplayer, 2.0F);
	world.spawnEntityInWorld(entityspear);
	}
}

Check out my Skyrim Let's Play here

tyber13 said:

So Bin Larden is finally dead. It's amazing what the Americans can do when the playstation network is down.

#15

Iamshortman
  • Location: socal
  • Minecraft: iamshortman

Posted 19 April 2012 - 11:49 PM

View Posthiloser12221, on 19 April 2012 - 04:09 AM, said:

Here it is:
package net.minecraft.src;
public class ItemSpear extends Item
{
protected ItemSpear(int par1)
{
  super(par1);
}
public void onPlayerStoppedUsing(ItemStack itemstack, World world, EntityPlayer entityplayer, int i)
	{
  EntitySpear entityspear = new EntitySpear(world, entityplayer, 2.0F);
	world.spawnEntityInWorld(entityspear);
	}
}
It works fine in eclipse but u need to put a "set item in use" on right click if you want it to spawn a spear.
"Well...... Thats a design flaw" - Me

#16

hiloser12221
  • Location: Behind you...
  • Minecraft: hiloser12221

Posted 20 April 2012 - 12:38 AM

View PostIamshortman, on 19 April 2012 - 11:49 PM, said:

It works fine in eclipse but u need to put a "set item in use" on right click if you want it to spawn a spear.
What do you mean a set item in use thing? Are you sure it worked in eclipse? the world.spawnEntityInWorld(entityspear) gave me the error "can't make static reference to the non-static method in world"
Check out my Skyrim Let's Play here

tyber13 said:

So Bin Larden is finally dead. It's amazing what the Americans can do when the playstation network is down.

#17

Iamshortman
  • Location: socal
  • Minecraft: iamshortman

Posted 20 April 2012 - 02:31 AM

View Posthiloser12221, on 20 April 2012 - 12:38 AM, said:

What do you mean a set item in use thing? Are you sure it worked in eclipse? the world.spawnEntityInWorld(entityspear) gave me the error "can't make static reference to the non-static method in world"
I fixed a piece so now it fires
I , in messing around got that Error when i referenced the World variable wrong(int the entity spawn in world ). the easiest way to explain it is, when you see this (, World world) you are saying that the Upper case World you are saying what ever is after that is a version of that. it is like saying EntitySpear entityspear = new EntitySpear, or int i. its a variable. so i think the name is incorrect, but i don't know why it doesn't work for you when it does for me.It is problem due to a different version of mcp so try messing with that name

eather way here is the code i edited to fire an arrow now.



package net.minecraft.src;
public class ItemSpear extends Item
{
protected ItemSpear(int par1)
{
  super(par1);
}
public void onPlayerStoppedUsing(ItemStack itemstack, World world, EntityPlayer entityplayer, int i)
		{
  EntitySpear entityspear = new EntitySpear(world, entityplayer, 2.0F);
		world.spawnEntityInWorld(entityspear);
		}
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
{
  if (!entityplayer.capabilities.isCreativeMode){
// entityplayer.inventory.consumeInventoryItem(mod_whatever .spear.shiftedIndex);
  }
  entityplayer.setItemInUse(itemstack, getMaxItemUseDuration(itemstack)); // this makes it so it will use the onPlayerStoppedUsing void
  return itemstack;
  }
}

"Well...... Thats a design flaw" - Me

#18

hiloser12221
  • Location: Behind you...
  • Minecraft: hiloser12221

Posted 20 April 2012 - 02:29 PM

Thanks, I'll let you know if I get it too work.
Check out my Skyrim Let's Play here

tyber13 said:

So Bin Larden is finally dead. It's amazing what the Americans can do when the playstation network is down.