Search in sources :

Example 1 with FarmableSapling

use of forestry.farming.logic.farmables.FarmableSapling in project ForestryMC by ForestryMC.

the class PluginNatura method registerItems.

@SubscribeEvent
public void registerItems(RegistryEvent<Item> itemRegistryEvent) {
    final ItemStack potashApple = findPotashAppleInRegistry();
    boolean hasMushroom = blueLargeGlowshroomBlock != null && greenLargeGlowshroomBlock != null && purpleLargeGlowshroomBlock != null;
    ForgeRegistries.ITEMS.forEach(item -> {
        final ResourceLocation registryName = item.getRegistryName();
        if (registryName == null || !registryName.getResourceDomain().equals(MOD_ID)) {
            return;
        }
        final String itemName = registryName.getResourcePath();
        if (itemName.matches("^.*_sapling\\d?$")) {
            consumeSubItems(item, "saplings", saplings);
            RecipeUtil.addFermenterRecipes(new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS);
            ItemStack[] windfall = new ItemStack[] {};
            // add potash apple as windfall for darkwood (nether_sapling:2)
            if (itemName.endsWith("nether_sapling")) {
                windfall = new ItemStack[] { potashApple };
            }
            FarmRegistry.getInstance().registerFarmables("farmArboreal", new FarmableSapling(new ItemStack(item), windfall));
            return;
        }
        if (hasMushroom && itemName.matches("^.*nether_glowshroom\\d?$")) {
            complexConsumeSubItems(item, "shrooms", subItem -> {
                shrooms.add(subItem);
                // find large shroom block that matches subItem
                final Block largeShroomBlock;
                if (subItem.getMetadata() == blueLargeGlowshroomBlock.damageDropped(blueLargeGlowshroomBlock.getDefaultState())) {
                    largeShroomBlock = blueLargeGlowshroomBlock;
                } else if (subItem.getMetadata() == greenLargeGlowshroomBlock.damageDropped(greenLargeGlowshroomBlock.getDefaultState())) {
                    largeShroomBlock = greenLargeGlowshroomBlock;
                } else {
                    largeShroomBlock = purpleLargeGlowshroomBlock;
                }
                // block representing planted glowshroom
                final Block smallShroomBlock = Block.getBlockFromItem(subItem.getItem());
                FarmRegistry.getInstance().registerFarmables("farmShroom", new FarmableVanillaMushroom(subItem, smallShroomBlock.getStateFromMeta(subItem.getMetadata()), largeShroomBlock));
            });
            return;
        }
        if (itemName.matches("^edibles|.*fruit_item|soups$")) {
            complexConsumeSubItems(item, "edibles", subitem -> {
                final String subItemName = subitem.getUnlocalizedName();
                if (subItemName.matches("^.*berry$")) {
                    berries.add(subitem);
                    return;
                }
                if (subItemName.matches("^.*(fruit_item|apple)$")) {
                    fruits.add(subitem);
                    return;
                }
                if (subItemName.matches("^.*stew$")) {
                    soups.add(subitem);
                    return;
                }
                edibles.add(subitem);
            });
        }
        if (itemName.matches("^.*_seeds$")) {
            consumeSubItems(item, "seeds", seeds);
            return;
        }
        if (itemName.matches("^.*_logs\\d?$")) {
            consumeSubItems(item, "logs", logs);
            return;
        }
        if (itemName.matches("^.*_crop\\d?$")) {
            consumeSubItems(item, "cropBlocks", cropBlocks);
            return;
        }
        if (itemName.matches("^materials$")) {
            complexConsumeSubItems(item, "materials", subitem -> {
                final String subItemName = subitem.getUnlocalizedName();
                if (subItemName.matches("^.*(barley|cotton)$")) {
                    crops.add(subitem);
                    return;
                }
                materials.add(subitem);
            });
        }
    });
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) FarmableSapling(forestry.farming.logic.farmables.FarmableSapling) FarmableVanillaMushroom(forestry.farming.logic.farmables.FarmableVanillaMushroom) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

FarmableSapling (forestry.farming.logic.farmables.FarmableSapling)1 FarmableVanillaMushroom (forestry.farming.logic.farmables.FarmableVanillaMushroom)1 Block (net.minecraft.block.Block)1 ItemStack (net.minecraft.item.ItemStack)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1