April 2014 - Flying pizza

package wsapr14.modfour;

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.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;
 }
}


April 2014 - Flying zombie

 @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;
}

April 2014 - Mod with item with zombie damage


  • Kopieer ModTwo -> ModThree
  • Refactor/rename packages
  • Maak eventueel een tweede texture voor je pizza item
  • Aanpassen In ModThree.java

@EventHandler
public void init(FMLInitializationEvent event) {
LanguageRegistry.addName(pizza, "Peter's Pizza in mod3");

}


  • Toevoegen aan PizzaItem.java
 @Override
 public boolean hitEntity(ItemStack itemstack, EntityLivingBase entity1, EntityLivingBase entity2) {
   if(entity1 instanceof EntityZombie) {
       entity1.motionY = 3;
       ((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;
}

  • Voeg project ModThree toe aan ClassPath van client configuratie
  • Test

April 2014 - Mod met item


  • Nieuw project , ModTwo (copieer ModOne) en hernoem alle ModOne's naar ModTwo
  • Nieuw package : wsapr14. modtwo.items
  • Nieuw class, wsapr14.modtwo.items.PizzaItem

package wsapr14.modtwo.items;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;

public class PizzaItem extends Item {
public PizzaItem() {
super();
        maxStackSize = 64;
setCreativeTab(CreativeTabs.tabMisc);
setUnlocalizedName("PetersPizza");
}
}


  • Pas ModTwo aan
package wsapr14.modtwo;

import wsapr14.modtwo.items.PizzaItem;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
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.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = ModTwo.MODID, version = ModTwo.VERSION)
public class ModTwo {

public static final String MODID = "modtwo";
public static final String VERSION = "1.0";
public static PizzaItem pizza;

@EventHandler
public  void preInit( FMLPreInitializationEvent event ) {
pizza = new PizzaItem();
pizza.setTextureName("modtwo:PetersPizza");
        GameRegistry.registerItem(pizza, pizza.getUnlocalizedName());

}

@EventHandler
public void init(FMLInitializationEvent event) {
}
}

  • Nieuw package : assets.modtwo.textures.items
  • Maak texture aan via http://pixlr.com/editor/
    • transparant
    • 64x64 bits
    • save as png : assets\modtwo\textures\items\PetersPizza.png


April 2014 - Eerste mod

  1. Verwijder ExampleOne class
  2. Nieuw java project maken in eclipse workspace
  3. Nieuw package , bv wsapr14.modone
  4. Nieuwe java class



package wsapr14.modone;

import net.minecraft.init.Blocks;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;

@Mod(modid = ModOne.MODID, version = ModOne.VERSION)
public class ModOne {

public static final String MODID = "modone";
public static final String VERSION = "1.0";

@EventHandler
public void init(FMLInitializationEvent event) {
// some example code
System.out.println("DIRT BLOCK >> " + Blocks.dirt.getUnlocalizedName());
}
}

April 2014 - Forge installatie


  1. Download http://www.minecraftforge.net/forum/index.php?action=files - 1.7.2-Latest - src
  2. Maak folder (forge), copieer download, unzip
  3. cmd / terminal in forge folder
  4. gradlew setupDecompWorkspace
  5. gradlew eclipse
  6. Open eclipse, go to eclipse folder in forge folder
  7. Try to run