Search in sources :

Example 1 with MachineRecipeInput

use of crazypants.enderio.base.recipe.MachineRecipeInput in project EnderIO by SleepyTrousers.

the class PoweredTask method readFromNBT.

@Nullable
public static IPoweredTask readFromNBT(@Nonnull NBTTagCompound nbtRoot) {
    IMachineRecipe recipe;
    float usedEnergy = nbtRoot.getFloat(KEY_USED_ENERGY);
    long seed = nbtRoot.getLong(KEY_SEED);
    float outputMultiplier = nbtRoot.getFloat(KEY_CHANCE_OUTPUT);
    float chanceMultiplier = nbtRoot.getFloat(KEY_CHANCE_MULTI);
    NBTTagList inputItems = (NBTTagList) nbtRoot.getTag(KEY_INPUT_STACKS);
    NNList<MachineRecipeInput> ins = new NNList<MachineRecipeInput>();
    for (int i = 0; i < inputItems.tagCount(); i++) {
        NBTTagCompound stackTag = inputItems.getCompoundTagAt(i);
        MachineRecipeInput mi = MachineRecipeInput.readFromNBT(stackTag);
        ins.add(mi);
    }
    String uid = nbtRoot.getString(KEY_RECIPE);
    recipe = MachineRecipeRegistry.instance.getRecipeForUid(uid);
    if (recipe != null) {
        return new PoweredTask(recipe, usedEnergy, seed, outputMultiplier, chanceMultiplier, ins);
    }
    return null;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NNList(com.enderio.core.common.util.NNList) IPoweredTask(crazypants.enderio.base.machine.interfaces.IPoweredTask) MachineRecipeInput(crazypants.enderio.base.recipe.MachineRecipeInput) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IMachineRecipe(crazypants.enderio.base.recipe.IMachineRecipe) Nullable(javax.annotation.Nullable)

Example 2 with MachineRecipeInput

use of crazypants.enderio.base.recipe.MachineRecipeInput in project EnderIO by SleepyTrousers.

the class PoweredTask method writeToNBT.

@Override
public void writeToNBT(@Nonnull NBTTagCompound nbtRoot) {
    NBTTagList inputItems = new NBTTagList();
    for (MachineRecipeInput ri : inputs) {
        NBTTagCompound stackRoot = new NBTTagCompound();
        ri.writeToNbt(stackRoot);
        inputItems.appendTag(stackRoot);
    }
    nbtRoot.setTag(KEY_INPUT_STACKS, inputItems);
    nbtRoot.setString(KEY_RECIPE, recipe.getUid());
    nbtRoot.setFloat(KEY_USED_ENERGY, usedEnergy);
    nbtRoot.setLong(KEY_SEED, nextSeed);
    nbtRoot.setFloat(KEY_CHANCE_OUTPUT, outputMultiplier);
    nbtRoot.setFloat(KEY_CHANCE_MULTI, chanceMultiplier);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) MachineRecipeInput(crazypants.enderio.base.recipe.MachineRecipeInput) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 3 with MachineRecipeInput

use of crazypants.enderio.base.recipe.MachineRecipeInput in project EnderIO by SleepyTrousers.

the class AbstractPoweredTaskEntity method startNextTask.

protected boolean startNextTask(@Nonnull IMachineRecipe nextRecipe, long nextSeed) {
    if (hasPower() && nextRecipe.isRecipe(getRecipeInputs())) {
        // then get our recipe and take away the source items
        currentTask = createTask(nextRecipe, nextSeed);
        List<MachineRecipeInput> consumed = nextRecipe.getQuantitiesConsumed(getRecipeInputs());
        for (MachineRecipeInput item : consumed) {
            if (item != null) {
                if (Prep.isValid(item.item)) {
                    decrStackSize(item.slotNumber, item.item.getCount());
                } else if (item.fluid != null) {
                    drainInputFluid(item);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : MachineRecipeInput(crazypants.enderio.base.recipe.MachineRecipeInput)

Example 4 with MachineRecipeInput

use of crazypants.enderio.base.recipe.MachineRecipeInput in project EnderIO by SleepyTrousers.

the class EnchanterRecipe method getVariants.

public NNList<NNList<MachineRecipeInput>> getVariants() {
    NNList<NNList<MachineRecipeInput>> result = new NNList<>();
    for (int level = 1; level <= enchantment.getMaxLevel(); level++) {
        for (ItemStack item : input.getItemStacks()) {
            item = item.copy();
            for (ItemStack lapis : LAPIS.getItemStacks()) {
                lapis = lapis.copy();
                item.setCount(stackSizePerLevel * level);
                lapis.setCount(getLapizForLevel(level));
                if (item.getCount() <= item.getMaxStackSize() && lapis.getCount() <= lapis.getMaxStackSize()) {
                    result.add(getQuantitiesConsumed(new NNList<>(new MachineRecipeInput(0, BOOK.getItemStacks().get(0)), new MachineRecipeInput(1, item), new MachineRecipeInput(2, lapis))));
                }
            }
        }
    }
    return result;
}
Also used : NNList(com.enderio.core.common.util.NNList) MachineRecipeInput(crazypants.enderio.base.recipe.MachineRecipeInput) ItemStack(net.minecraft.item.ItemStack)

Example 5 with MachineRecipeInput

use of crazypants.enderio.base.recipe.MachineRecipeInput in project EnderIO by SleepyTrousers.

the class AbstractPainterTemplate method getQuantitiesConsumed.

@Override
@Nonnull
public List<MachineRecipeInput> getQuantitiesConsumed(@Nonnull NNList<MachineRecipeInput> inputs) {
    MachineRecipeInput consume = null;
    for (MachineRecipeInput input : inputs) {
        if (input != null && input.slotNumber == 0 && Prep.isValid(input.item)) {
            ItemStack consumed = input.item.copy();
            consumed.setCount(1);
            consume = new MachineRecipeInput(input.slotNumber, consumed);
        }
    }
    if (consume != null) {
        return Collections.singletonList(consume);
    }
    return Collections.emptyList();
}
Also used : MachineRecipeInput(crazypants.enderio.base.recipe.MachineRecipeInput) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

MachineRecipeInput (crazypants.enderio.base.recipe.MachineRecipeInput)14 ItemStack (net.minecraft.item.ItemStack)9 Nonnull (javax.annotation.Nonnull)8 NNList (com.enderio.core.common.util.NNList)5 IMachineRecipe (crazypants.enderio.base.recipe.IMachineRecipe)2 ArrayList (java.util.ArrayList)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 GhostBackgroundItemSlot (com.enderio.core.client.gui.widget.GhostBackgroundItemSlot)1 GhostSlot (com.enderio.core.client.gui.widget.GhostSlot)1 IPoweredTask (crazypants.enderio.base.machine.interfaces.IPoweredTask)1 EnchanterRecipe (crazypants.enderio.base.recipe.enchanter.EnchanterRecipe)1 CapturedMob (crazypants.enderio.util.CapturedMob)1 List (java.util.List)1 Nullable (javax.annotation.Nullable)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 Slot (net.minecraft.inventory.Slot)1