Search in sources :

Example 1 with IPoweredTask

use of crazypants.enderio.base.machine.interfaces.IPoweredTask in project EnderIO by SleepyTrousers.

the class HandlePoweredTask method read.

@Override
public IPoweredTask read(@Nonnull Registry registry, @Nonnull Set<NBTAction> phase, @Nonnull NBTTagCompound nbt, @Nullable Field field, @Nonnull String name, @Nullable IPoweredTask object) throws IllegalArgumentException, IllegalAccessException, InstantiationException, NoHandlerFoundException {
    if (nbt.hasKey(name)) {
        try {
            NBTTagCompound tag = (NBTTagCompound) nbt.getTag(name);
            String className = tag.getString("class");
            if (!className.isEmpty()) {
                Class<?> clazz = Class.forName(className);
                if (clazz != null) {
                    Method method = clazz.getDeclaredMethod("readFromNBT", NBTTagCompound.class);
                    if (method != null) {
                        Object object2 = method.invoke(null, tag);
                        if (object2 instanceof IPoweredTask) {
                            return (IPoweredTask) object2;
                        }
                    }
                }
            }
        } catch (ClassNotFoundException e) {
            throw new IllegalArgumentException(e);
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException(e);
        } catch (SecurityException e) {
            throw new IllegalArgumentException(e);
        } catch (InvocationTargetException e) {
            throw new IllegalArgumentException(e);
        }
    }
    return null;
}
Also used : IPoweredTask(crazypants.enderio.base.machine.interfaces.IPoweredTask) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with IPoweredTask

use of crazypants.enderio.base.machine.interfaces.IPoweredTask 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 3 with IPoweredTask

use of crazypants.enderio.base.machine.interfaces.IPoweredTask in project EnderIO by SleepyTrousers.

the class TilePoweredSpawner method createTask.

@Override
protected IPoweredTask createTask(@Nonnull IMachineRecipe nextRecipe, long nextSeed) {
    PoweredTask res = new PoweredTask(nextRecipe, nextSeed, getRecipeInputs());
    int ticksDelay;
    if (isSpawnMode) {
        ticksDelay = SpawnerConfig.poweredSpawnerMinDelayTicks.get() + (int) Math.round((SpawnerConfig.poweredSpawnerMaxDelayTicks.get() - SpawnerConfig.poweredSpawnerMinDelayTicks.get()) * Math.random());
    } else {
        ticksDelay = SpawnerConfig.poweredSpawnerMaxDelayTicks.get() - ((SpawnerConfig.poweredSpawnerMaxDelayTicks.get() - SpawnerConfig.poweredSpawnerMinDelayTicks.get()) / 2);
    }
    ticksDelay /= SPAWNER_SPEEDUP.getFloat(getCapacitorData());
    int powerPerTick = getPowerUsePerTick();
    res.setRequiredEnergy(powerPerTick * ticksDelay);
    return res;
}
Also used : PoweredTask(crazypants.enderio.base.machine.task.PoweredTask) IPoweredTask(crazypants.enderio.base.machine.interfaces.IPoweredTask)

Example 4 with IPoweredTask

use of crazypants.enderio.base.machine.interfaces.IPoweredTask in project EnderIO by SleepyTrousers.

the class TileSagMill method createTask.

@Override
protected IPoweredTask createTask(@Nonnull IMachineRecipe nextRecipe, long nextSeed) {
    PoweredTask res;
    if (grindingBall != null && nextRecipe.getBonusType(getRecipeInputs()).doChances()) {
        res = new PoweredTask(nextRecipe, nextSeed, grindingBall.getGrindingMultiplier(), grindingBall.getChanceMultiplier(), getRecipeInputs());
        res.setRequiredEnergy(res.getRequiredEnergy() * grindingBall.getPowerMultiplier());
    } else {
        res = new PoweredTask(nextRecipe, nextSeed, getRecipeInputs());
    }
    return res;
}
Also used : PoweredTask(crazypants.enderio.base.machine.task.PoweredTask) IPoweredTask(crazypants.enderio.base.machine.interfaces.IPoweredTask)

Example 5 with IPoweredTask

use of crazypants.enderio.base.machine.interfaces.IPoweredTask in project EnderIO by SleepyTrousers.

the class AbstractPoweredTaskEntity method canInsertResult.

protected boolean canInsertResult(long nextSeed, @Nonnull IMachineRecipe nextRecipe) {
    final IPoweredTask task = createTask(nextRecipe, nextSeed);
    if (task == null) {
        return false;
    }
    ResultStack[] nextResults = task.getCompletedResult();
    List<ItemStack> outputStacks = null;
    final int numOutputSlots = slotDefinition.getNumOutputSlots();
    if (numOutputSlots > 0) {
        outputStacks = new ArrayList<ItemStack>(numOutputSlots);
        boolean allFull = true;
        for (int i = slotDefinition.minOutputSlot; i <= slotDefinition.maxOutputSlot; i++) {
            ItemStack st = inventory[i];
            if (st != null && Prep.isValid(st)) {
                st = st.copy();
                if (allFull && st.getCount() < st.getMaxStackSize()) {
                    allFull = false;
                }
            } else {
                allFull = false;
            }
            outputStacks.add(st);
        }
        if (allFull) {
            return false;
        }
    }
    for (ResultStack result : nextResults) {
        if (Prep.isValid(result.item)) {
            if (outputStacks == null || mergeItemResult(result.item, outputStacks) == 0) {
                return false;
            }
        } else if (result.fluid != null) {
            if (!canInsertResultFluid(result)) {
                return false;
            }
        }
    }
    return true;
}
Also used : ResultStack(crazypants.enderio.base.recipe.IMachineRecipe.ResultStack) IPoweredTask(crazypants.enderio.base.machine.interfaces.IPoweredTask) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IPoweredTask (crazypants.enderio.base.machine.interfaces.IPoweredTask)6 PoweredTask (crazypants.enderio.base.machine.task.PoweredTask)2 IMachineRecipe (crazypants.enderio.base.recipe.IMachineRecipe)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NNList (com.enderio.core.common.util.NNList)1 ResultStack (crazypants.enderio.base.recipe.IMachineRecipe.ResultStack)1 MachineRecipeInput (crazypants.enderio.base.recipe.MachineRecipeInput)1 VanillaSmeltingRecipe (crazypants.enderio.base.recipe.alloysmelter.VanillaSmeltingRecipe)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Nullable (javax.annotation.Nullable)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagList (net.minecraft.nbt.NBTTagList)1