Skip to content

Commit

Permalink
Did MF1 cooking recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackJar72 committed Jul 13, 2020
1 parent 514a94f commit b9975a4
Show file tree
Hide file tree
Showing 8 changed files with 284 additions and 2 deletions.
40 changes: 40 additions & 0 deletions main/java/jaredbgreat/mf3/api/ItemMeta.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package jaredbgreat.mf3.api;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class ItemMeta {
public final Item item;
public final int meta;

public ItemMeta(Item item, int meta) {
this.item = item;
this.meta = meta;
}

public ItemMeta(ItemStack item) {
this.item = item.getItem();
this.meta = item.getItemDamage();
}

public ItemStack getStack(int number) {
return new ItemStack(item, Math.min(number, item.getItemStackLimit()), meta);
}

@Override
public boolean equals(Object o) {
if(o instanceof ItemMeta) {
ItemMeta other = (ItemMeta)o;
return ((item == other.item) && (meta == other.meta));
}
return false;
}

@Override
public int hashCode() {
return item.hashCode() ^ (meta + (meta << 16));
}



}
95 changes: 95 additions & 0 deletions main/java/jaredbgreat/mf3/api/crafting/cooking/FoodPrepRecipe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package jaredbgreat.mf3.api.crafting.cooking;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;

public class FoodPrepRecipe {
public static List<FoodPrepRecipe> recipes = new ArrayList();

public float time;
public ItemStack input;
public ItemStack output;
public String utensil;
public String prepSound;



/**
* Adds a food preperation recipe on a board, while ignoring item metadata
* @param in the item ID for the input food
* @param out the result of the food
* @param time the amount of time used to craft
* @param utensil the utensil type (eg. "knife") used
* @param sound the sound made(same string as making a sound yourself)
*/
public static void addFoodPrepRecipe(Item in, ItemStack out, float time, String utensil, String sound)
{
recipes.add(new FoodPrepRecipe(in, out, time, utensil, sound));
}

/**
* Adds a food preperation recipe on a board
* @param in the food that goes in
* @param out the result of the food
* @param time the amount of time used to craft
* @param utensil the utensil type (eg. "knife") used
* @param sound the sound made(same string as making a sound yourself)
*/
public static void addFoodPrepRecipe(ItemStack in, ItemStack out, float time, String utensil, String sound)
{
recipes.add(new FoodPrepRecipe(in, out, time, utensil, sound));
}



public FoodPrepRecipe(Item in, ItemStack out, float time, String utensil, String sound)
{
this(new ItemStack(in, 1, OreDictionary.WILDCARD_VALUE), out, time, utensil, sound);
}

public FoodPrepRecipe(ItemStack in, ItemStack out, float time, String utensil, String sound)
{
this.time = time;
this.input = in;
this.output = out;
this.utensil = utensil;
this.prepSound = sound;
}

/**
* Gets a recipe depending on the type of tool used, and on what food
* @param in the food being used
* @param utensil the item that's being used on the food
* @return the recipe matching the process
*/
public static FoodPrepRecipe getRecipeFor(ItemStack in, ItemStack utensil)
{
if(in == null)
{
return null;
}

for(int a = 0; a < recipes.size(); a ++)
{
FoodPrepRecipe recipe = recipes.get(a);

if(in == recipe.input)
{
if(recipe.input.getItemDamage() == OreDictionary.WILDCARD_VALUE
|| recipe.input.getItemDamage() == in.getItemDamage())
{
if(UtensilManager.isToolValid(utensil, recipe.utensil))
{
return recipe;
}
}
}
}
return null;
}
}
15 changes: 15 additions & 0 deletions main/java/jaredbgreat/mf3/api/crafting/cooking/IHeatSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package jaredbgreat.mf3.api.crafting.cooking;

public interface IHeatSource {
/**
* Determines if a roast can be placed above
* @return true if the posts render above it
*/
boolean canPlaceAbove();

/**
* Gets the heat of the source(the higher, the faster)
* @return the heat in celcius
*/
int getHeat();
}
24 changes: 24 additions & 0 deletions main/java/jaredbgreat/mf3/api/crafting/cooking/IUtensil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package jaredbgreat.mf3.api.crafting.cooking;

import net.minecraft.entity.EntityLiving;
import net.minecraft.item.ItemStack;

public interface IUtensil
{

/**
* Gets the tool type for the item
* @param tool the tool item itself
* @return the item used Example:
* "knife" is used for a knife
*/
String getType(ItemStack tool);

/**
* Determines how fast the tool finishes recipes
* @param tool the item used
* @return the amount of efficiency
*/
float getEfficiency(ItemStack tool);
}

80 changes: 80 additions & 0 deletions main/java/jaredbgreat/mf3/api/crafting/cooking/OvenRecipes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package jaredbgreat.mf3.api.crafting.cooking;

import jaredbgreat.mf3.api.ItemMeta;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class OvenRecipes
{
/** The list of smelting results. */
private static Map smeltingList = new HashMap();
private static Map experienceList = new HashMap();
private static HashMap<List<ItemMeta>, ItemStack> metaSmeltingList
= new HashMap<List<ItemMeta>, ItemStack>();
private static HashMap<List<ItemMeta>, Float> metaExperience
= new HashMap<List<ItemMeta>, Float>();

/**
* Adds a smelting recipe.
*/
public static void addSmelting(int id, ItemStack stack, float xp)
{
smeltingList.put(Integer.valueOf(id), stack);
experienceList.put(stack.getItem(), Float.valueOf(xp));
}

/**
* A metadata sensitive version of adding a furnace recipe.
*/
public static void addSmelting(Item item, int meta, ItemStack itemstack, float experience)
{
metaSmeltingList.put(Arrays.asList(new ItemMeta(item, meta)), itemstack);
metaExperience.put(Arrays.asList(new ItemMeta(item, itemstack.getItemDamage())), experience);
}

/**
* Used to get the resulting ItemStack form a source ItemStack
* @param item The Source ItemStack
* @return The result ItemStack
*/
public static ItemStack getSmeltingResult(ItemStack item)
{
if (item == null)
{
return null;
}
ItemStack ret = (ItemStack)metaSmeltingList.get(Arrays.asList(item.getItem(), item.getItemDamage()));
if (ret != null)
{
return ret;
}
return (ItemStack)smeltingList.get(item.getItem());
}

/**
* Grabs the amount of base experience for this item to give when pulled from the furnace slot.
*/
public static float getExperience(ItemStack item)
{
if (item == null || item.getItem() == null)
{
return 0;
}
float ret = item.getItem().getSmeltingExperience(item);
if (ret < 0 && metaExperience.containsKey(Arrays.asList(item.getItem(), item.getItemDamage())))
{
ret = metaExperience.get(Arrays.asList(new ItemMeta(item.getItem(), item.getItemDamage())));
}
if (ret < 0 && experienceList.containsKey(item.getItem()))
{
ret = ((Float)experienceList.get(item.getItem())).floatValue();
}
return (ret < 0 ? 0 : ret);
}
}
28 changes: 28 additions & 0 deletions main/java/jaredbgreat/mf3/api/crafting/cooking/UtensilManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package jaredbgreat.mf3.api.crafting.cooking;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;

public class UtensilManager {

public static String getTypeOfTool(ItemStack tool)
{
if(tool != null && tool.getItem() != null)
{
if(tool.getItem() instanceof IUtensil)
{
return ((IUtensil)tool.getItem()).getType(tool);
}
}

return "Null";
}

public static boolean isToolValid(ItemStack tool, String type)
{
return getTypeOfTool(tool).equalsIgnoreCase(type);
}
}
2 changes: 1 addition & 1 deletion main/java/jaredbgreat/mf3/entity/EntityDrake.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package jaredbgreat.mf3.entity;

import jaredbgreat.mf3.ai.EntityAIFindCave;
import jaredbgreat.mf3.api.tactics.ISpecialSenses;
import jaredbgreat.mf3.entity.ai.EntityAIFindCave;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jaredbgreat.mf3.ai;
package jaredbgreat.mf3.entity.ai;

import jaredbgreat.mf3.entity.EntityDrake;

Expand Down

0 comments on commit b9975a4

Please sign in to comment.