import wsapr14.modfour.items.FlyingPizza;
import wsapr14.modfour.items.PizzaItem;
import wsapr14.modfour.items.RenderFlyingPizza;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid = ModFour.MODID, version = ModFour.VERSION)
public class ModFour {
public static final String MODID = "modfour";
public static final String VERSION = "1.0";
public static PizzaItem pizza;
public static FlyingPizza flyingPizza;
@EventHandler
public void preInit( FMLPreInitializationEvent event ) {
pizza = new PizzaItem();
pizza.setTextureName("modfour:PetersPizza");
GameRegistry.registerItem(pizza, pizza.getUnlocalizedName());
}
@EventHandler
public void init(FMLInitializationEvent event) {
LanguageRegistry.addName(pizza, "Peter's Pizza in mod4");
EntityRegistry.registerModEntity(FlyingPizza.class, "FlyingPizza", 1, this, 64, 10, true);
RenderingRegistry.registerEntityRenderingHandler(FlyingPizza.class, new RenderFlyingPizza(pizza));
}
}
--------------------
package wsapr14.modfour.items;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentText;
import net.minecraft.world.World;
public class PizzaItem extends Item {
public PizzaItem() {
super();
this.setMaxStackSize(64);
setCreativeTab(CreativeTabs.tabMisc);
setUnlocalizedName("PetersPizza4");
}
@Override
public boolean hitEntity(ItemStack itemstack, EntityLivingBase entity1, EntityLivingBase entity2) {
if(entity1 instanceof EntityZombie) {
entity1.motionY = 1.5;
((EntityPlayer) entity2).addChatMessage(new ChatComponentText("Well done " + ((EntityPlayer) entity2).getDisplayName() + " You go hit them zombies!"));
} else {
((EntityPlayer) entity2).addChatMessage(new ChatComponentText("Oh you dumbo " + ((EntityPlayer) entity2).getDisplayName() + "..you should not hit that!"));
}
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 FlyingPizza(par2World, par3EntityPlayer));
}
return par1ItemStack;
}
}
package wsapr14.modfour.items;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentText;
import net.minecraft.world.World;
public class PizzaItem extends Item {
public PizzaItem() {
super();
this.setMaxStackSize(64);
setCreativeTab(CreativeTabs.tabMisc);
setUnlocalizedName("PetersPizza4");
}
@Override
public boolean hitEntity(ItemStack itemstack, EntityLivingBase entity1, EntityLivingBase entity2) {
if(entity1 instanceof EntityZombie) {
entity1.motionY = 1.5;
((EntityPlayer) entity2).addChatMessage(new ChatComponentText("Well done " + ((EntityPlayer) entity2).getDisplayName() + " You go hit them zombies!"));
} else {
((EntityPlayer) entity2).addChatMessage(new ChatComponentText("Oh you dumbo " + ((EntityPlayer) entity2).getDisplayName() + "..you should not hit that!"));
}
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 FlyingPizza(par2World, par3EntityPlayer));
}
return par1ItemStack;
}
}
------
package wsapr14.modfour.items;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
public class FlyingPizza extends EntityThrowable {
public FlyingPizza(World par1World) {
super(par1World);
}
public FlyingPizza(World par2World, EntityPlayer par3EntityPlayer) {
super(par2World,par3EntityPlayer);
}
@Override
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) {
PizzaParticleEffects.spawnParticle("pizzaPiece",this.posX, this.posY, this.posZ, 0, -0.1, 0);
}
if (!this.worldObj.isRemote) {
this.setDead();
}
}
}
-----
package wsapr14.modfour.items;
import net.minecraft.client.renderer.entity.RenderSnowball;
import net.minecraft.item.Item;
public class RenderFlyingPizza extends RenderSnowball {
public RenderFlyingPizza(Item par1Item) {
super(par1Item);
}
}
-----
package wsapr14.modfour.items;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityBreakingFX;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.world.World;
import wsapr14.modfour.ModFour;
public class PizzaParticleEffects {
private static Minecraft mc = Minecraft.getMinecraft();
private static World theWorld = mc.theWorld;
private static TextureManager renderEngine = mc.renderEngine;
public static EntityFX spawnParticle(String particleName, double par2, double par4, double par6, double par8, double par10, double par12) {
if (mc != null && mc.renderViewEntity != null && mc.effectRenderer != null) {
int var14 = mc.gameSettings.particleSetting;
if (var14 == 1 && theWorld.rand.nextInt(3) == 0) {
var14 = 2;
}
double var15 = mc.renderViewEntity.posX - par2;
double var17 = mc.renderViewEntity.posY - par4;
double var19 = mc.renderViewEntity.posZ - par6;
EntityFX var21 = null;
double var22 = 16.0D;
if (var15 * var15 + var17 * var17 + var19 * var19 > var22 * var22) {
return null;
} else if (var14 > 1) {
return null;
} else {
if (particleName.equals("pizzaPiece")) {
var21 = new EntityBreakingFX(theWorld, par2, par4, par6, ModFour.pizza);
}
mc.effectRenderer.addEffect(var21);
return var21;
}
}
return null;
}
}