Some more work on the crafting system, almost done it.
It was a lot easier that I thought it would be
This commit is contained in:
parent
12bea10af6
commit
f075d6391c
5 changed files with 59 additions and 13 deletions
|
@ -25,7 +25,6 @@ public abstract class BaseRecipe implements IBaseRecipeType {
|
|||
outputs = new ArrayList<ItemStack>();
|
||||
this.name = name;
|
||||
//This adds all new recipes
|
||||
RecipeHanderer.addRecipe(this);
|
||||
this.tickTime = tickTime;
|
||||
this.euPerTick = euPerTick;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package techreborn.api.recipe;
|
|||
import ic2.api.energy.prefab.BasicSink;
|
||||
import techreborn.tiles.TileMachineBase;
|
||||
import techreborn.util.Inventory;
|
||||
import techreborn.util.ItemUtils;
|
||||
|
||||
/**
|
||||
* Use this in your tile entity to craft things
|
||||
|
@ -45,7 +46,7 @@ public class RecipeCrafter {
|
|||
public int[] inputSlots;
|
||||
|
||||
/**
|
||||
* This si the list fo the slots that the crafting logic should look fot the output item stacks.
|
||||
* This is the list for the slots that the crafting logic should look fot the output item stacks.
|
||||
*/
|
||||
public int[] outputSlots;
|
||||
|
||||
|
@ -72,10 +73,44 @@ public class RecipeCrafter {
|
|||
}
|
||||
|
||||
|
||||
IBaseRecipeType currentRecipe;
|
||||
int currentTickTime = 0;
|
||||
|
||||
/**
|
||||
* Call this on the tile tick
|
||||
*/
|
||||
public void updateEntity(){
|
||||
|
||||
if(currentRecipe == null){
|
||||
for(IBaseRecipeType recipe : RecipeHanderer.getRecipeClassFromName(recipeName)){
|
||||
boolean isFullRecipe = false;
|
||||
for (int i = 0; i < inputs; i++) {
|
||||
if(ItemUtils.isItemEqual(inventory.getStackInSlot(inputSlots[i]), recipe.getInputs().get(i), true, true)){
|
||||
isFullRecipe = true;
|
||||
} else {
|
||||
isFullRecipe = false;
|
||||
}
|
||||
}
|
||||
if(isFullRecipe){
|
||||
currentRecipe = recipe;
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < inputs; i++) {
|
||||
if(!ItemUtils.isItemEqual(inventory.getStackInSlot(inputSlots[i]), currentRecipe.getInputs().get(i), true, true)){
|
||||
currentRecipe = null;
|
||||
currentTickTime = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(currentTickTime >= currentRecipe.tickTime()){
|
||||
//TODO give the player the goodies :)
|
||||
//Need some nicer way of added the crafting things.
|
||||
} else {
|
||||
if(energy.useEnergy(currentRecipe.euPerTick())){
|
||||
currentTickTime ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ public class RecipeHanderer {
|
|||
public static List<IBaseRecipeType> getRecipeClassFromName(String name){
|
||||
List<IBaseRecipeType> baseRecipeList = new ArrayList<IBaseRecipeType>();
|
||||
for(IBaseRecipeType baseRecipe : recipeList){
|
||||
if(baseRecipe.equals(name)){
|
||||
if(baseRecipe.getRecipeName().equals(name)){
|
||||
baseRecipeList.add(baseRecipe);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package techreborn.init;
|
||||
|
||||
import codechicken.nei.api.API;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import ic2.api.item.IC2Items;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
|
@ -8,12 +8,11 @@ import net.minecraft.item.ItemStack;
|
|||
import techreborn.api.BlastFurnaceRecipe;
|
||||
import techreborn.api.CentrifugeRecipie;
|
||||
import techreborn.api.TechRebornAPI;
|
||||
import techreborn.api.recipe.RecipeHanderer;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.recipes.ImplosionCompressorRecipe;
|
||||
import techreborn.util.CraftingHelper;
|
||||
import techreborn.util.LogHelper;
|
||||
import techreborn.util.RecipeRemover;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
public class ModRecipes {
|
||||
public static ConfigTechReborn config;
|
||||
|
@ -196,7 +195,7 @@ public class ModRecipes {
|
|||
Blocks.cobblestone);
|
||||
TechRebornAPI.registerBlastFurnaceRecipe(new BlastFurnaceRecipe(new ItemStack(Items.apple), new ItemStack(Items.ender_pearl), new ItemStack(Items.golden_apple), new ItemStack(Items.diamond), 120, 1000));
|
||||
|
||||
new ImplosionCompressorRecipe(new ItemStack(Items.diamond), new ItemStack(Items.golden_apple), new ItemStack(Items.brewing_stand), new ItemStack(Items.carrot), 120, 5);
|
||||
RecipeHanderer.addRecipe(new ImplosionCompressorRecipe(new ItemStack(Items.diamond), new ItemStack(Items.golden_apple), new ItemStack(Items.brewing_stand), new ItemStack(Items.carrot), 120, 5));
|
||||
|
||||
LogHelper.info("Machine Recipes Added");
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package techreborn.tiles;
|
|||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import techreborn.api.recipe.RecipeCrafter;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.util.Inventory;
|
||||
import ic2.api.energy.prefab.BasicSink;
|
||||
|
@ -12,7 +13,19 @@ public class TileImplosionCompressor extends TileMachineBase implements IWrencha
|
|||
public int tickTime;
|
||||
public BasicSink energy;
|
||||
public Inventory inventory = new Inventory(4, "TileImplosionCompressor", 64);
|
||||
|
||||
public RecipeCrafter crafter;
|
||||
|
||||
public TileImplosionCompressor() {
|
||||
energy = new BasicSink(this, 100000, 1);
|
||||
//Input slots
|
||||
int[] inputs = new int[2];
|
||||
inputs[0] = 0;
|
||||
inputs[1] = 1;
|
||||
int[] outputs = new int[2];
|
||||
outputs[0] = 2;
|
||||
outputs[1] = 3;
|
||||
crafter = new RecipeCrafter("implosionCompressorRecipe", this, energy, 2, 2, inventory, inputs, outputs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side)
|
||||
|
@ -49,9 +62,9 @@ public class TileImplosionCompressor extends TileMachineBase implements IWrencha
|
|||
return new ItemStack(ModBlocks.ImplosionCompressor, 1);
|
||||
}
|
||||
|
||||
public boolean isComplete()
|
||||
{
|
||||
return false;
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
crafter.updateEntity();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue