Worked on food item
This commit is contained in:
parent
5c2d07b0f5
commit
3d97fa49ba
6 changed files with 388 additions and 19 deletions
23
src/dark/farmtech/FTRecipeLoader.java
Normal file
23
src/dark/farmtech/FTRecipeLoader.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package dark.farmtech;
|
||||
|
||||
import dark.core.common.RecipeLoader;
|
||||
|
||||
public class FTRecipeLoader extends RecipeLoader
|
||||
{
|
||||
private static FTRecipeLoader instance;
|
||||
|
||||
public static FTRecipeLoader instance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new FTRecipeLoader();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadRecipes()
|
||||
{
|
||||
super.loadRecipes();
|
||||
}
|
||||
}
|
|
@ -142,20 +142,10 @@ public class FarmTech extends ModPrefab
|
|||
|
||||
}
|
||||
|
||||
public static final CreativeTabs TabFarmTech = new CreativeTabs("FarmTech")
|
||||
{
|
||||
@Override
|
||||
public ItemStack getIconItemStack()
|
||||
{
|
||||
return new ItemStack(Item.wheat.itemID, 1, 0);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void loadRecipes()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
FTRecipeLoader.instance().loadRecipes();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,17 +1,179 @@
|
|||
package dark.farmtech.entities;
|
||||
|
||||
import net.minecraft.entity.EntityAgeable;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.EntityAIFollowParent;
|
||||
import net.minecraft.entity.ai.EntityAILookIdle;
|
||||
import net.minecraft.entity.ai.EntityAIMate;
|
||||
import net.minecraft.entity.ai.EntityAIPanic;
|
||||
import net.minecraft.entity.ai.EntityAISwimming;
|
||||
import net.minecraft.entity.ai.EntityAITempt;
|
||||
import net.minecraft.entity.ai.EntityAIWander;
|
||||
import net.minecraft.entity.ai.EntityAIWatchClosest;
|
||||
import net.minecraft.entity.passive.EntityAnimal;
|
||||
import net.minecraft.entity.passive.EntityChicken;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemSeeds;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class EntityTurkey extends EntityChicken
|
||||
public class EntityTurkey extends EntityAnimal
|
||||
{
|
||||
|
||||
public EntityTurkey(World par1World)
|
||||
public float field_70886_e;
|
||||
public float destPos;
|
||||
public float field_70884_g;
|
||||
public float field_70888_h;
|
||||
public float field_70889_i = 1.0F;
|
||||
|
||||
/** The time until the next egg is spawned. */
|
||||
public int timeUntilNextEgg;
|
||||
|
||||
public EntityTurkey(World world)
|
||||
{
|
||||
super(par1World);
|
||||
// TODO Auto-generated constructor stub
|
||||
super(world);
|
||||
this.setSize(0.8F, 1.2F);
|
||||
this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
|
||||
this.tasks.addTask(0, new EntityAISwimming(this));
|
||||
this.tasks.addTask(1, new EntityAIPanic(this, 1.4D));
|
||||
this.tasks.addTask(2, new EntityAIMate(this, 1.0D));
|
||||
this.tasks.addTask(3, new EntityAITempt(this, 1.0D, Item.seeds.itemID, false));
|
||||
this.tasks.addTask(4, new EntityAIFollowParent(this, 1.1D));
|
||||
this.tasks.addTask(5, new EntityAIWander(this, 1.0D));
|
||||
this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
|
||||
this.tasks.addTask(7, new EntityAILookIdle(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAIEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyEntityAttributes()
|
||||
{
|
||||
super.applyEntityAttributes();
|
||||
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setAttribute(4.0D);
|
||||
this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setAttribute(0.25D);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLivingUpdate()
|
||||
{
|
||||
super.onLivingUpdate();
|
||||
this.field_70888_h = this.field_70886_e;
|
||||
this.field_70884_g = this.destPos;
|
||||
this.destPos = (float) (this.destPos + (this.onGround ? -1 : 4) * 0.3D);
|
||||
|
||||
if (this.destPos < 0.0F)
|
||||
{
|
||||
this.destPos = 0.0F;
|
||||
}
|
||||
|
||||
if (this.destPos > 1.0F)
|
||||
{
|
||||
this.destPos = 1.0F;
|
||||
}
|
||||
|
||||
if (!this.onGround && this.field_70889_i < 1.0F)
|
||||
{
|
||||
this.field_70889_i = 1.0F;
|
||||
}
|
||||
|
||||
this.field_70889_i = (float) (this.field_70889_i * 0.9D);
|
||||
|
||||
if (!this.onGround && this.motionY < 0.0D)
|
||||
{
|
||||
this.motionY *= 0.6D;
|
||||
}
|
||||
|
||||
this.field_70886_e += this.field_70889_i * 2.0F;
|
||||
|
||||
if (!this.isChild() && !this.worldObj.isRemote && --this.timeUntilNextEgg <= 0)
|
||||
{
|
||||
this.playSound("mob.chicken.plop", 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
|
||||
this.dropItem(Item.egg.itemID, 1);
|
||||
this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
|
||||
}
|
||||
}
|
||||
|
||||
/** Called when the mob is falling. Calculates and applies fall damage. */
|
||||
@Override
|
||||
protected void fall(float par1)
|
||||
{
|
||||
}
|
||||
|
||||
/** Returns the sound this mob makes while it's alive. */
|
||||
@Override
|
||||
protected String getLivingSound()
|
||||
{
|
||||
return "mob.chicken.say";
|
||||
}
|
||||
|
||||
/** Returns the sound this mob makes when it is hurt. */
|
||||
@Override
|
||||
protected String getHurtSound()
|
||||
{
|
||||
return "mob.chicken.hurt";
|
||||
}
|
||||
|
||||
/** Returns the sound this mob makes on death. */
|
||||
@Override
|
||||
protected String getDeathSound()
|
||||
{
|
||||
return "mob.chicken.hurt";
|
||||
}
|
||||
|
||||
/** Plays step sound at given x, y, z for the entity */
|
||||
@Override
|
||||
protected void playStepSound(int par1, int par2, int par3, int par4)
|
||||
{
|
||||
this.playSound("mob.chicken.step", 0.15F, 1.0F);
|
||||
}
|
||||
|
||||
/** Returns the item ID for the item the mob drops on death. */
|
||||
@Override
|
||||
protected int getDropItemId()
|
||||
{
|
||||
return Item.feather.itemID;
|
||||
}
|
||||
|
||||
/** Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit
|
||||
* by a player. @param par2 - Level of Looting used to kill this mob. */
|
||||
@Override
|
||||
protected void dropFewItems(boolean par1, int par2)
|
||||
{
|
||||
int j = this.rand.nextInt(3) + this.rand.nextInt(1 + par2);
|
||||
|
||||
for (int k = 0; k < j; ++k)
|
||||
{
|
||||
this.dropItem(Item.feather.itemID, 1);
|
||||
}
|
||||
|
||||
if (this.isBurning())
|
||||
{
|
||||
this.dropItem(Item.chickenCooked.itemID, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.dropItem(Item.chickenRaw.itemID, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/** Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots
|
||||
* or seeds depending on the animal type) */
|
||||
@Override
|
||||
public boolean isBreedingItem(ItemStack par1ItemStack)
|
||||
{
|
||||
return par1ItemStack != null && par1ItemStack.getItem() instanceof ItemSeeds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityAgeable createChild(EntityAgeable par1EntityAgeable)
|
||||
{
|
||||
return new EntityChicken(this.worldObj);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,14 +13,14 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
import dark.farmtech.FarmTech;
|
||||
|
||||
/** Bucket containing compost for farming
|
||||
*
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class ItemFarmBucket extends ItemBucket
|
||||
{
|
||||
public ItemFarmBucket(int itemID, int blockID)
|
||||
{
|
||||
super(FarmTech.CONFIGURATION.getItem("Bucket", itemID).getInt(), blockID);
|
||||
this.setCreativeTab(FarmTech.TabFarmTech);
|
||||
this.setCreativeTab(CreativeTabs.tabMisc);
|
||||
this.setHasSubtypes(true);
|
||||
this.setContainerItem(Item.bucketEmpty);
|
||||
this.setUnlocalizedName("farmBucket");
|
||||
|
|
193
src/dark/farmtech/item/ItemFood.java
Normal file
193
src/dark/farmtech/item/ItemFood.java
Normal file
|
@ -0,0 +1,193 @@
|
|||
package dark.farmtech.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.Configuration;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import dark.core.prefab.IExtraInfo.IExtraItemInfo;
|
||||
import dark.farmtech.FarmTech;
|
||||
|
||||
/** Item for storing all kinds of food based items including meats, fruits, pies, cakes, breads, etc
|
||||
* we have 1000s of meta to work with :)
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class ItemFood extends Item implements IExtraItemInfo
|
||||
{
|
||||
public ItemFood(int par1)
|
||||
{
|
||||
super(FarmTech.CONFIGURATION.getItem("Food", FarmTech.getNextID()).getInt());
|
||||
this.setHasSubtypes(true);
|
||||
this.setCreativeTab(CreativeTabs.tabFood);
|
||||
this.setUnlocalizedName("FarmFood");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onEaten(ItemStack itemStack, World world, EntityPlayer player)
|
||||
{
|
||||
FarmFood food = FarmFood.get(itemStack);
|
||||
if (player != null && food != null)
|
||||
{
|
||||
--itemStack.stackSize;
|
||||
//TODO add stats and achievements for some of the foods
|
||||
world.playSoundAtEntity(player, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F);
|
||||
|
||||
if (!world.isRemote && food.hasPotion && food.potionID > 0 && world.rand.nextFloat() < food.potionChance)
|
||||
{
|
||||
player.addPotionEffect(new PotionEffect(food.potionID, food.potionDuration * 20, food.potionAmp));
|
||||
}
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxItemUseDuration(ItemStack par1ItemStack)
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumAction getItemUseAction(ItemStack par1ItemStack)
|
||||
{
|
||||
return EnumAction.eat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
|
||||
{
|
||||
if (player.canEat(true))
|
||||
{
|
||||
player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(IconRegister par1IconRegister)
|
||||
{
|
||||
for (FarmFood food : FarmFood.values())
|
||||
{
|
||||
food.icon = par1IconRegister.registerIcon(FarmTech.instance.PREFIX + "food_" + food.name);
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public Icon getIconFromDamage(int par1)
|
||||
{
|
||||
FarmFood food = FarmFood.get(par1);
|
||||
if (food != null)
|
||||
{
|
||||
return food.icon;
|
||||
}
|
||||
return this.itemIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
|
||||
{
|
||||
par3List.add(new ItemStack(this.itemID, 1, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasExtraConfigs()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadExtraConfigs(Configuration config)
|
||||
{
|
||||
for (FarmFood food : FarmFood.values())
|
||||
{
|
||||
food.foodValue = (float) config.get("FoodValue", food.name, food.foodValue).getDouble(food.foodValue);
|
||||
food.saturation = (float) config.get("FoodSaturation", food.name, food.saturation).getDouble(food.saturation);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadOreNames()
|
||||
{
|
||||
for (FarmFood food : FarmFood.values())
|
||||
{
|
||||
OreDictionary.registerOre(food.name, new ItemStack(this, 1, food.ordinal()));
|
||||
}
|
||||
}
|
||||
|
||||
/** enum that stores data for each meta value that represents a food object for the item
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public static enum FarmFood
|
||||
{
|
||||
TurkeyRaw("TurkeyRaw", 1, 2, 0.3F),
|
||||
TurkeyCooked("TurkeyCooked", 6, 0.6F);
|
||||
/** Metadata id that this item converts to for each recipe creation */
|
||||
final int cookedID;
|
||||
/** Name used for translation and icons */
|
||||
final String name;
|
||||
float foodValue;
|
||||
float saturation;
|
||||
boolean hasPotion = false;
|
||||
int potionID, potionDuration, potionAmp;
|
||||
float potionChance;
|
||||
Icon icon;
|
||||
|
||||
private FarmFood(String name, float foodValue, float saturation)
|
||||
{
|
||||
this(name, -1, foodValue, saturation);
|
||||
}
|
||||
|
||||
private FarmFood(String name, int cookedID, float foodValue, float saturation)
|
||||
{
|
||||
this.name = name;
|
||||
this.cookedID = cookedID;
|
||||
//Means the food is raw and can harm the player if not cooked
|
||||
if (cookedID != -1)
|
||||
{
|
||||
this.hasPotion = true;
|
||||
this.potionID = Potion.hunger.id;
|
||||
this.potionDuration = 30;
|
||||
this.potionAmp = 0;
|
||||
this.potionChance = 0.3F;
|
||||
}
|
||||
}
|
||||
|
||||
private FarmFood(String name, int cookedID, float foodValue, float saturation, int pID, int pD, int pA, float pC)
|
||||
{
|
||||
this.name = name;
|
||||
this.cookedID = cookedID;
|
||||
this.hasPotion = true;
|
||||
this.potionID = pID;
|
||||
this.potionDuration = pD;
|
||||
this.potionAmp = pA;
|
||||
this.potionChance = pC;
|
||||
}
|
||||
|
||||
public static FarmFood get(ItemStack stack)
|
||||
{
|
||||
return get(stack != null ? stack.getItemDamage() : -1);
|
||||
}
|
||||
|
||||
public static FarmFood get(int meta)
|
||||
{
|
||||
if (meta >= 0 && meta < FarmFood.values().length)
|
||||
{
|
||||
return FarmFood.values()[meta];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +1,20 @@
|
|||
package dark.farmtech.machines;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import dark.core.common.DMCreativeTab;
|
||||
import dark.core.prefab.machine.BlockMachine;
|
||||
import dark.core.registration.ModObjectRegistry.BlockBuildData;
|
||||
import dark.farmtech.FarmTech;
|
||||
|
||||
/** Prefab class for all farm blocks to remove the need for some configuration of the super class
|
||||
*
|
||||
*
|
||||
* @author Darkguardsman */
|
||||
public abstract class BlockFT extends BlockMachine
|
||||
{
|
||||
|
||||
public BlockFT(Class<? extends BlockMachine> blockClass, String name, Material material)
|
||||
{
|
||||
super(new BlockBuildData(blockClass, name, material).setCreativeTab(FarmTech.TabFarmTech));
|
||||
super(new BlockBuildData(blockClass, name, material).setCreativeTab(DMCreativeTab.tabIndustrial));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue