Search in sources :

Example 1 with IBeeHousingInventory

use of forestry.api.apiculture.IBeeHousingInventory in project ForestryMC by ForestryMC.

the class BeekeepingLogic method canWork.

/* UPDATING */
@Override
public boolean canWork() {
    IErrorLogic errorLogic = housing.getErrorLogic();
    errorLogic.clearErrors();
    IBeeHousingInventory beeInventory = housing.getBeeInventory();
    boolean hasSpace = addPendingProducts(beeInventory, spawn);
    errorLogic.setCondition(!hasSpace, EnumErrorCode.NO_SPACE_INVENTORY);
    ItemStack queenStack = beeInventory.getQueen();
    EnumBeeType beeType = BeeManager.beeRoot.getType(queenStack);
    // check if we're breeding
    if (beeType == EnumBeeType.PRINCESS) {
        boolean hasDrone = BeeManager.beeRoot.isDrone(beeInventory.getDrone());
        errorLogic.setCondition(!hasDrone, EnumErrorCode.NO_DRONE);
        // not active (no bee FX) when we are breeding
        setActive(false);
        return !errorLogic.hasErrors();
    }
    if (beeType == EnumBeeType.QUEEN) {
        if (!isQueenAlive(queenStack)) {
            IBee dyingQueen = BeeManager.beeRoot.getMember(queenStack);
            Collection<ItemStack> spawned = killQueen(dyingQueen, housing, beeListener);
            spawn.addAll(spawned);
            queenStack = ItemStack.EMPTY;
        }
    } else {
        queenStack = ItemStack.EMPTY;
    }
    if (this.queenStack != queenStack) {
        if (!queenStack.isEmpty()) {
            this.queen = BeeManager.beeRoot.getMember(queenStack);
            if (this.queen != null) {
                hasFlowersCache.onNewQueen(queen, housing);
            }
        } else {
            this.queen = null;
        }
        this.queenStack = queenStack;
        queenCanWorkCache.clear();
    }
    if (errorLogic.setCondition(queen == null, EnumErrorCode.NO_QUEEN)) {
        setActive(false);
        beeProgress = 0;
        return false;
    }
    Set<IErrorState> queenErrors = queenCanWorkCache.queenCanWork(queen, housing);
    for (IErrorState errorState : queenErrors) {
        errorLogic.setCondition(true, errorState);
    }
    hasFlowersCache.update(queen, housing);
    boolean hasFlowers = hasFlowersCache.hasFlowers();
    boolean flowerCacheNeedsSync = hasFlowersCache.needsSync();
    errorLogic.setCondition(!hasFlowers, EnumErrorCode.NO_FLOWER);
    boolean canWork = !errorLogic.hasErrors();
    if (active != canWork) {
        setActive(canWork);
    } else if (flowerCacheNeedsSync) {
        syncToClient();
    }
    return canWork;
}
Also used : IBeeHousingInventory(forestry.api.apiculture.IBeeHousingInventory) IErrorState(forestry.api.core.IErrorState) IBee(forestry.api.apiculture.IBee) ItemStack(net.minecraft.item.ItemStack) IErrorLogic(forestry.api.core.IErrorLogic) EnumBeeType(forestry.api.apiculture.EnumBeeType)

Example 2 with IBeeHousingInventory

use of forestry.api.apiculture.IBeeHousingInventory in project ForestryMC by ForestryMC.

the class BeekeepingLogic method killQueen.

private static Collection<ItemStack> killQueen(IBee queen, IBeeHousing beeHousing, IBeeListener beeListener) {
    IBeeHousingInventory beeInventory = beeHousing.getBeeInventory();
    Collection<ItemStack> spawn;
    if (queen.canSpawn()) {
        spawn = spawnOffspring(queen, beeHousing);
        beeListener.onQueenDeath();
        beeInventory.getQueen().setCount(0);
        beeInventory.setQueen(ItemStack.EMPTY);
    } else {
        Log.warning("Tried to spawn offspring off an unmated queen. Devolving her to a princess.");
        ItemStack convert = new ItemStack(ModuleApiculture.getItems().beePrincessGE);
        NBTTagCompound nbttagcompound = new NBTTagCompound();
        queen.writeToNBT(nbttagcompound);
        convert.setTagCompound(nbttagcompound);
        spawn = Collections.singleton(convert);
        beeInventory.setQueen(ItemStack.EMPTY);
    }
    return spawn;
}
Also used : IBeeHousingInventory(forestry.api.apiculture.IBeeHousingInventory) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IBeeHousingInventory

use of forestry.api.apiculture.IBeeHousingInventory in project ForestryMC by ForestryMC.

the class BeekeepingLogic method spawnOffspring.

/**
 * Creates the succeeding princess and between one and three drones.
 */
private static Collection<ItemStack> spawnOffspring(IBee queen, IBeeHousing beeHousing) {
    World world = beeHousing.getWorldObj();
    Stack<ItemStack> offspring = new Stack<>();
    IApiaristTracker breedingTracker = BeeManager.beeRoot.getBreedingTracker(world, beeHousing.getOwner());
    // Princess
    boolean secondPrincess = world.rand.nextInt(10000) < ModuleApiculture.getSecondPrincessChance() * 100;
    int count = secondPrincess ? 2 : 1;
    while (count > 0) {
        count--;
        IBee heiress = queen.spawnPrincess(beeHousing);
        if (heiress != null) {
            ItemStack princess = BeeManager.beeRoot.getMemberStack(heiress, EnumBeeType.PRINCESS);
            breedingTracker.registerPrincess(heiress);
            offspring.push(princess);
        }
    }
    // Drones
    List<IBee> drones = queen.spawnDrones(beeHousing);
    for (IBee drone : drones) {
        ItemStack droneStack = BeeManager.beeRoot.getMemberStack(drone, EnumBeeType.DRONE);
        breedingTracker.registerDrone(drone);
        offspring.push(droneStack);
    }
    IBeeHousingInventory beeInventory = beeHousing.getBeeInventory();
    Collection<ItemStack> spawn = new ArrayList<>();
    while (!offspring.isEmpty()) {
        ItemStack spawned = offspring.pop();
        if (!beeInventory.addProduct(spawned, true)) {
            spawn.add(spawned);
        }
    }
    return spawn;
}
Also used : IBeeHousingInventory(forestry.api.apiculture.IBeeHousingInventory) ArrayList(java.util.ArrayList) IApiaristTracker(forestry.api.apiculture.IApiaristTracker) IBee(forestry.api.apiculture.IBee) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) Stack(java.util.Stack) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IBeeHousingInventory

use of forestry.api.apiculture.IBeeHousingInventory in project ForestryMC by ForestryMC.

the class BeekeepingLogic method doProduction.

private static void doProduction(IBee queen, IBeeHousing beeHousing, IBeeListener beeListener) {
    // Produce and add stacks
    List<ItemStack> products = queen.produceStacks(beeHousing);
    beeListener.wearOutEquipment(1);
    IBeeHousingInventory beeInventory = beeHousing.getBeeInventory();
    for (ItemStack stack : products) {
        beeInventory.addProduct(stack, false);
    }
}
Also used : IBeeHousingInventory(forestry.api.apiculture.IBeeHousingInventory) ItemStack(net.minecraft.item.ItemStack)

Example 5 with IBeeHousingInventory

use of forestry.api.apiculture.IBeeHousingInventory in project ForestryMC by ForestryMC.

the class BeekeepingLogic method doWork.

@Override
public void doWork() {
    IBeeHousingInventory beeInventory = housing.getBeeInventory();
    ItemStack queenStack = beeInventory.getQueen();
    EnumBeeType beeType = BeeManager.beeRoot.getType(queenStack);
    if (beeType == EnumBeeType.PRINCESS) {
        tickBreed();
    } else if (beeType == EnumBeeType.QUEEN) {
        queenWorkTick(queen, queenStack);
    }
}
Also used : IBeeHousingInventory(forestry.api.apiculture.IBeeHousingInventory) ItemStack(net.minecraft.item.ItemStack) EnumBeeType(forestry.api.apiculture.EnumBeeType)

Aggregations

IBeeHousingInventory (forestry.api.apiculture.IBeeHousingInventory)6 ItemStack (net.minecraft.item.ItemStack)6 EnumBeeType (forestry.api.apiculture.EnumBeeType)3 IBee (forestry.api.apiculture.IBee)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 IApiaristTracker (forestry.api.apiculture.IApiaristTracker)1 IErrorLogic (forestry.api.core.IErrorLogic)1 IErrorState (forestry.api.core.IErrorState)1 ArrayList (java.util.ArrayList)1 Stack (java.util.Stack)1 World (net.minecraft.world.World)1