Search in sources :

Example 1 with IBlockSoil

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

the class GardeningManager method addWeedKiller.

@Override
public boolean addWeedKiller(World world, BlockPos pos) {
    IBlockState oldState = world.getBlockState(pos);
    if (!(oldState.getBlock() instanceof IBlockSoil)) {
        return false;
    }
    EnumSoilType type = getSoilType(world, pos);
    IBlockState newState = getSoil(type, true, oldState.getValue(BlockSoil.MOISTURE), oldState.getValue(BlockSoil.ACIDITY));
    boolean done = world.setBlockState(pos, newState, 2);
    if (done && BlockPlant.isWeed(world, pos.up())) {
        world.setBlockToAir(pos.up());
    }
    return done;
}
Also used : IBlockSoil(binnie.botany.api.gardening.IBlockSoil) IBlockState(net.minecraft.block.state.IBlockState) EnumSoilType(binnie.botany.api.gardening.EnumSoilType)

Example 2 with IBlockSoil

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

the class ItemSoilMeter method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    Block block = worldIn.getBlockState(pos).getBlock();
    IGardeningManager gardening = BotanyCore.getGardening();
    if (!gardening.isSoil(block)) {
        pos = pos.down();
        block = worldIn.getBlockState(pos).getBlock();
    }
    if (!gardening.isSoil(block)) {
        pos = pos.down();
        block = worldIn.getBlockState(pos).getBlock();
    }
    if (gardening.isSoil(block) && worldIn.isRemote) {
        IBlockSoil soil = (IBlockSoil) block;
        String info = I18N.localise("botany.soil.type") + ": " + EnumHelper.getLocalisedName(soil.getType(worldIn, pos), true) + ", " + TextFormatting.WHITE + I18N.localise("botany.moisture") + ": " + EnumHelper.getLocalisedName(soil.getMoisture(worldIn, pos), true) + ", " + TextFormatting.WHITE + I18N.localise("botany.ph") + ": " + EnumHelper.getLocalisedName(soil.getPH(worldIn, pos), true);
        ITextComponent chat = new TextComponentString(info);
        player.sendStatusMessage(chat, false);
    }
    return EnumActionResult.SUCCESS;
}
Also used : IBlockSoil(binnie.botany.api.gardening.IBlockSoil) ITextComponent(net.minecraft.util.text.ITextComponent) Block(net.minecraft.block.Block) TextComponentString(net.minecraft.util.text.TextComponentString) IGardeningManager(binnie.botany.api.gardening.IGardeningManager) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 3 with IBlockSoil

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

the class ModuleGardening method onFertiliseSoil.

@SubscribeEvent
public void onFertiliseSoil(PlayerInteractEvent.RightClickBlock event) {
    World world = event.getWorld();
    if (world == null) {
        return;
    }
    BlockPos pos = event.getPos();
    EntityPlayer player = event.getEntityPlayer();
    if (player == null) {
        return;
    }
    ItemStack heldItem = player.getHeldItemMainhand();
    if (heldItem.isEmpty()) {
        return;
    }
    IGardeningManager gardening = BotanyCore.getGardening();
    Block block = world.getBlockState(event.getPos()).getBlock();
    if (!gardening.isSoil(block)) {
        pos = pos.down();
        block = world.getBlockState(pos).getBlock();
    }
    if (!gardening.isSoil(block)) {
        return;
    }
    IBlockSoil soil = (IBlockSoil) block;
    if (gardening.onFertiliseSoil(heldItem, soil, world, pos, player)) {
        return;
    }
    if (OreDictionaryUtil.hasOreName(heldItem, "weedkiller") && gardening.addWeedKiller(world, pos)) {
        if (!player.capabilities.isCreativeMode) {
            heldItem.shrink(1);
        }
    }
}
Also used : IBlockSoil(binnie.botany.api.gardening.IBlockSoil) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) IGardeningManager(binnie.botany.api.gardening.IGardeningManager) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with IBlockSoil

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

the class ModuleGardening method onBonemeal.

@SubscribeEvent
public void onBonemeal(BonemealEvent event) {
    IGardeningManager gardening = BotanyCore.getGardening();
    BlockPos pos = event.getPos();
    Block block = event.getBlock().getBlock();
    if (gardening.isSoil(block)) {
        IBlockSoil soil = (IBlockSoil) block;
        if (soil.fertilise(event.getWorld(), pos, EnumSoilType.LOAM)) {
            event.setResult(Event.Result.ALLOW);
        }
    }
}
Also used : IBlockSoil(binnie.botany.api.gardening.IBlockSoil) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) IGardeningManager(binnie.botany.api.gardening.IGardeningManager) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with IBlockSoil

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

the class ModuleFlowers method onPlantVanilla.

@Deprecated
public void onPlantVanilla(PlayerInteractEvent.RightClickBlock event) {
    BlockPos pos = event.getPos();
    World world = event.getWorld();
    EntityPlayer player = event.getEntityPlayer();
    ItemStack heldItem = player.getHeldItemMainhand();
    if (event.getWorld().isRemote) {
        return;
    }
    if (heldItem.isEmpty()) {
        return;
    }
    Block block = world.getBlockState(pos).getBlock();
    int py = -1;
    if (block instanceof IBlockSoil && (world.isAirBlock(pos.up()) || block.isReplaceable(world, pos))) {
        py = 1;
    }
    if (py < 0) {
        return;
    }
    IFlowerRoot flowerRoot = BotanyCore.getFlowerRoot();
    IFlower flower = flowerRoot.getConversion(heldItem);
    if (flower != null && flowerRoot.plant(world, pos.add(0, py, 0), flower, player.getGameProfile()) && !player.capabilities.isCreativeMode) {
        heldItem.shrink(1);
    }
}
Also used : IBlockSoil(binnie.botany.api.gardening.IBlockSoil) IFlower(binnie.botany.api.genetics.IFlower) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) IFlowerRoot(binnie.botany.api.genetics.IFlowerRoot)

Aggregations

IBlockSoil (binnie.botany.api.gardening.IBlockSoil)7 Block (net.minecraft.block.Block)5 IGardeningManager (binnie.botany.api.gardening.IGardeningManager)4 BlockPos (net.minecraft.util.math.BlockPos)4 ItemStack (net.minecraft.item.ItemStack)3 IBlockState (net.minecraft.block.state.IBlockState)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 EnumAcidity (binnie.botany.api.gardening.EnumAcidity)1 EnumSoilType (binnie.botany.api.gardening.EnumSoilType)1 IFlower (binnie.botany.api.genetics.IFlower)1 IFlowerRoot (binnie.botany.api.genetics.IFlowerRoot)1 FarmDirection (forestry.api.farming.FarmDirection)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 TextComponentString (net.minecraft.util.text.TextComponentString)1