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);
}
}
}
}
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);
}
}
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);
}
}
}
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;
}
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);
}
}
}
Aggregations