package wsdec13.peter.items;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntitySnowball;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import wsdec13.peter.items.EntityPizza;
public class PizzaItem extends Item {
public PizzaItem(int id) {
super(id);
setCreativeTab(CreativeTabs.tabMisc);
setUnlocalizedName("PetersPizza");
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister) {
itemIcon = iconRegister.registerIcon("wsdec13pcmod" + ":" + "pizza");
}
@Override
public boolean hitEntity(ItemStack itemstack, EntityLivingBase entity1, EntityLivingBase entity2) {
if(entity1 instanceof EntityZombie) {
entity1.motionY = 3;
((EntityPlayer) entity2).addChatMessage("Danger...flying zombies!");
} else {
((EntityPlayer) entity2).addChatMessage("Je bent een klojo als je geen pizza lust!! ");
}
return false;
}
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 EntityPizza(par2World, par3EntityPlayer));
}
return par1ItemStack;
}
}
wsdec13.peter.items.EntityPizza.java
package wsdec13.peter.items;
import cpw.mods.fml.common.registry.IThrowableEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
public class EntityPizza extends EntityThrowable {
public EntityPizza(World world) {
super(world);
}
public EntityPizza(World world, EntityLivingBase livingBase) {
super(world, livingBase);
}
public EntityPizza(World world, double x, double y, double z) {
super(world, x, y, z);
}
protected void onImpact(MovingObjectPosition movingObjectPosition) {
if (movingObjectPosition.entityHit != null) {
float damage = 0;
if(movingObjectPosition.entityHit instanceof EntityZombie) {
damage = 5;
movingObjectPosition.entityHit.motionY=3;
} else if (movingObjectPosition.entityHit instanceof EntityBlaze) {
damage = 3;
}
movingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), damage);
}
for (int i = 0; i < 8; ++i) {
double red = 202D / 255D;
double green = 112D / 255D;
double blue = 15D / 255D;
this.worldObj.spawnParticle("reddust", this.posX, this.posY, this.posZ, red, green, blue);
}
if (!this.worldObj.isRemote) {
this.setDead();
}
}
}