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