Search in sources :

Example 1 with TEStemCrop

use of com.eerussianguy.firmalife.te.TEStemCrop in project firmalife by eerussianguy.

the class BlockStemCrop method grow.

@Override
public void grow(World world, BlockPos cropPos, IBlockState cropState, Random random) {
    if (!world.isRemote) {
        // if penultimate stage
        PropertyInteger stageProperty = getStageProperty();
        if (cropState.getProperties().containsKey(stageProperty) && cropState.getValue(stageProperty) == getCrop().getMaxStage() - 1) {
            TEStemCrop te = Helpers.getTE(world, cropPos, TEStemCrop.class);
            EnumFacing fruitDirection = te.getFruitDirection();
            BlockPos fruitPos = cropPos.offset(fruitDirection);
            StemCrop crop = (StemCrop) getCrop();
            if (crop.getCropBlock().canPlaceBlockAt(world, fruitPos)) {
                IBlockState fruitState = crop.getCropBlock().getDefaultState().withProperty(BlockStemFruit.FACING, fruitDirection.getOpposite());
                world.setBlockState(fruitPos, fruitState);
                super.grow(world, cropPos, cropState, random);
            }
        } else {
            super.grow(world, cropPos, cropState, random);
        }
    }
}
Also used : PropertyInteger(net.minecraft.block.properties.PropertyInteger) TEStemCrop(com.eerussianguy.firmalife.te.TEStemCrop) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) StemCrop(com.eerussianguy.firmalife.init.StemCrop) TEStemCrop(com.eerussianguy.firmalife.te.TEStemCrop) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with TEStemCrop

use of com.eerussianguy.firmalife.te.TEStemCrop in project firmalife by eerussianguy.

the class BlockStemCrop method onBlockAdded.

@Override
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
    super.onBlockAdded(worldIn, pos, state);
    // if adding a fully grown and wild crop
    if (state.getValue(getStageProperty()) == getCrop().getMaxStage() && state.getValue(WILD)) {
        TEStemCrop te = Helpers.getTE(worldIn, pos, TEStemCrop.class);
        EnumFacing fruitDirection = te.getFruitDirection();
        BlockPos targetPos = pos.offset(fruitDirection);
        StemCrop crop = (StemCrop) getCrop();
        if (// spawn fruit
        crop.getCropBlock().canPlaceBlockAt(worldIn, targetPos)) {
            worldIn.setBlockState(targetPos, crop.getCropBlock().getDefaultState().withProperty(BlockStemFruit.FACING, fruitDirection.getOpposite()));
        } else // revert back a stage
        {
            worldIn.setBlockState(pos, state.withProperty(getStageProperty(), getCrop().getMaxStage() - 1));
        }
    }
}
Also used : TEStemCrop(com.eerussianguy.firmalife.te.TEStemCrop) EnumFacing(net.minecraft.util.EnumFacing) StemCrop(com.eerussianguy.firmalife.init.StemCrop) TEStemCrop(com.eerussianguy.firmalife.te.TEStemCrop) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with TEStemCrop

use of com.eerussianguy.firmalife.te.TEStemCrop in project firmalife by eerussianguy.

the class BlockStemFruit method harvestBlock.

@Override
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity tee, ItemStack tool) {
    super.harvestBlock(world, player, pos, state, tee, tool);
    if (!world.isRemote) {
        for (EnumFacing neighbor : EnumFacing.Plane.HORIZONTAL) {
            BlockPos cropPos = pos.offset(neighbor);
            Block block = world.getBlockState(cropPos).getBlock();
            if (block instanceof BlockStemCrop) {
                BlockStemCrop crop = (BlockStemCrop) block;
                // check the crop is pointing towards us
                TEStemCrop te = Helpers.getTE(world, cropPos, TEStemCrop.class);
                if (te != null && te.getFruitDirection() == neighbor.getOpposite()) {
                    IBlockState cropState = world.getBlockState(cropPos);
                    int cropStage = cropState.getValue(crop.getStageProperty());
                    if (cropStage == crop.getCrop().getMaxStage()) {
                        world.setBlockState(cropPos, cropState.withProperty(crop.getStageProperty(), cropStage - 3));
                        SimpleSkill skill = CapabilityPlayerData.getSkill(player, SkillType.AGRICULTURE);
                        ItemStack seedDrop = new ItemStack(ItemSeedsTFC.get(crop.getCrop()), 0);
                        if (skill != null) {
                            seedDrop.setCount(Crop.getSkillSeedBonus(skill, RANDOM));
                        }
                        if (!seedDrop.isEmpty())
                            ItemHandlerHelper.giveItemToPlayer(player, seedDrop);
                    }
                }
            }
        }
    }
    world.setBlockToAir(pos);
}
Also used : TEStemCrop(com.eerussianguy.firmalife.te.TEStemCrop) IBlockState(net.minecraft.block.state.IBlockState) SimpleSkill(net.dries007.tfc.util.skills.SimpleSkill) EnumFacing(net.minecraft.util.EnumFacing) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Aggregations

TEStemCrop (com.eerussianguy.firmalife.te.TEStemCrop)3 EnumFacing (net.minecraft.util.EnumFacing)3 BlockPos (net.minecraft.util.math.BlockPos)3 StemCrop (com.eerussianguy.firmalife.init.StemCrop)2 IBlockState (net.minecraft.block.state.IBlockState)2 SimpleSkill (net.dries007.tfc.util.skills.SimpleSkill)1 Block (net.minecraft.block.Block)1 PropertyInteger (net.minecraft.block.properties.PropertyInteger)1 ItemStack (net.minecraft.item.ItemStack)1