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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations