Search in sources :

Example 6 with WorkerBuildingModule

use of com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule in project minecolonies by ldtteam.

the class BuildingLumberjack method bonemealFungi.

/**
 * Returns early if no worker is assigned Iterates over the nether tree position list If position is a fungus, grows it depending on worker's level If the block has changed,
 * removes the position from the list and returns early If the position is not a fungus, removes the position from the list
 */
private void bonemealFungi() {
    final WorkerBuildingModule module = getFirstModuleOccurance(WorkerBuildingModule.class);
    final ICitizenData data = getFirstModuleOccurance(WorkerBuildingModule.class).getFirstCitizen();
    if (data == null) {
        return;
    }
    final int modifier = Math.max(0, Math.min(FUNGI_MODIFIER, 100));
    for (Iterator<BlockPos> iterator = netherTrees.iterator(); iterator.hasNext(); ) {
        final BlockPos pos = iterator.next();
        final World world = colony.getWorld();
        if (WorldUtil.isBlockLoaded(world, pos)) {
            final BlockState blockState = world.getBlockState(pos);
            final Block block = blockState.getBlock();
            if (block == Blocks.CRIMSON_FUNGUS || block == Blocks.WARPED_FUNGUS) {
                int threshold = modifier + (int) Math.ceil(data.getCitizenSkillHandler().getLevel(module.getPrimarySkill()) * (1 - ((float) modifier / 100)));
                final int rand = world.getRandom().nextInt(100);
                if (rand < threshold) {
                    final IGrowable growable = (IGrowable) block;
                    if (growable.isValidBonemealTarget(world, pos, blockState, world.isClientSide)) {
                        if (!world.isClientSide) {
                            if (growable.isBonemealSuccess(world, world.random, pos, blockState)) {
                                growable.performBonemeal((ServerWorld) world, world.random, pos, blockState);
                                return;
                            }
                        }
                    }
                }
            } else {
                iterator.remove();
            }
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) IGrowable(net.minecraft.block.IGrowable) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) ICitizenData(com.minecolonies.api.colony.ICitizenData) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World)

Aggregations

ICitizenData (com.minecolonies.api.colony.ICitizenData)6 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)6 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 Skill (com.minecolonies.api.entity.citizen.Skill)2 ILocalResearch (com.minecolonies.api.research.ILocalResearch)2 Block (net.minecraft.block.Block)2 BlockState (net.minecraft.block.BlockState)2 IGrowable (net.minecraft.block.IGrowable)2 BlockPos (net.minecraft.util.math.BlockPos)2 World (net.minecraft.world.World)2 ServerWorld (net.minecraft.world.server.ServerWorld)2