1
Throwable Items?
Hello,
I made an item similar to an egg. I want to be able to throw the egg, and have it explode when it hits anything.
Here is the current codeIt makes the player jump whenever the mouse is right clicked.
If someone can please tell me how to make it throwable and explode when it hits something, I will greatly appreciate it.
If you would rather link something explaining it, that is welcome as well.
Thanks,
Router
I made an item similar to an egg. I want to be able to throw the egg, and have it explode when it hits anything.
Here is the current code
Click to reveal
package onebarrouter.chickenwars;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class ItemBombEgg extends Item {
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player){
player.jump();
return itemStack;
}
}
If someone can please tell me how to make it throwable and explode when it hits something, I will greatly appreciate it.
If you would rather link something explaining it, that is welcome as well.
Thanks,
Router
1
The easiest way for something like this is to create an entity in onItemRightClick for your item. That entity will have motion applied.
The entity needs to extend EntityThrowable, and override onImpact. In that method, create your explosion.
If you're confused just look at the ItemEgg and EntityEgg classes, it's pretty simple
Don't forget, you'll need to manually remove the item from the players inventory when they throw it - and it's a good idea to check if they're creative (and if so DON'T remove the item) too.
The entity needs to extend EntityThrowable, and override onImpact. In that method, create your explosion.
If you're confused just look at the ItemEgg and EntityEgg classes, it's pretty simple
Don't forget, you'll need to manually remove the item from the players inventory when they throw it - and it's a good idea to check if they're creative (and if so DON'T remove the item) too.
