Search in sources :

Example 36 with NNList

use of com.enderio.core.common.util.NNList in project EnderIO by SleepyTrousers.

the class BlockPaintedStone method getDrops.

@Override
public void getDrops(@Nonnull NonNullList<ItemStack> drops, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull IBlockState state, int fortune) {
    NNList<ItemStack> drops2 = new NNList<>();
    super.getDrops(drops2, world, pos, state, fortune);
    for (ItemStack drop : drops2) {
        PaintUtil.setSourceBlock(NullHelper.notnullM(drop, "null stack from getDrops()"), getPaintSource(state, world, pos));
    }
    drops.addAll(drops2);
}
Also used : NNList(com.enderio.core.common.util.NNList) ItemStack(net.minecraft.item.ItemStack)

Example 37 with NNList

use of com.enderio.core.common.util.NNList in project EnderIO by SleepyTrousers.

the class DarkSteelUpgradeRecipeCategory method register.

public static void register(IModRegistry registry) {
    long start = System.nanoTime();
    registry.addRecipeCatalyst(new ItemStack(blockDarkSteelAnvil.getBlockNN()), VanillaRecipeCategoryUid.ANVIL);
    NNList<ItemStack> blacklist = new NNList<>();
    for (UpgradePath rec : allRecipes) {
        rec.getOutput().getItem().getSubItems(getCreativeTab(rec), blacklist);
    }
    NNList<ItemStack> seen = new NNList<>();
    for (UpgradePath rec : allRecipes) {
        if (!inList(blacklist, rec.getOutput()) && !inList(seen, rec.getOutput())) {
            seen.add(rec.getOutput());
        }
    }
    int enchantmentRecipes = registerBookEnchantmentRecipes(registry, seen);
    final IVanillaRecipeFactory factory = registry.getJeiHelpers().getVanillaRecipeFactory();
    Collection<IRecipeWrapper> anvilRecipes = NullHelper.notnullJ(allRecipes.stream().map(rec -> factory.createAnvilRecipe(rec.getInput(), Collections.singletonList(rec.getUpgrade()), Collections.singletonList(rec.getOutput()))).collect(Collectors.toList()), "Stream#collect");
    registry.addRecipes(anvilRecipes, VanillaRecipeCategoryUid.ANVIL);
    Log.info(String.format("DarkSteelUpgradeRecipeCategory: Added %d dark steel upgrade recipes and %d enchantment recipes for upgradable items to JEI in %.3f seconds.", allRecipes.size(), enchantmentRecipes, (System.nanoTime() - start) / 1000000000d));
}
Also used : UpgradePath(crazypants.enderio.base.handler.darksteel.DarkSteelRecipeManager.UpgradePath) NNList(com.enderio.core.common.util.NNList) IRecipeWrapper(mezz.jei.api.recipe.IRecipeWrapper) ItemStack(net.minecraft.item.ItemStack) IVanillaRecipeFactory(mezz.jei.api.recipe.IVanillaRecipeFactory)

Example 38 with NNList

use of com.enderio.core.common.util.NNList in project EnderIO by SleepyTrousers.

the class DarkSteelUpgradeSubtypeInterpreter method apply.

@Override
@Nonnull
public String apply(ItemStack itemStack) {
    if (itemStack == null) {
        throw new NullPointerException("You want me to return something Nonnull for a null ItemStack? F.U.");
    }
    String result = DarkSteelRecipeManager.getUpgradesAsString(itemStack);
    Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(itemStack);
    final List<Enchantment> keyList = new NNList<>(enchantments.keySet());
    keyList.sort(new Comparator<Enchantment>() {

        @Override
        public int compare(Enchantment o1, Enchantment o2) {
            return safeString(o1).compareTo(safeString(o2));
        }
    });
    for (Enchantment enchantment : keyList) {
        result += "/" + safeString(enchantment);
    }
    return "DS:" + result;
}
Also used : NNList(com.enderio.core.common.util.NNList) Enchantment(net.minecraft.enchantment.Enchantment) Nonnull(javax.annotation.Nonnull)

Example 39 with NNList

use of com.enderio.core.common.util.NNList in project EnderIO by SleepyTrousers.

the class SoulBinderRecipeManager method addRecipeFromNBT.

// @formatter:off
/**
 * Example of how to add a recipe:
 *
 * <pre> NBTTagCompound root = new NBTTagCompound();
 * root.setString(SoulBinderRecipeManager.KEY_RECIPE_UID, "diamondToWood");
 * root.setInteger(SoulBinderRecipeManager.KEY_REQUIRED_ENERGY, 50000);
 * root.setInteger(SoulBinderRecipeManager.KEY_REQUIRED_XP, 7);
 * root.setString(SoulBinderRecipeManager.KEY_SOUL_TYPES, "minecraft:zombie|specialmobs:specialzombie|minecraft:villager");
 * ItemStack is = new ItemStack(Items.diamond);
 * NBTTagCompound stackRoot = new NBTTagCompound();
 * is.writeToNBT(stackRoot);
 * root.setTag(SoulBinderRecipeManager.KEY_INPUT_STACK, stackRoot);
 * is = new ItemStack(Blocks.planks);
 * stackRoot = new NBTTagCompound();
 * is.writeToNBT(stackRoot);
 * root.setTag(SoulBinderRecipeManager.KEY_OUTPUT_STACK, stackRoot);
 *
 * SoulBinderRecipeManager.getInstance().addRecipeFromNBT(root);
 * FMLInterModComms.sendMessage("EnderIO",  "recipe:soulbinder", root);</pre>
 *
 * @param root
 * @return
 */
// @formatter:on
public boolean addRecipeFromNBT(@Nonnull NBTTagCompound root) {
    try {
        String recipeUid = root.getString(KEY_RECIPE_UID);
        if (recipeUid.trim().length() == 0) {
            Log.error("SoulBinderRecipeManager: Could not add custom soul binder recipe from IMC as recipe UID not set: " + root);
            return false;
        }
        ItemStack inputStack = getStackFromRoot(root, KEY_INPUT_STACK);
        if (Prep.isInvalid(inputStack)) {
            Log.error("SoulBinderRecipeManager: Could not add custom soul binder recipe from IMC as no input stack defined: " + root);
            return false;
        }
        ItemStack outputStack = getStackFromRoot(root, KEY_OUTPUT_STACK);
        if (Prep.isInvalid(outputStack)) {
            Log.error("SoulBinderRecipeManager: Could not add custom soul binder recipe from IMC as no output stack defined: " + root);
            return false;
        }
        int energyRequired = root.getInteger(KEY_REQUIRED_ENERGY);
        if (energyRequired <= 0) {
            Log.error("SoulBinderRecipeManager: Could not add custom soul binder recipe from IMC as energy required was <= 0: " + root);
            return false;
        }
        int xpLevelsRequired = root.getInteger(KEY_REQUIRED_XP);
        if (xpLevelsRequired <= 0) {
            Log.error("SoulBinderRecipeManager: Could not add custom soul binder recipe from IMC as XP required was <= 0: " + root);
            return false;
        }
        String str = root.getString(KEY_SOUL_TYPES);
        if (str.trim().length() == 0) {
            Log.error("SoulBinderRecipeManager: Could not add custom soul binder recipe from IMC as no soul types defined: " + root);
            return false;
        }
        String[] entityNames = str.split("\\|");
        NNList<ResourceLocation> entityRLs = new NNList<>();
        for (String string : entityNames) {
            if (string == null || string.trim().isEmpty()) {
                Log.error("SoulBinderRecipeManager: Could not add custom soul binder recipe from IMC as no soul types contains emtpty entry: " + root);
                return false;
            }
            entityRLs.add(new ResourceLocation(string));
        }
        if (entityRLs.isEmpty()) {
            Log.error("SoulBinderRecipeManager: Could not add custom soul binder recipe from IMC as no soul types defined: " + root);
            return false;
        }
        BasicSoulBinderRecipe recipe = new BasicSoulBinderRecipe(inputStack, outputStack, energyRequired, xpLevelsRequired, recipeUid, entityRLs.toArray(new ResourceLocation[0]));
        MachineRecipeRegistry.instance.registerRecipe(MachineRecipeRegistry.SOULBINDER, recipe);
        return true;
    } catch (Exception e) {
        Log.error("SoulBinderRecipeManager: Could not add custom soul binder exception thrown when parsing message: " + e);
        return false;
    }
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) NNList(com.enderio.core.common.util.NNList) ItemStack(net.minecraft.item.ItemStack)

Example 40 with NNList

use of com.enderio.core.common.util.NNList in project EnderIO by SleepyTrousers.

the class FarmLogic method endUsingItem.

@Override
@Nonnull
public NNList<ItemStack> endUsingItem(boolean trashHandItem) {
    NNList<ItemStack> result = new NNList<>();
    for (int i = 0; i < farmerJoe.inventory.getSizeInventory(); i++) {
        ItemStack stack = farmerJoe.inventory.removeStackFromSlot(i);
        if (Prep.isValid(stack)) {
            result.add(stack);
        }
    }
    joeInUse = false;
    return result;
}
Also used : NNList(com.enderio.core.common.util.NNList) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

NNList (com.enderio.core.common.util.NNList)53 ItemStack (net.minecraft.item.ItemStack)37 Nonnull (javax.annotation.Nonnull)12 BlockPos (net.minecraft.util.math.BlockPos)8 EntityItem (net.minecraft.entity.item.EntityItem)7 MachineRecipeInput (crazypants.enderio.base.recipe.MachineRecipeInput)5 Block (net.minecraft.block.Block)5 IBlockState (net.minecraft.block.state.IBlockState)5 IHarvestResult (crazypants.enderio.api.farm.IHarvestResult)4 ArrayList (java.util.ArrayList)4 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 GhostBackgroundItemSlot (com.enderio.core.client.gui.widget.GhostBackgroundItemSlot)3 Recipe (crazypants.enderio.base.recipe.Recipe)3 RecipeOutput (crazypants.enderio.base.recipe.RecipeOutput)3 ThingsRecipeInput (crazypants.enderio.base.recipe.ThingsRecipeInput)3 World (net.minecraft.world.World)3 Triple (org.apache.commons.lang3.tuple.Triple)3 IConduitBundle (crazypants.enderio.base.conduit.IConduitBundle)2 RaytraceResult (crazypants.enderio.base.conduit.RaytraceResult)2 IMachineRecipe (crazypants.enderio.base.recipe.IMachineRecipe)2