use of com.eerussianguy.firmalife.te.TEStemCrop in project firmalife by eerussianguy.
the class BlockStemCrop method grow.
@Override
public void grow(World world, BlockPos cropPos, IBlockState cropState, Random random) {
if (!world.isRemote) {
// if penultimate stage
PropertyInteger stageProperty = getStageProperty();
if (cropState.getProperties().containsKey(stageProperty) && cropState.getValue(stageProperty) == getCrop().getMaxStage() - 1) {
TEStemCrop te = Helpers.getTE(world, cropPos, TEStemCrop.class);
EnumFacing fruitDirection = te.getFruitDirection();
BlockPos fruitPos = cropPos.offset(fruitDirection);
StemCrop crop = (StemCrop) getCrop();
if (crop.getCropBlock().canPlaceBlockAt(world, fruitPos)) {
IBlockState fruitState = crop.getCropBlock().getDefaultState().withProperty(BlockStemFruit.FACING, fruitDirection.getOpposite());
world.setBlockState(fruitPos, fruitState);
super.grow(world, cropPos, cropState, random);
}
} else {
super.grow(world, cropPos, cropState, random);
}
}
}
use of com.eerussianguy.firmalife.te.TEStemCrop in project firmalife by eerussianguy.
the class BlockStemCrop method onBlockAdded.
@Override
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
super.onBlockAdded(worldIn, pos, state);
// if adding a fully grown and wild crop
if (state.getValue(getStageProperty()) == getCrop().getMaxStage() && state.getValue(WILD)) {
TEStemCrop te = Helpers.getTE(worldIn, pos, TEStemCrop.class);
EnumFacing fruitDirection = te.getFruitDirection();
BlockPos targetPos = pos.offset(fruitDirection);
StemCrop crop = (StemCrop) getCrop();
if (// spawn fruit
crop.getCropBlock().canPlaceBlockAt(worldIn, targetPos)) {
worldIn.setBlockState(targetPos, crop.getCropBlock().getDefaultState().withProperty(BlockStemFruit.FACING, fruitDirection.getOpposite()));
} else // revert back a stage
{
worldIn.setBlockState(pos, state.withProperty(getStageProperty(), getCrop().getMaxStage() - 1));
}
}
}
use of com.eerussianguy.firmalife.te.TEStemCrop in project firmalife by eerussianguy.
the class BlockStemFruit method harvestBlock.
@Override
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity tee, ItemStack tool) {
super.harvestBlock(world, player, pos, state, tee, tool);
if (!world.isRemote) {
for (EnumFacing neighbor : EnumFacing.Plane.HORIZONTAL) {
BlockPos cropPos = pos.offset(neighbor);
Block block = world.getBlockState(cropPos).getBlock();
if (block instanceof BlockStemCrop) {
BlockStemCrop crop = (BlockStemCrop) block;
// check the crop is pointing towards us
TEStemCrop te = Helpers.getTE(world, cropPos, TEStemCrop.class);
if (te != null && te.getFruitDirection() == neighbor.getOpposite()) {
IBlockState cropState = world.getBlockState(cropPos);
int cropStage = cropState.getValue(crop.getStageProperty());
if (cropStage == crop.getCrop().getMaxStage()) {
world.setBlockState(cropPos, cropState.withProperty(crop.getStageProperty(), cropStage - 3));
SimpleSkill skill = CapabilityPlayerData.getSkill(player, SkillType.AGRICULTURE);
ItemStack seedDrop = new ItemStack(ItemSeedsTFC.get(crop.getCrop()), 0);
if (skill != null) {
seedDrop.setCount(Crop.getSkillSeedBonus(skill, RANDOM));
}
if (!seedDrop.isEmpty())
ItemHandlerHelper.giveItemToPlayer(player, seedDrop);
}
}
}
}
}
world.setBlockToAir(pos);
}
Aggregations