<commit_before>package com.InfinityRaider.AgriCraft.blocks;

import com.InfinityRaider.AgriCraft.AgriCraft;
import com.InfinityRaider.AgriCraft.compatibility.ModIntegration;
import com.InfinityRaider.AgriCraft.compatibility.applecore.AppleCoreHelper;
import com.InfinityRaider.AgriCraft.farming.GrowthRequirements;
import com.InfinityRaider.AgriCraft.handler.ConfigurationHandler;
import com.InfinityRaider.AgriCraft.init.Items;
import com.InfinityRaider.AgriCraft.items.ItemDebugger;
import com.InfinityRaider.AgriCraft.reference.Constants;
import com.InfinityRaider.AgriCraft.reference.Names;
import com.InfinityRaider.AgriCraft.tileentity.TileEntityCrop;
import com.InfinityRaider.AgriCraft.utility.SeedHelper;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.common.eventhandler.Event;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.IGrowable;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import tconstruct.items.tools.Scythe;
import tconstruct.library.tools.AbilityHelper;
import vazkii.botania.api.item.IGrassHornExcempt;

import java.util.ArrayList;
import java.util.Random;

@Optional.Interface(modid = Names.Mods.botania, iface = "vazkii.botania.api.item.IGrassHornExcempt")
public class BlockCrop extends BlockModPlant implements ITileEntityProvider, IGrowable, IGrassHornExcempt {

    @SideOnly(Side.CLIENT)
    private IIcon[] weedIcons;

    public BlockCrop() {
        super(Blocks.farmland, null, null, 0, 0, 6);
        this.isBlockContainer = true;
        //set the bounding box dimensions
        this.maxX = Constants.unit*14;
        this.minX = Constants.unit*2;
        this.maxZ = this.maxX;
        this.minZ = this.minX;
        this.maxY = Constants.unit*13;
        this.minY = 0;
    }

    //this makes a new tile entity every time you place the block
    @Override
    public TileEntity createNewTileEntity(World world, int meta) {
        return new TileEntityCrop();
    }

    //this makes the plant grow
    @Override
    public void updateTick(World world, int x, int y, int z, Random rnd) {
        TileEntityCrop crop = (TileEntityCrop) world.getTileEntity(x, y, z);
        if(crop.hasPlant()) {
            Event.Result allowGrowthResult = AppleCoreHelper.validateGrowthTick(this, world, x, y, z, rnd);
            if (allowGrowthResult != Event.Result.DENY) {
                int meta = this.getPlantMetadata(world, x, y, z);
                if (meta < 7 && crop.isFertile()) {
                    double multiplier = 1.0 + (crop.growth + 0.00) / 10;
                    float growthRate = (float) SeedHelper.getBaseGrowth(crop.seed, crop.seedMeta);
                    boolean shouldGrow = (rnd.nextDouble()<=(growthRate * multiplier)/100);
                    if (shouldGrow) {
                        meta++;
                        world.setBlockMetadataWithNotify(x, y, z, meta, 2);
                        AppleCoreHelper.announceGrowthTick(this, world, x, y, z);
                    }
                }
            }
        } else if(crop.weed) {
            Event.Result allowGrowthResult = AppleCoreHelper.validateGrowthTick(this, world, x, y, z, rnd);
            if (allowGrowthResult != Event.Result.DENY) {
                int meta = this.getPlantMetadata(world, x, y, z);
                if (meta<7) {
                    double multiplier = 1.0 + (10 + 0.00) / 10;
                    float growthRate = (float) Constants.growthTier1;
                    boolean shouldGrow = (rnd.nextDouble()<=(growthRate * multiplier)/100);
                    if (shouldGrow) {
                        meta++;
                        world.setBlockMetadataWithNotify(x, y, z, meta, 2);
                        AppleCoreHelper.announceGrowthTick(this, world, x, y, z);
                    }
                }
                else {
                    if(ConfigurationHandler.enableWeeds) {
                        crop.spreadWeed();
                    }
                }
            }
        } else {
            //10%chance to spawn weeds
            if(ConfigurationHandler.enableWeeds && Math.random()<0.10) {
                crop.spawnWeed();
            }
            else if(crop.crossCrop) {
                crop.crossOver();
            }
        }
    }

    //this harvests the crop
    public boolean harvest(World world, int x, int y, int z) {
        if(!world.isRemote) {
            boolean update = false;
            TileEntityCrop crop = (TileEntityCrop) world.getTileEntity(x, y, z);
            if(crop.weed) {
                crop.clearWeed();   //update is not needed because it is called in the clearWeed() method
            }else if(crop.crossCrop) {
                crop.crossCrop = false;
                this.dropBlockAsItem(world, x, y, z, new ItemStack(Items.crops, 1));
                update = true;
            } else if(crop.isMature()) {
                crop.getWorldObj().setBlockMetadataWithNotify(crop.xCoord, crop.yCoord, crop.zCoord, 2, 2);
                update = true;
                ArrayList<ItemStack> drops = SeedHelper.getPlantFruits(crop.seed, world, x, y, z, crop.gain, crop.seedMeta);
                for (ItemStack drop : drops) {
                    this.dropBlockAsItem(world, x, y, z, drop);
                }
            }
            if (update) {
                crop.markForUpdate();
            }
            return update;
        }
        return false;
    }

    public void setCrossCrop(World world, int x, int y, int z, EntityPlayer player) {
        if(!world.isRemote) {
            boolean update = false;
            TileEntityCrop crop = (TileEntityCrop) world.getTileEntity(x, y, z);
            if (crop.weed) {
                return;
            }

            if(!crop.crossCrop && !crop.hasPlant()) {
                crop.crossCrop=true;
                player.getCurrentEquippedItem().stackSize = player.capabilities.isCreativeMode?player.getCurrentEquippedItem().stackSize:player.getCurrentEquippedItem().stackSize - 1;
                update = true;
            }
            else {
                this.harvest(world, x, y, z);
            }
            if (update) {
                crop.markForUpdate();
            }
        }
    }

    public void plantSeed(World world, int x, int y, int z, EntityPlayer player) {
        if(!world.isRemote) {
            TileEntityCrop crop = (TileEntityCrop) world.getTileEntity(x, y, z);
            //is the cropEmpty a crosscrop or does it already have a plant
            if (crop.crossCrop || crop.hasPlant() || !(player.getCurrentEquippedItem().getItem() instanceof ItemSeeds)) {
                return;
            }
            //the seed can be planted here
            else {
                ItemStack stack = player.getCurrentEquippedItem();
                if (!SeedHelper.isValidSeed((ItemSeeds) stack.getItem(), stack.getItemDamage()) || !GrowthRequirements.getGrowthRequirement((ItemSeeds) stack.getItem(), stack.getItemDamage()).canGrow(world, x, y, z)) {
                    return;
                }
                //get NBT data from the seeds<commit_msg>Planting seeds only requires the correct soils instead of all the growth requirements [cf push]<commit_after>package com.InfinityRaider.AgriCraft.blocks;

import com.InfinityRaider.AgriCraft.AgriCraft;
import com.InfinityRaider.AgriCraft.compatibility.ModIntegration;
import com.InfinityRaider.AgriCraft.compatibility.applecore.AppleCoreHelper;
import com.InfinityRaider.AgriCraft.farming.GrowthRequirements;
import com.InfinityRaider.AgriCraft.handler.ConfigurationHandler;
import com.InfinityRaider.AgriCraft.init.Items;
import com.InfinityRaider.AgriCraft.items.ItemDebugger;
import com.InfinityRaider.AgriCraft.reference.Constants;
import com.InfinityRaider.AgriCraft.reference.Names;
import com.InfinityRaider.AgriCraft.tileentity.TileEntityCrop;
import com.InfinityRaider.AgriCraft.utility.SeedHelper;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.common.eventhandler.Event;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.IGrowable;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import tconstruct.items.tools.Scythe;
import tconstruct.library.tools.AbilityHelper;
import vazkii.botania.api.item.IGrassHornExcempt;

import java.util.ArrayList;
import java.util.Random;

@Optional.Interface(modid = Names.Mods.botania, iface = "vazkii.botania.api.item.IGrassHornExcempt")
public class BlockCrop extends BlockModPlant implements ITileEntityProvider, IGrowable, IGrassHornExcempt {

    @SideOnly(Side.CLIENT)
    private IIcon[] weedIcons;

    public BlockCrop() {
        super(Blocks.farmland, null, null, 0, 0, 6);
        this.isBlockContainer = true;
        //set the bounding box dimensions
        this.maxX = Constants.unit*14;
        this.minX = Constants.unit*2;
        this.maxZ = this.maxX;
        this.minZ = this.minX;
        this.maxY = Constants.unit*13;
        this.minY = 0;
    }

    //this makes a new tile entity every time you place the block
    @Override
    public TileEntity createNewTileEntity(World world, int meta) {
        return new TileEntityCrop();
    }

    //this makes the plant grow
    @Override
    public void updateTick(World world, int x, int y, int z, Random rnd) {
        TileEntityCrop crop = (TileEntityCrop) world.getTileEntity(x, y, z);
        if(crop.hasPlant()) {
            Event.Result allowGrowthResult = AppleCoreHelper.validateGrowthTick(this, world, x, y, z, rnd);
            if (allowGrowthResult != Event.Result.DENY) {
                int meta = this.getPlantMetadata(world, x, y, z);
                if (meta < 7 && crop.isFertile()) {
                    double multiplier = 1.0 + (crop.growth + 0.00) / 10;
                    float growthRate = (float) SeedHelper.getBaseGrowth(crop.seed, crop.seedMeta);
                    boolean shouldGrow = (rnd.nextDouble()<=(growthRate * multiplier)/100);
                    if (shouldGrow) {
                        meta++;
                        world.setBlockMetadataWithNotify(x, y, z, meta, 2);
                        AppleCoreHelper.announceGrowthTick(this, world, x, y, z);
                    }
                }
            }
        } else if(crop.weed) {
            Event.Result allowGrowthResult = AppleCoreHelper.validateGrowthTick(this, world, x, y, z, rnd);
            if (allowGrowthResult != Event.Result.DENY) {
                int meta = this.getPlantMetadata(world, x, y, z);
                if (meta<7) {
                    double multiplier = 1.0 + (10 + 0.00) / 10;
                    float growthRate = (float) Constants.growthTier1;
                    boolean shouldGrow = (rnd.nextDouble()<=(growthRate * multiplier)/100);
                    if (shouldGrow) {
                        meta++;
                        world.setBlockMetadataWithNotify(x, y, z, meta, 2);
                        AppleCoreHelper.announceGrowthTick(this, world, x, y, z);
                    }
                }
                else {
                    if(ConfigurationHandler.enableWeeds) {
                        crop.spreadWeed();
                    }
                }
            }
        } else {
            //10%chance to spawn weeds
            if(ConfigurationHandler.enableWeeds && Math.random()<0.10) {
                crop.spawnWeed();
            }
            else if(crop.crossCrop) {
                crop.crossOver();
            }
        }
    }

    //this harvests the crop
    public boolean harvest(World world, int x, int y, int z) {
        if(!world.isRemote) {
            boolean update = false;
            TileEntityCrop crop = (TileEntityCrop) world.getTileEntity(x, y, z);
            if(crop.weed) {
                crop.clearWeed();   //update is not needed because it is called in the clearWeed() method
            }else if(crop.crossCrop) {
                crop.crossCrop = false;
                this.dropBlockAsItem(world, x, y, z, new ItemStack(Items.crops, 1));
                update = true;
            } else if(crop.isMature()) {
                crop.getWorldObj().setBlockMetadataWithNotify(crop.xCoord, crop.yCoord, crop.zCoord, 2, 2);
                update = true;
                ArrayList<ItemStack> drops = SeedHelper.getPlantFruits(crop.seed, world, x, y, z, crop.gain, crop.seedMeta);
                for (ItemStack drop : drops) {
                    this.dropBlockAsItem(world, x, y, z, drop);
                }
            }
            if (update) {
                crop.markForUpdate();
            }
            return update;
        }
        return false;
    }

    public void setCrossCrop(World world, int x, int y, int z, EntityPlayer player) {
        if(!world.isRemote) {
            boolean update = false;
            TileEntityCrop crop = (TileEntityCrop) world.getTileEntity(x, y, z);
            if (crop.weed) {
                return;
            }

            if(!crop.crossCrop && !crop.hasPlant()) {
                crop.crossCrop=true;
                player.getCurrentEquippedItem().stackSize = player.capabilities.isCreativeMode?player.getCurrentEquippedItem().stackSize:player.getCurrentEquippedItem().stackSize - 1;
                update = true;
            }
            else {
                this.harvest(world, x, y, z);
            }
            if (update) {
                crop.markForUpdate();
            }
        }
    }

    public void plantSeed(World world, int x, int y, int z, EntityPlayer player) {
        if(!world.isRemote) {
            TileEntityCrop crop = (TileEntityCrop) world.getTileEntity(x, y, z);
            //is the cropEmpty a crosscrop or does it already have a plant
            if (crop.crossCrop || crop.hasPlant() || !(player.getCurrentEquippedItem().getItem() instanceof ItemSeeds)) {
                return;
            }
            //the seed can be planted here
            else {
                ItemStack stack = player.getCurrentEquippedItem();
                if (!SeedHelper.isValidSeed((ItemSeeds) stack.getItem(), stack.getItemDamage()) || !GrowthRequirements.getGrowthRequirement((ItemSeeds) stack.getItem(), stack.getItemDamage()).isValidSoil(world, x, y-1, z)) {
                    return;
                }
                //get NBT data from the seeds
{'fraction_non_alphanumeric': 0.10348187605560608, 'fraction_numerical': 0.005911394049629726, 'mean_word_length': 2.11010101010101, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '828318', 'n_tokens_mistral': 4731, 'n_tokens_neox': 4513, 'n_words': 943}