Search in sources :

Example 6 with TileEntityFlower

use of binnie.botany.tile.TileEntityFlower in project Binnie by ForestryMC.

the class ModuleFlowers method onShearFlower.

@SubscribeEvent
public void onShearFlower(PlayerInteractEvent.RightClickBlock event) {
    EntityPlayer player = event.getEntityPlayer();
    if (player == null) {
        return;
    }
    ItemStack heldItem = player.getHeldItemMainhand();
    if (heldItem.isEmpty()) {
        return;
    }
    TileEntity tile = event.getWorld().getTileEntity(event.getPos());
    if (!(tile instanceof TileEntityFlower)) {
        return;
    }
    TileEntityFlower flower = (TileEntityFlower) tile;
    if (heldItem.getItem() == Items.SHEARS) {
        flower.onShear();
        heldItem.damageItem(1, player);
    } else if (heldItem.getItem() == pollen) {
        IFlower pollen = BotanyCore.getFlowerRoot().getMember(heldItem);
        if (pollen != null && flower.canMateWith(pollen)) {
            flower.mateWith(pollen);
            if (!player.capabilities.isCreativeMode) {
                heldItem.shrink(1);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IFlower(binnie.botany.api.genetics.IFlower) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) TileEntityFlower(binnie.botany.tile.TileEntityFlower) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 7 with TileEntityFlower

use of binnie.botany.tile.TileEntityFlower in project Binnie by ForestryMC.

the class ModuleFlowers method onBonemeal.

@SubscribeEvent
public void onBonemeal(BonemealEvent event) {
    BlockPos pos = event.getPos();
    TileEntityFlower tile = TileUtil.getTile(event.getWorld(), pos, TileEntityFlower.class);
    if (tile != null && tile.onBonemeal()) {
        event.setResult(Event.Result.ALLOW);
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) TileEntityFlower(binnie.botany.tile.TileEntityFlower) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 8 with TileEntityFlower

use of binnie.botany.tile.TileEntityFlower in project Binnie by ForestryMC.

the class FlowerRoot method tryGrowSection.

@Override
public void tryGrowSection(World world, BlockPos pos) {
    if (world.isRemote) {
        return;
    }
    TileEntity tileFlower = world.getTileEntity(pos);
    if (tileFlower == null || !(tileFlower instanceof TileEntityFlower)) {
        return;
    }
    IFlower flower = ((TileEntityFlower) tileFlower).getFlower();
    int section = ((TileEntityFlower) tileFlower).getSection();
    if (flower == null || section >= flower.getGenome().getPrimary().getType().getSections() - 1 || flower.getAge() <= 0) {
        return;
    }
    BlockPos up = pos.up();
    IBlockState blockAbove = world.getBlockState(up);
    if (blockAbove.getBlock().isReplaceable(world, up)) {
        world.setBlockState(up, ModuleFlowers.flower.getDefaultState());
        TileEntity flowerAbove = world.getTileEntity(up);
        if (flowerAbove != null && flowerAbove instanceof TileEntityFlower) {
            ((TileEntityFlower) flowerAbove).setSection(section + 1);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) IFlower(binnie.botany.api.genetics.IFlower) BlockPos(net.minecraft.util.math.BlockPos) TileEntityFlower(binnie.botany.tile.TileEntityFlower)

Example 9 with TileEntityFlower

use of binnie.botany.tile.TileEntityFlower in project Binnie by ForestryMC.

the class BlockFlower method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack heldItem = player.getHeldItemMainhand();
    if (heldItem.isEmpty() || heldItem.getItem() != BinnieCore.getFieldKit() || !player.isSneaking()) {
        return false;
    }
    if (world.isRemote) {
        return true;
    }
    TileEntity tile = world.getTileEntity(pos);
    if (!(tile instanceof TileEntityFlower)) {
        return true;
    }
    TileEntityFlower tileFlower = (TileEntityFlower) tile;
    IFlower flower = tileFlower.getFlower();
    if (flower == null) {
        return true;
    }
    IFlowerGenome flowerGenome = flower.getGenome();
    NBTTagCompound info = new NBTTagCompound();
    info.setString("Species", flowerGenome.getPrimary().getUID());
    info.setString("Species2", flowerGenome.getSecondary().getUID());
    info.setFloat("Age", flower.getAge() / flowerGenome.getLifespan());
    info.setShort("Colour", (short) flowerGenome.getPrimaryColor().getID());
    info.setShort("Colour2", (short) flowerGenome.getSecondaryColor().getID());
    info.setBoolean("Wilting", flower.isWilted());
    info.setBoolean("Flowered", flower.hasFlowered());
    Botany.proxy.sendToPlayer(new MessageNBT(PacketID.FIELDKIT.ordinal(), info), player);
    heldItem.damageItem(1, player);
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IFlowerGenome(binnie.botany.api.genetics.IFlowerGenome) MessageNBT(binnie.core.network.packet.MessageNBT) IFlower(binnie.botany.api.genetics.IFlower) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) TileEntityFlower(binnie.botany.tile.TileEntityFlower)

Example 10 with TileEntityFlower

use of binnie.botany.tile.TileEntityFlower in project Binnie by ForestryMC.

the class BlockFlower method neighborChanged.

@Override
@SuppressWarnings("deprecation")
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) {
    checkAndDropBlock(worldIn, pos);
    TileEntity tile = worldIn.getTileEntity(pos);
    if (tile instanceof TileEntityFlower) {
        TileEntityFlower flower = (TileEntityFlower) tile;
        if (flower.getSection() == 0 && flower.getFlower() != null && flower.getFlower().getAge() > 0 && flower.getFlower().getGenome().getPrimary().getType().getSections() > 1 && worldIn.getBlockState(pos.up()).getBlock() != ModuleFlowers.flower) {
            dropBlockAsItem(worldIn, pos, worldIn.getBlockState(pos), 0);
            worldIn.setBlockToAir(pos);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityFlower(binnie.botany.tile.TileEntityFlower)

Aggregations

TileEntityFlower (binnie.botany.tile.TileEntityFlower)12 TileEntity (net.minecraft.tileentity.TileEntity)9 IFlower (binnie.botany.api.genetics.IFlower)5 ItemStack (net.minecraft.item.ItemStack)3 IFlowerRoot (binnie.botany.api.genetics.IFlowerRoot)2 IBlockState (net.minecraft.block.state.IBlockState)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 BlockPos (net.minecraft.util.math.BlockPos)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 IFlowerGenome (binnie.botany.api.genetics.IFlowerGenome)1 FlowerRenderInfo (binnie.botany.tile.FlowerRenderInfo)1 MessageNBT (binnie.core.network.packet.MessageNBT)1 GameProfile (com.mojang.authlib.GameProfile)1 IFarmable (forestry.api.farming.IFarmable)1 IOwnedTile (forestry.core.owner.IOwnedTile)1 Nullable (javax.annotation.Nullable)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1