Search in sources :

Example 6 with IGardeningManager

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

the class TileEntityFlower method randomUpdate.

public void randomUpdate(Random rand) {
    if (world.getBlockState(pos).getBlock() != ModuleFlowers.flower) {
        invalidate();
        return;
    }
    if (getSection() > 0) {
        return;
    }
    if (flower == null) {
        return;
    }
    if (!isBreeding()) {
        return;
    }
    if (updateState(rand)) {
        return;
    }
    IGardeningManager gardening = BotanyCore.getGardening();
    EnumSoilType soil = gardening.getSoilType(world, pos.down());
    float chanceDispersal = 0.8f;
    chanceDispersal += 0.2f * flower.getGenome().getFertility();
    chanceDispersal *= 1.0f + soil.ordinal() * 0.5f;
    float chancePollinate = 1.0f;
    chancePollinate += 0.25f * flower.getGenome().getFertility();
    chancePollinate *= 1.0f + soil.ordinal() * 0.5f;
    float chanceSelfPollinate = 0.2f * chancePollinate;
    plantOffspring(rand, chanceDispersal);
    mateFlower(rand, chancePollinate, chanceSelfPollinate);
    spawnButterflies();
    matureCaterpillar();
    checkIfDead(false);
    updateRender(true);
}
Also used : EnumSoilType(binnie.botany.api.gardening.EnumSoilType) IGardeningManager(binnie.botany.api.gardening.IGardeningManager)

Example 7 with IGardeningManager

use of binnie.botany.api.gardening.IGardeningManager 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)

Example 8 with IGardeningManager

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

the class ModuleGardening method addFertiliserRecipes.

private void addFertiliserRecipes(RecipeUtil recipeUtil) {
    IGardeningManager gardening = BotanyCore.getGardening();
    for (EnumMoisture moisture : EnumMoisture.values()) {
        for (EnumAcidity acidity : EnumAcidity.values()) {
            int pH = acidity.ordinal();
            for (EnumSoilType type : EnumSoilType.values()) {
                Map<EnumFertiliserType, Map<ItemStack, Integer>> fertilisers = gardening.getFertilisers();
                for (EnumFertiliserType fertiliserType : EnumFertiliserType.values()) {
                    for (Map.Entry<ItemStack, Integer> entry : fertilisers.get(fertiliserType).entrySet()) {
                        ItemStack stack = entry.getKey();
                        int strengthMax = entry.getValue();
                        for (boolean weedkiller : new boolean[] { false, true }) {
                            int numOfBlocks = strengthMax * strengthMax;
                            for (int strength = 1; strength < strengthMax; ++strength) {
                                int endPh;
                                if (fertiliserType == EnumFertiliserType.ACID) {
                                    endPh = pH - strength;
                                } else if (fertiliserType == EnumFertiliserType.ALKALINE) {
                                    endPh = pH + strength;
                                } else {
                                    endPh = type.ordinal() + strength;
                                }
                                if (endPh < 0 || endPh > 2 || pH == endPh) {
                                    continue;
                                }
                                ItemStack start = getStack(type, acidity, moisture, weedkiller);
                                ItemStack end = getStack(type, EnumAcidity.values()[endPh], moisture, weedkiller);
                                if (!start.isEmpty() && !end.isEmpty()) {
                                    end.setCount(numOfBlocks);
                                    Object[] stacks = new Object[numOfBlocks + 1];
                                    for (int i = 0; i < numOfBlocks; ++i) {
                                        stacks[i] = start;
                                    }
                                    stacks[numOfBlocks] = stack.copy();
                                    String recipeName = fertiliserType.name().toLowerCase(Locale.ENGLISH) + "_fertiliser_moisture" + moisture + "_ph" + pH + "_type" + type + "_strength" + strength;
                                    recipeUtil.addShapelessRecipe(recipeName, end, stacks);
                                }
                                numOfBlocks /= 2;
                            }
                        }
                    }
                }
                ItemStack start = getStack(type, acidity, moisture, false);
                ItemStack end = getStack(type, acidity, moisture, true);
                String recipeName = "weedkiller_moisture" + moisture + "_ph" + pH + "_type" + type;
                recipeUtil.addShapelessRecipe(recipeName, end, start, start, start, start, "weedkiller");
            }
        }
    }
}
Also used : EnumMoisture(binnie.botany.api.gardening.EnumMoisture) EnumAcidity(binnie.botany.api.gardening.EnumAcidity) EnumSoilType(binnie.botany.api.gardening.EnumSoilType) EnumFertiliserType(binnie.botany.api.gardening.EnumFertiliserType) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map) IGardeningManager(binnie.botany.api.gardening.IGardeningManager)

Example 9 with IGardeningManager

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

the class TileEntityFlower method updateState.

private boolean updateState(Random rand) {
    float light = world.getLight(pos);
    if (light < 6.0f) {
        for (int offsetX = -2; offsetX <= 2; ++offsetX) {
            for (int offsetY = -2; offsetY <= 2; ++offsetY) {
                light -= (world.canBlockSeeSky(pos.add(offsetX, 0, offsetY)) ? 0.0f : 0.5f);
            }
        }
    }
    IGardeningManager gardening = BotanyCore.getGardening();
    boolean canTolerate = gardening.canTolerate(getFlower(), world, pos);
    if (rand.nextFloat() < getFlower().getGenome().getAgeChance()) {
        if (flower.getAge() < 1) {
            if (canTolerate && light > 6.0f) {
                doFlowerAge();
            }
        } else {
            doFlowerAge();
        }
    }
    if (canTolerate && flower.getAge() > 1 && !flower.isWilted() && light > 6.0f) {
        flower.setFlowered(true);
    }
    if (!canTolerate && flower.isWilted() && rand.nextInt(2 + Math.max(flower.getAge(), 2)) == 0) {
        kill();
        return true;
    }
    if (light < 2.0f && flower.isWilted()) {
        kill();
        return true;
    }
    if (!canTolerate || light < 1.0f) {
        flower.setWilted(true);
    } else {
        flower.setWilted(false);
    }
    return false;
}
Also used : IGardeningManager(binnie.botany.api.gardening.IGardeningManager)

Aggregations

IGardeningManager (binnie.botany.api.gardening.IGardeningManager)9 ItemStack (net.minecraft.item.ItemStack)5 IBlockSoil (binnie.botany.api.gardening.IBlockSoil)4 Block (net.minecraft.block.Block)4 EnumAcidity (binnie.botany.api.gardening.EnumAcidity)3 BlockPos (net.minecraft.util.math.BlockPos)3 EnumMoisture (binnie.botany.api.gardening.EnumMoisture)2 EnumSoilType (binnie.botany.api.gardening.EnumSoilType)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 EnumFertiliserType (binnie.botany.api.gardening.EnumFertiliserType)1 RecipeUtil (binnie.core.util.RecipeUtil)1 FarmDirection (forestry.api.farming.FarmDirection)1 Map (java.util.Map)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 World (net.minecraft.world.World)1