use of me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe in project FluffyMachines by NCBPFluffyBear.
the class ElectricDustRecycler method getDisplayRecipes.
@Nonnull
@Override
public List<ItemStack> getDisplayRecipes() {
List<ItemStack> displayRecipes = new ArrayList<>(recipes.size() * 2);
for (MachineRecipe recipe : recipes) {
displayRecipes.add(recipe.getInput()[0]);
displayRecipes.add(recipe.getOutput()[recipe.getOutput().length - 1]);
}
return displayRecipes;
}
use of me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe in project Slimefun4 by Slimefun.
the class OilPump method findNextRecipe.
@Override
protected MachineRecipe findNextRecipe(BlockMenu inv) {
if (inv.fits(SlimefunItems.OIL_BUCKET, getOutputSlots())) {
Block b = inv.getBlock();
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), emptyBucket, true, false)) {
OptionalInt supplies = Slimefun.getGPSNetwork().getResourceManager().getSupplies(oil, b.getWorld(), b.getX() >> 4, b.getZ() >> 4);
if (supplies.isPresent() && supplies.getAsInt() > 0) {
MachineRecipe recipe = new MachineRecipe(26, new ItemStack[] { emptyBucket }, new ItemStack[] { SlimefunItems.OIL_BUCKET });
inv.consumeItem(slot);
Slimefun.getGPSNetwork().getResourceManager().setSupplies(oil, b.getWorld(), b.getX() >> 4, b.getZ() >> 4, supplies.getAsInt() - 1);
return recipe;
} else {
/*
* Move the empty bucket to the output slot to prevent this
* from immediately starting all over again (to prevent lag)
*/
ItemStack item = inv.getItemInSlot(slot).clone();
inv.replaceExistingItem(slot, null);
inv.pushItem(item, getOutputSlots());
return null;
}
}
}
}
return null;
}
use of me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe in project Slimefun4 by Slimefun.
the class AutoEnchanter method enchant.
@Nullable
@ParametersAreNonnullByDefault
protected MachineRecipe enchant(BlockMenu menu, ItemStack target, ItemStack enchantedBook) {
// Call an event so other Plugins can modify it.
AsyncAutoEnchanterProcessEvent event = new AsyncAutoEnchanterProcessEvent(target, enchantedBook, menu);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return null;
}
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) enchantedBook.getItemMeta();
Map<Enchantment, Integer> enchantments = new HashMap<>();
// Find applicable enchantments
for (Map.Entry<Enchantment, Integer> entry : meta.getStoredEnchants().entrySet()) {
if (entry.getKey().canEnchantItem(target)) {
if (isEnchantmentLevelAllowed(entry.getValue())) {
enchantments.put(entry.getKey(), entry.getValue());
} else if (!menu.toInventory().getViewers().isEmpty()) {
showEnchantmentLevelWarning(menu);
return null;
}
}
}
/*
* If override is false, remove those with lower level so we don't override existing enchants
* This also removes those with the same level so they aren't accounted for enchanting time
*/
if (!overrideExistingEnchantsLvl.getValue()) {
enchantments.entrySet().removeIf(e -> target.getEnchantmentLevel(e.getKey()) >= e.getValue());
}
// Check if we found any valid enchantments
if (!enchantments.isEmpty()) {
ItemStack enchantedItem = target.clone();
enchantedItem.setAmount(1);
enchantedItem.addUnsafeEnchantments(enchantments);
MachineRecipe recipe = new MachineRecipe(75 * enchantments.size() / getSpeed(), new ItemStack[] { target, enchantedBook }, new ItemStack[] { enchantedItem, new ItemStack(Material.BOOK) });
if (!InvUtils.fitAll(menu.toInventory(), recipe.getOutput(), getOutputSlots())) {
return null;
}
for (int inputSlot : getInputSlots()) {
menu.consumeItem(inputSlot);
}
return recipe;
} else {
return null;
}
}
use of me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe in project Slimefun4 by Slimefun.
the class AutoBrewer method findNextRecipe.
@Override
@Nullable
protected MachineRecipe findNextRecipe(BlockMenu menu) {
ItemStack input1 = menu.getItemInSlot(getInputSlots()[0]);
ItemStack input2 = menu.getItemInSlot(getInputSlots()[1]);
if (input1 == null || input2 == null) {
return null;
}
if (isPotion(input1.getType()) || isPotion(input2.getType())) {
boolean isPotionInFirstSlot = isPotion(input1.getType());
ItemStack ingredient = isPotionInFirstSlot ? input2 : input1;
// Reject any named items
if (ingredient.hasItemMeta()) {
return null;
}
ItemStack potionItem = isPotionInFirstSlot ? input1 : input2;
PotionMeta potion = (PotionMeta) potionItem.getItemMeta();
ItemStack output = brew(ingredient.getType(), potionItem.getType(), potion);
if (output == null) {
return null;
}
output.setItemMeta(potion);
if (!InvUtils.fits(menu.toInventory(), output, getOutputSlots())) {
return null;
}
for (int slot : getInputSlots()) {
menu.consumeItem(slot);
}
return new MachineRecipe(30, new ItemStack[] { input1, input2 }, new ItemStack[] { output });
} else {
return null;
}
}
use of me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe in project Slimefun4 by Slimefun.
the class Freezer method getDisplayRecipes.
@Override
public List<ItemStack> getDisplayRecipes() {
List<ItemStack> displayRecipes = new ArrayList<>(recipes.size() * 2);
for (MachineRecipe recipe : recipes) {
displayRecipes.add(recipe.getInput()[0]);
displayRecipes.add(recipe.getOutput()[recipe.getOutput().length - 1]);
}
return displayRecipes;
}
Aggregations