use of crazypants.enderio.base.recipe.IMachineRecipe 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.recipe.IMachineRecipe in project EnderIO by SleepyTrousers.
the class AbstractPoweredTaskEntity method processTasks.
@Override
protected boolean processTasks(boolean redstoneChecksPassed) {
if (!redstoneChecksPassed) {
return false;
}
boolean requiresClientSync = false;
// Process any current items
requiresClientSync |= checkProgress(redstoneChecksPassed);
if (currentTask != null || !hasPower() || !hasInputStacks()) {
return requiresClientSync;
}
if (startFailed) {
ticksSinceCheckedRecipe++;
if (ticksSinceCheckedRecipe < 20) {
return false;
}
}
ticksSinceCheckedRecipe = 0;
// If a recipe could not be started we will try with the same chance next time
if (theNextSeed == null) {
theNextSeed = random.nextLong();
}
// Then see if we need to start a new one
IMachineRecipe nextRecipe = canStartNextTask(theNextSeed);
if (nextRecipe != null) {
boolean started = startNextTask(nextRecipe, theNextSeed);
if (started) {
// this chance value has been used up
theNextSeed = null;
}
startFailed = !started;
} else {
startFailed = true;
}
return requiresClientSync;
}
use of crazypants.enderio.base.recipe.IMachineRecipe in project EnderIO by SleepyTrousers.
the class TileSoulBinder method isMachineItemValidForSlot.
@Override
public boolean isMachineItemValidForSlot(int slot, @Nonnull ItemStack item) {
if (!slotDefinition.isInputSlot(slot)) {
return false;
}
MachineRecipeInput newInput = new MachineRecipeInput(slot, item);
int otherSlot = slot == 0 ? 1 : 0;
if (Prep.isInvalid(getStackInSlot(otherSlot))) {
List<IMachineRecipe> recipes = MachineRecipeRegistry.instance.getRecipesForInput(getMachineName(), newInput);
if (recipes.isEmpty()) {
return false;
}
for (IMachineRecipe rec : recipes) {
if (rec != null && rec.isValidInput(newInput)) {
return true;
}
}
} else {
NNList<MachineRecipeInput> inputs = new NNList<>(newInput, new MachineRecipeInput(otherSlot, getStackInSlot(otherSlot)));
return MachineRecipeRegistry.instance.getRecipeForInputs(getMachineName(), inputs) != null;
}
return false;
}
use of crazypants.enderio.base.recipe.IMachineRecipe in project EnderIO by SleepyTrousers.
the class TileSliceAndSplice method isMachineItemValidForSlot.
@Override
public boolean isMachineItemValidForSlot(int slot, @Nonnull ItemStack itemstack) {
if (Prep.isInvalid(itemstack)) {
return false;
}
if (!slotDefinition.isInputSlot(slot)) {
return false;
}
if (slot == axeIndex) {
return FarmingTool.AXE.itemMatches(itemstack);
}
if (slot == shearsIndex) {
return FarmingTool.SHEARS.itemMatches(itemstack);
}
ItemStack currentStackInSlot = getStackInSlot(slot);
if (Prep.isValid(currentStackInSlot)) {
return currentStackInSlot.isItemEqual(itemstack);
}
int numSlotsFilled = 0;
for (int i = slotDefinition.getMinInputSlot(); i <= slotDefinition.getMaxInputSlot(); i++) {
if (i >= 0 && i < inventory.length && i != axeIndex && i != shearsIndex) {
if (Prep.isValid(getStackInSlot(i))) {
numSlotsFilled++;
}
}
}
List<IMachineRecipe> recipes = MachineRecipeRegistry.instance.getRecipesForInput(getMachineName(), MachineRecipeInput.create(slot, itemstack));
return isValidInputForAlloyRecipe(slot, itemstack, numSlotsFilled, recipes);
}
use of crazypants.enderio.base.recipe.IMachineRecipe in project EnderIO by SleepyTrousers.
the class PainterRecipeCategory method splitRecipes.
// ------------ Recipes
@SuppressWarnings("null")
@Nonnull
private static List<PainterRecipeWrapper> splitRecipes(@Nonnull Collection<IMachineRecipe> recipes, List<ItemStack> validItems) {
long start = System.nanoTime();
List<AbstractPainterTemplate<?>> basicPainterTemplates = new ArrayList<AbstractPainterTemplate<?>>();
for (IMachineRecipe recipe : recipes) {
if (recipe instanceof AbstractPainterTemplate<?>) {
basicPainterTemplates.add((AbstractPainterTemplate<?>) recipe);
}
}
List<PainterRecipeWrapper> recipesWrappers = new ArrayList<PainterRecipeWrapper>();
for (ItemStack target : validItems) {
for (AbstractPainterTemplate<?> basicPainterTemplate : basicPainterTemplates) {
if (basicPainterTemplate.isValidTarget(target)) {
recipesWrappers.add(new PainterRecipeWrapper(basicPainterTemplate, target, new ArrayList<ItemStack>(), new ArrayList<ItemStack>()));
}
}
}
List<ItemStack> paints = ClientConfig.jeiUseShortenedPainterRecipes.get() ? getLimitedItems(validItems) : validItems;
int count = 0;
for (ItemStack paint : paints) {
try {
for (PainterRecipeWrapper painterRecipeWrapper : recipesWrappers) {
if (painterRecipeWrapper.recipe.isRecipe(paint, painterRecipeWrapper.target)) {
for (ResultStack result : painterRecipeWrapper.recipe.getCompletedResult(paint, painterRecipeWrapper.target)) {
painterRecipeWrapper.results.add(result.item);
painterRecipeWrapper.paints.add(paint);
count++;
}
}
}
} catch (Exception e) {
Log.warn("PainterRecipeCategory: Error while accessing item '" + paint + "': " + e);
e.printStackTrace();
}
}
long end = System.nanoTime();
for (PainterRecipeWrapper painterRecipeWrapper : recipesWrappers) {
if (painterRecipeWrapper.results.isEmpty()) {
Log.warn("PainterRecipeCategory: Empty recipe group: " + painterRecipeWrapper.recipe + " for " + painterRecipeWrapper.target);
}
}
Log.info(String.format("PainterRecipeCategory: Added %d painter recipes in %d groups to JEI in %.3f seconds.", count, recipesWrappers.size(), (end - start) / 1000000000d));
return recipesWrappers;
}
Aggregations