Search in sources :

Example 1 with NutRecipe

use of com.eerussianguy.firmalife.recipe.NutRecipe in project firmalife by eerussianguy.

the class CTNut method removeRecipe.

@ZenMethod
public static void removeRecipe(IItemStack output) {
    if (output == null)
        throw new IllegalArgumentException("Output not allowed to be empty");
    ArrayList<NutRecipe> removeList = new ArrayList<>();
    RegistriesFL.NUT_TREES.getValuesCollection().stream().filter(x -> x.getNut().isItemEqual(InputHelper.toStack(output))).forEach(removeList::add);
    for (NutRecipe recipe : removeList) {
        CraftTweakerAPI.apply(new IAction() {

            @Override
            public void apply() {
                IForgeRegistryModifiable<NutRecipe> NUT = (IForgeRegistryModifiable<NutRecipe>) RegistriesFL.NUT_TREES;
                NUT.remove(recipe.getRegistryName());
            }

            @Override
            public String describe() {
                return "Removing Drying recipe for output " + output.getDisplayName();
            }
        });
    }
}
Also used : DryingRecipe(com.eerussianguy.firmalife.recipe.DryingRecipe) NutRecipe(com.eerussianguy.firmalife.recipe.NutRecipe) IAction(crafttweaker.IAction) ZenClass(stanhebben.zenscript.annotations.ZenClass) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) CraftTweakerAPI(crafttweaker.CraftTweakerAPI) Block(net.minecraft.block.Block) IItemStack(crafttweaker.api.item.IItemStack) ResourceLocation(net.minecraft.util.ResourceLocation) ZenMethod(stanhebben.zenscript.annotations.ZenMethod) IForgeRegistryModifiable(net.minecraftforge.registries.IForgeRegistryModifiable) ItemBlock(net.minecraft.item.ItemBlock) InputHelper(com.blamejared.mtlib.helpers.InputHelper) RegistriesFL(com.eerussianguy.firmalife.init.RegistriesFL) ZenRegister(crafttweaker.annotations.ZenRegister) IForgeRegistryModifiable(net.minecraftforge.registries.IForgeRegistryModifiable) IAction(crafttweaker.IAction) ArrayList(java.util.ArrayList) NutRecipe(com.eerussianguy.firmalife.recipe.NutRecipe) ZenMethod(stanhebben.zenscript.annotations.ZenMethod)

Example 2 with NutRecipe

use of com.eerussianguy.firmalife.recipe.NutRecipe in project firmalife by eerussianguy.

the class DTRegistry method registerNutRecipes.

@Override
public void registerNutRecipes(IForgeRegistry<NutRecipe> r) {
    ModTrees.tfcTrees.forEach(tree -> {
        String treeName = tree.getName().getPath();
        BlockBranch log = tree.getDynamicBranch();
        Block leaves = ModBlocks.leafMap.get(treeName).getDynamicLeavesState().getBlock();
        if (treeName.contains("chestnut")) {
            r.register(new NutRecipe(log, leaves, new ItemStack(ItemsFL.getFood(FoodFL.CHESTNUTS))).setRegistryName("dt_chestnut"));
        } else if (treeName.contains("pine")) {
            r.register(new NutRecipe(log, leaves, new ItemStack(ItemsFL.getFood(FoodFL.PINE_NUTS))).setRegistryName("dt_pine"));
        } else if (treeName.contains("oak")) {
            r.register(new NutRecipe(log, leaves, new ItemStack(ItemsFL.getFood(FoodFL.ACORNS))).setRegistryName("dt_oak"));
        } else if (treeName.contains("hickory")) {
            r.register(new NutRecipe(log, leaves, new ItemStack(ItemsFL.getFood(FoodFL.PECAN_NUTS))).setRegistryName("dt_hickory"));
        } else if (treeName.contains("palm")) {
            r.register(new NutRecipe(log, leaves, new ItemStack(ItemsFL.getFood(FoodFL.COCONUT))).setRegistryName("dt_palm"));
        }
    });
}
Also used : Block(net.minecraft.block.Block) NutRecipe(com.eerussianguy.firmalife.recipe.NutRecipe) ItemStack(net.minecraft.item.ItemStack) BlockBranch(com.ferreusveritas.dynamictrees.blocks.BlockBranch)

Example 3 with NutRecipe

use of com.eerussianguy.firmalife.recipe.NutRecipe in project firmalife by eerussianguy.

the class ItemMetalMallet method onItemUse.

@Override
@Nonnull
@SuppressWarnings("deprecation")
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote && hand == EnumHand.MAIN_HAND) {
        Block block = worldIn.getBlockState(pos).getBlock();
        if (block instanceof BlockPlacedItemFlat) {
            TEPlacedItemFlat tile = (TEPlacedItemFlat) worldIn.getTileEntity(pos);
            if (tile == null)
                return EnumActionResult.FAIL;
            CrackingRecipe entry = CrackingRecipe.get(tile.getStack());
            if (entry == null)
                return EnumActionResult.FAIL;
            if (Constants.RNG.nextInt(100) < entry.getChance()) {
                InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), entry.getOutputItem(tile.getStack()));
                worldIn.playSound(null, pos, SoundEvents.BLOCK_WOOD_PLACE, SoundCategory.BLOCKS, 2.0F, 1.0F);
            } else
                worldIn.playSound(null, pos, SoundEvents.BLOCK_WOOD_FALL, SoundCategory.BLOCKS, 2.0F, 1.0F);
            tile.setStack(ItemStack.EMPTY);
            worldIn.setBlockToAir(pos);
            player.getHeldItem(hand).damageItem(1, player);
            return EnumActionResult.SUCCESS;
        } else if (block == BlocksFL.MELON_FRUIT) {
            List<ItemStack> drops = block.getDrops(worldIn, pos, worldIn.getBlockState(pos), 0);
            ItemStack stack = drops.get(0);
            if (stack.getItem() == Item.getItemFromBlock(block)) {
                IFood cap = stack.getCapability(CapabilityFood.CAPABILITY, null);
                if (cap != null) {
                    if (!cap.isRotten()) {
                        for (int i = 0; i < 2 + RNG.nextInt(4); i++) Helpers.spawnItemStack(worldIn, pos, new ItemStack(ItemsFL.getFood(FoodFL.MELON)));
                    }
                }
            }
            worldIn.destroyBlock(pos, false);
            worldIn.playSound(null, pos, SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.BLOCKS, 1.0f, 1.0f);
            return EnumActionResult.SUCCESS;
        }
        BlockPos offsetPos;
        BlockPos logPos = pos;
        IBlockState logState = worldIn.getBlockState(pos);
        Block logBlock = logState.getBlock();
        // grabbing the registry to verify you're clicking a nut tree
        NutRecipe entry = NutRecipe.get(logBlock);
        if (entry == null)
            return EnumActionResult.FAIL;
        int leafCount = 0;
        for (int i = 1; i < 14; i++) {
            logPos = pos.up(i);
            logState = worldIn.getBlockState(logPos);
            if (// we already verified that logBlock is correct
            logState.getBlock() != logBlock)
                break;
            for (// this is a crappy leaf counting algorithm
            EnumFacing d : // this is a crappy leaf counting algorithm
            EnumFacing.HORIZONTALS) {
                IBlockState leafState;
                for (int j = 1; j < 5; j++) {
                    offsetPos = logPos.offset(d, j);
                    leafState = worldIn.getBlockState(offsetPos);
                    if (// offset the thing if the trunk seems to curve
                    j == 1 && leafState.getBlock() == logBlock)
                        pos = pos.offset(d, j);
                    if (worldIn.isAirBlock(offsetPos))
                        continue;
                    if (leafState.getBlock() == entry.getLeaves())
                        leafCount++;
                }
            }
        }
        if (leafCount > 0) {
            Month month = CalendarTFC.CALENDAR_TIME.getMonthOfYear();
            if (!(month == Month.OCTOBER || month == Month.NOVEMBER)) {
                player.sendStatusMessage(new TextComponentTranslation("tooltip.firmalife.not_fall"), true);
                return EnumActionResult.PASS;
            }
            IPlayerDataFL playerData = player.getCapability(CapPlayerDataFL.CAPABILITY, null);
            if (playerData != null) {
                boolean timePassed = (int) CalendarTFC.CALENDAR_TIME.getTicks() - playerData.getNuttedTime() > ConfigFL.General.BALANCE.nutTime;
                boolean distanced = playerData.getNutDistance(pos) > ConfigFL.General.BALANCE.nutDistance;
                if (distanced && timePassed) {
                    playerData.setNuttedTime();
                    playerData.setNutPosition(pos);
                    leafCount = (int) Math.ceil(leafCount * 0.66);
                    while (// batches drops a few times
                    leafCount > 0) {
                        int dropCount = Math.min(Constants.RNG.nextInt(4) + 1, leafCount);
                        BlockPos dropPos = logPos.offset(EnumFacing.random(Constants.RNG), Constants.RNG.nextInt(3) + 1);
                        // should be querying nut
                        Helpers.spawnItemStack(worldIn, dropPos, new ItemStack(entry.getNut().getItem(), Constants.RNG.nextInt(dropCount)));
                        TFCParticles.LEAF1.sendToAllNear(worldIn, dropPos.getX() + RNG.nextFloat() / 10, dropPos.getY() - RNG.nextFloat() / 10, dropPos.getZ() + RNG.nextFloat() / 10, (RNG.nextFloat() - 0.5) / 10, -0.15D + RNG.nextFloat() / 10, (RNG.nextFloat() - 0.5) / 10, 90);
                        leafCount -= dropCount;
                    }
                    worldIn.playSound(null, pos, SoundEvents.BLOCK_WOOD_PLACE, SoundCategory.BLOCKS, 3.0F, 1.0F);
                    player.getHeldItem(hand).damageItem(1, player);
                    player.addPotionEffect(new PotionEffect(MobEffects.HUNGER, 200, 1));
                } else {
                    if (!timePassed) {
                        player.sendStatusMessage(new TextComponentTranslation("tooltip.firmalife.refractory"), true);
                    } else {
                        player.sendStatusMessage(new TextComponentTranslation("tooltip.firmalife.distance"), true);
                    }
                    player.addPotionEffect(new PotionEffect(MobEffects.MINING_FATIGUE, 200, 1));
                    player.addPotionEffect(new PotionEffect(PotionEffectsTFC.THIRST, 200, 0));
                }
                return EnumActionResult.SUCCESS;
            }
        }
    }
    return EnumActionResult.FAIL;
}
Also used : CrackingRecipe(com.eerussianguy.firmalife.recipe.CrackingRecipe) IFood(net.dries007.tfc.api.capability.food.IFood) IPlayerDataFL(com.eerussianguy.firmalife.player.IPlayerDataFL) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IBlockState(net.minecraft.block.state.IBlockState) PotionEffect(net.minecraft.potion.PotionEffect) Month(net.dries007.tfc.util.calendar.Month) TEPlacedItemFlat(net.dries007.tfc.objects.te.TEPlacedItemFlat) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) List(java.util.List) BlockPos(net.minecraft.util.math.BlockPos) NutRecipe(com.eerussianguy.firmalife.recipe.NutRecipe) BlockPlacedItemFlat(net.dries007.tfc.objects.blocks.BlockPlacedItemFlat) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 4 with NutRecipe

use of com.eerussianguy.firmalife.recipe.NutRecipe in project firmalife by eerussianguy.

the class CTNut method addRecipe.

@ZenMethod
public static void addRecipe(String recipe_name, IItemStack log, IItemStack leave, IItemStack output) {
    if (!(InputHelper.isABlock(log) && InputHelper.isABlock(leave)))
        throw new IllegalArgumentException("Input is not a block!");
    ItemStack log_stack = InputHelper.toStack(log);
    ItemStack leave_stack = InputHelper.toStack(leave);
    if (log_stack.getItem() instanceof ItemBlock && leave_stack.getItem() instanceof ItemBlock) {
        Block log_block = ((ItemBlock) log_stack.getItem()).getBlock();
        Block leave_block = ((ItemBlock) leave_stack.getItem()).getBlock();
        NutRecipe recipe = new NutRecipe(log_block, leave_block, InputHelper.toStack(output)).setRegistryName(recipe_name);
        CraftTweakerAPI.apply(new IAction() {

            @Override
            public void apply() {
                RegistriesFL.NUT_TREES.register(recipe);
            }

            @Override
            public String describe() {
                return "Adding Nut recipe " + recipe.getRegistryName().toString();
            }
        });
    }
}
Also used : IAction(crafttweaker.IAction) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) NutRecipe(com.eerussianguy.firmalife.recipe.NutRecipe) ItemStack(net.minecraft.item.ItemStack) IItemStack(crafttweaker.api.item.IItemStack) ItemBlock(net.minecraft.item.ItemBlock) ZenMethod(stanhebben.zenscript.annotations.ZenMethod)

Aggregations

NutRecipe (com.eerussianguy.firmalife.recipe.NutRecipe)4 Block (net.minecraft.block.Block)4 ItemStack (net.minecraft.item.ItemStack)4 ItemBlock (net.minecraft.item.ItemBlock)3 IAction (crafttweaker.IAction)2 IItemStack (crafttweaker.api.item.IItemStack)2 ZenMethod (stanhebben.zenscript.annotations.ZenMethod)2 InputHelper (com.blamejared.mtlib.helpers.InputHelper)1 RegistriesFL (com.eerussianguy.firmalife.init.RegistriesFL)1 IPlayerDataFL (com.eerussianguy.firmalife.player.IPlayerDataFL)1 CrackingRecipe (com.eerussianguy.firmalife.recipe.CrackingRecipe)1 DryingRecipe (com.eerussianguy.firmalife.recipe.DryingRecipe)1 BlockBranch (com.ferreusveritas.dynamictrees.blocks.BlockBranch)1 CraftTweakerAPI (crafttweaker.CraftTweakerAPI)1 ZenRegister (crafttweaker.annotations.ZenRegister)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Nonnull (javax.annotation.Nonnull)1 IFood (net.dries007.tfc.api.capability.food.IFood)1 BlockPlacedItemFlat (net.dries007.tfc.objects.blocks.BlockPlacedItemFlat)1