Search in sources :

Example 1 with EnumAcidity

use of binnie.botany.api.gardening.EnumAcidity in project Binnie by ForestryMC.

the class GardeningManager method onFertiliseSoil.

@Override
public boolean onFertiliseSoil(ItemStack heldItem, IBlockSoil soil, World world, BlockPos pos, EntityPlayer player) {
    int fertiliserStrength = getFertiliserStrength(heldItem);
    if (isFertiliser(EnumFertiliserType.NUTRIENT, heldItem) && soil.getType(world, pos) != EnumSoilType.FLOWERBED) {
        EnumSoilType type = soil.getType(world, pos);
        int next = Math.min(type.ordinal() + fertiliserStrength, 2);
        if (soil.fertilise(world, pos, EnumSoilType.values()[next])) {
            if (!player.capabilities.isCreativeMode) {
                heldItem.shrink(1);
            }
            return true;
        }
    }
    if (isFertiliser(EnumFertiliserType.ACID, heldItem) && soil.getPH(world, pos) != EnumAcidity.ACID) {
        EnumAcidity pH = soil.getPH(world, pos);
        int next = Math.max(pH.ordinal() - fertiliserStrength, 0);
        if (soil.setPH(world, pos, EnumAcidity.values()[next])) {
            if (!player.capabilities.isCreativeMode) {
                heldItem.shrink(1);
            }
            return true;
        }
    }
    if (isFertiliser(EnumFertiliserType.ALKALINE, heldItem) && soil.getPH(world, pos) != EnumAcidity.ALKALINE) {
        EnumAcidity pH = soil.getPH(world, pos);
        int next = Math.min(pH.ordinal() + fertiliserStrength, 2);
        if (soil.setPH(world, pos, EnumAcidity.values()[next])) {
            if (!player.capabilities.isCreativeMode) {
                heldItem.shrink(1);
            }
            return true;
        }
    }
    return false;
}
Also used : EnumAcidity(binnie.botany.api.gardening.EnumAcidity) EnumSoilType(binnie.botany.api.gardening.EnumSoilType)

Example 2 with EnumAcidity

use of binnie.botany.api.gardening.EnumAcidity in project Binnie by ForestryMC.

the class BlockSoil method getStateFromMeta.

@Override
@SuppressWarnings("deprecation")
public IBlockState getStateFromMeta(int meta) {
    EnumMoisture moisture = EnumMoisture.values()[meta % 3];
    EnumAcidity acidity = EnumAcidity.values()[meta / 3];
    return getDefaultState().withProperty(MOISTURE, moisture).withProperty(ACIDITY, acidity);
}
Also used : EnumMoisture(binnie.botany.api.gardening.EnumMoisture) EnumAcidity(binnie.botany.api.gardening.EnumAcidity)

Example 3 with EnumAcidity

use of binnie.botany.api.gardening.EnumAcidity in project Binnie by ForestryMC.

the class GardenLogic method getAvailableLoam.

private ItemStack getAvailableLoam(IFarmHousing housing) {
    EnumMoisture[] moistures;
    if (moisture == EnumMoisture.DAMP) {
        moistures = new EnumMoisture[] { EnumMoisture.DAMP, EnumMoisture.NORMAL, EnumMoisture.DRY };
    } else if (moisture == EnumMoisture.DRY) {
        moistures = new EnumMoisture[] { EnumMoisture.DRY, EnumMoisture.DAMP, EnumMoisture.DRY };
    } else {
        moistures = new EnumMoisture[] { EnumMoisture.DRY, EnumMoisture.NORMAL, EnumMoisture.DAMP };
    }
    EnumAcidity[] acidities = { EnumAcidity.NEUTRAL, EnumAcidity.ACID, EnumAcidity.ALKALINE };
    for (EnumMoisture moist : moistures) {
        for (EnumAcidity acid : acidities) {
            for (Block type : new Block[] { ModuleGardening.flowerbed, ModuleGardening.loam, ModuleGardening.soil }) {
                int meta = acid.ordinal() * 3 + moist.ordinal();
                NonNullList<ItemStack> resources = NonNullList.create();
                ItemStack resourceStack = new ItemStack(type, 1, meta);
                resources.add(resourceStack);
                if (housing.getFarmInventory().hasResources(resources)) {
                    return resourceStack;
                }
            }
        }
    }
    NonNullList<ItemStack> resources = NonNullList.create();
    ItemStack resourceStack = new ItemStack(Blocks.DIRT);
    resources.add(resourceStack);
    if (housing.getFarmInventory().hasResources(resources)) {
        return new ItemStack(Blocks.DIRT);
    }
    return ItemStack.EMPTY;
}
Also used : EnumMoisture(binnie.botany.api.gardening.EnumMoisture) EnumAcidity(binnie.botany.api.gardening.EnumAcidity) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack)

Example 4 with EnumAcidity

use of binnie.botany.api.gardening.EnumAcidity in project Binnie by ForestryMC.

the class ItemTrowel method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    if (!player.canPlayerEdit(pos, facing, stack)) {
        return EnumActionResult.FAIL;
    }
    Block block = worldIn.getBlockState(pos).getBlock();
    if (facing == EnumFacing.DOWN || (!worldIn.isAirBlock(pos.up()) && ModuleManager.isModuleEnabled(Constants.BOTANY_MOD_ID, BotanyModuleUIDs.FLOWERS) && worldIn.getBlockState(pos.up()).getBlock() != ModuleFlowers.flower) || (block != Blocks.GRASS && block != Blocks.DIRT && block != Blocks.GRASS_PATH)) {
        return EnumActionResult.PASS;
    }
    worldIn.playSound(player, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F);
    if (worldIn.isRemote) {
        return EnumActionResult.SUCCESS;
    }
    IGardeningManager gardening = BotanyCore.getGardening();
    EnumMoisture moisture = gardening.getNaturalMoisture(worldIn, pos);
    EnumAcidity acidity = gardening.getNaturalPH(worldIn, pos);
    gardening.plantSoil(worldIn, pos, EnumSoilType.SOIL, moisture, acidity);
    stack.damageItem(1, player);
    return EnumActionResult.SUCCESS;
}
Also used : EnumMoisture(binnie.botany.api.gardening.EnumMoisture) EnumAcidity(binnie.botany.api.gardening.EnumAcidity) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) IGardeningManager(binnie.botany.api.gardening.IGardeningManager)

Example 5 with EnumAcidity

use of binnie.botany.api.gardening.EnumAcidity in project Binnie by ForestryMC.

the class GardenLogic method maintainSoil.

private boolean maintainSoil(World world, BlockPos pos, FarmDirection direction, int extent, IFarmHousing housing) {
    IGardeningManager gardening = BotanyCore.getGardening();
    for (int i = 0; i < extent; ++i) {
        BlockPos position = pos.offset(direction.getFacing(), i);
        if (fertilised && gardening.isSoil(getBlock(world, position))) {
            IBlockSoil soil = (IBlockSoil) getBlock(world, position);
            if (soil.fertilise(world, position, EnumSoilType.FLOWERBED)) {
                continue;
            }
        }
        if (getBlock(world, position.up()) == ModuleGardening.plant) {
            world.setBlockToAir(position.up());
        } else {
            if (acidity != null && gardening.isSoil(getBlock(world, position))) {
                IBlockSoil soil = (IBlockSoil) getBlock(world, position);
                EnumAcidity pH = soil.getPH(world, position);
                if (pH.ordinal() < acidity.ordinal()) {
                    ItemStack stack = getAvailableFertiliser(housing, EnumFertiliserType.ALKALINE);
                    if (!stack.isEmpty() && soil.setPH(world, position, EnumAcidity.values()[pH.ordinal() + 1])) {
                        NonNullList<ItemStack> resources = NonNullList.create();
                        resources.add(stack);
                        housing.getFarmInventory().removeResources(resources);
                        continue;
                    }
                }
                if (pH.ordinal() > acidity.ordinal()) {
                    ItemStack stack = getAvailableFertiliser(housing, EnumFertiliserType.ACID);
                    if (!stack.isEmpty() && soil.setPH(world, position, EnumAcidity.values()[pH.ordinal() - 1])) {
                        NonNullList<ItemStack> resources = NonNullList.create();
                        resources.add(stack);
                        housing.getFarmInventory().removeResources(resources);
                        continue;
                    }
                }
            }
            if (!isAirBlock(world, position) && !BlockUtil.isReplaceableBlock(getBlockState(world, position), world, position)) {
                ItemStack block = getAsItemStack(world, position);
                ItemStack loam = getAvailableLoam(housing);
                if (isWaste(block) && !loam.isEmpty()) {
                    IBlockState blockState = Block.getBlockFromItem(block.getItem()).getStateFromMeta(block.getItemDamage());
                    Blocks.DIRT.getDrops(produce, world, position, blockState, 0);
                    setBlock(world, position, Blocks.AIR, 0);
                    return trySetSoil(world, position, loam, housing);
                }
            } else if (!isManual()) {
                if (!isWaterBlock(world, position)) {
                    if (i % 2 == 0) {
                        return trySetSoil(world, position, housing);
                    }
                    FarmDirection cclock = FarmDirection.EAST;
                    if (direction == FarmDirection.EAST) {
                        cclock = FarmDirection.SOUTH;
                    } else if (direction == FarmDirection.SOUTH) {
                        cclock = FarmDirection.EAST;
                    } else if (direction == FarmDirection.WEST) {
                        cclock = FarmDirection.SOUTH;
                    }
                    BlockPos previous = position.offset(cclock.getFacing());
                    ItemStack soil2 = getAsItemStack(world, previous);
                    if (!gardening.isSoil(soil2.getItem())) {
                        trySetSoil(world, position, housing);
                    }
                }
            }
        }
    }
    return false;
}
Also used : IBlockSoil(binnie.botany.api.gardening.IBlockSoil) IBlockState(net.minecraft.block.state.IBlockState) EnumAcidity(binnie.botany.api.gardening.EnumAcidity) BlockPos(net.minecraft.util.math.BlockPos) FarmDirection(forestry.api.farming.FarmDirection) ItemStack(net.minecraft.item.ItemStack) IGardeningManager(binnie.botany.api.gardening.IGardeningManager)

Aggregations

EnumAcidity (binnie.botany.api.gardening.EnumAcidity)9 EnumMoisture (binnie.botany.api.gardening.EnumMoisture)6 ItemStack (net.minecraft.item.ItemStack)4 IGardeningManager (binnie.botany.api.gardening.IGardeningManager)3 EnumSoilType (binnie.botany.api.gardening.EnumSoilType)2 Block (net.minecraft.block.Block)2 IBlockState (net.minecraft.block.state.IBlockState)2 EnumFertiliserType (binnie.botany.api.gardening.EnumFertiliserType)1 IBlockSoil (binnie.botany.api.gardening.IBlockSoil)1 EnumTemperature (forestry.api.core.EnumTemperature)1 FarmDirection (forestry.api.farming.FarmDirection)1 Map (java.util.Map)1 ItemBlock (net.minecraft.item.ItemBlock)1 BlockPos (net.minecraft.util.math.BlockPos)1 Biome (net.minecraft.world.biome.Biome)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1