use of net.minecraft.entity.passive.BeeEntity in project minecolonies by ldtteam.
the class EntityAIWorkBeekeeper method decideWhatToDo.
/**
* Decides what job the beekeeper should switch to, breeding or harvesting.
*
* @return The next {@link IAIState} the beekeeper should switch to, after executing this method.
*/
private IAIState decideWhatToDo() {
setDelay(DECIDING_DELAY + (99 / getSecondarySkillLevel() - 1));
final Set<BlockPos> hives = getOwnBuilding().getHives();
if (hives.isEmpty()) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_HIVES), ChatPriority.BLOCKING));
setDelay(NO_HIVES_DELAY);
return DECIDE;
}
ItemListModule flowersModule = getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(BUILDING_FLOWER_LIST));
if (flowersModule.getList().isEmpty()) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_BEEKEEPER_NOFLOWERS), ChatPriority.BLOCKING));
setDelay(NO_FLOWERS_DELAY);
return DECIDE;
}
for (BlockPos pos : hives) {
if (!(world.getBlockState(pos).getBlock() instanceof BeehiveBlock)) {
getOwnBuilding().removeHive(pos);
}
}
final Optional<BlockPos> hive = getOwnBuilding().getHives().stream().filter(pos -> BeehiveTileEntity.getHoneyLevel(world.getBlockState(pos)) >= 5).findFirst();
if (hive.isPresent()) {
return BEEKEEPER_HARVEST;
}
final List<BeeEntity> bees = new ArrayList<>(searchForAnimals(world, getOwnBuilding()));
final JobBeekeeper job = worker.getCitizenJobHandler().getColonyJob(JobBeekeeper.class);
if (bees.isEmpty()) {
if (getBeesInHives() <= 0) {
job.tickNoBees();
if (job.checkForBeeInteraction()) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_BEES), ChatPriority.BLOCKING));
}
} else {
job.resetCounter();
}
setDelay(NO_ANIMALS_DELAY);
return DECIDE;
} else {
job.resetCounter();
}
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(TranslationConstants.COM_MINECOLONIES_COREMOD_STATUS_DECIDING));
final int breedableAnimals = (int) bees.stream().filter(animal -> animal.getAge() == 0).count();
final boolean hasBreedingItem = InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), (stack) -> flowersModule.isItemInList(new ItemStorage(stack)));
if (getOwnBuilding().getSetting(BuildingBeekeeper.BREEDING).getValue() && !hasMaxAnimals(bees) && breedableAnimals >= NUM_OF_ANIMALS_TO_BREED && hasBreedingItem) {
return HERDER_BREED;
}
return START_WORKING;
}
use of net.minecraft.entity.passive.BeeEntity in project minecolonies by ldtteam.
the class EntityAIWorkBeekeeper method breedAnimals.
/**
* Breed some animals together.
*
* @return The next {@link IAIState}.
*/
private IAIState breedAnimals() {
setDelay(BREEDING_DELAY);
final List<BeeEntity> animals = searchForAnimals(world, getOwnBuilding());
final AnimalEntity animalOne = animals.stream().filter(animal -> !animal.isBaby()).findAny().orElse(null);
if (animalOne == null) {
return DECIDE;
}
final AnimalEntity animalTwo = animals.stream().filter(animal -> {
final float range = animal.distanceTo(animalOne);
final boolean isAnimalOne = animalOne.equals(animal);
return animal.getAge() == 0 && range <= DISTANCE_TO_BREED && !isAnimalOne;
}).findAny().orElse(null);
if (animalTwo == null) {
return DECIDE;
}
if (!equipBreedItem(Hand.MAIN_HAND)) {
return START_WORKING;
}
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(TranslationConstants.COM_MINECOLONIES_COREMOD_STATUS_HERDER_BREEDING));
breedTwoAnimals(animalOne, animalTwo);
incrementActionsDoneAndDecSaturation();
return DECIDE;
}
use of net.minecraft.entity.passive.BeeEntity in project friends-and-foes by Faboslav.
the class BeeEntityMixin method addPollinateMoobloomGoal.
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/ai/goal/GoalSelector;add(ILnet/minecraft/entity/ai/goal/Goal;)V", ordinal = 4, shift = At.Shift.AFTER), method = "initGoals")
private void addPollinateMoobloomGoal(CallbackInfo ci) {
this.pollinateMoobloomGoal = new BeePollinateMoobloomGoal((BeeEntity) (Object) this, (BeeEntityAccessor) this);
this.goalSelector.add(3, this.pollinateMoobloomGoal);
}
use of net.minecraft.entity.passive.BeeEntity in project minecolonies by Minecolonies.
the class EntityAIWorkBeekeeper method breedAnimals.
/**
* Breed some animals together.
*
* @return The next {@link IAIState}.
*/
private IAIState breedAnimals() {
setDelay(BREEDING_DELAY);
final List<BeeEntity> animals = searchForAnimals(world, getOwnBuilding());
final AnimalEntity animalOne = animals.stream().filter(animal -> !animal.isBaby()).findAny().orElse(null);
if (animalOne == null) {
return DECIDE;
}
final AnimalEntity animalTwo = animals.stream().filter(animal -> {
final float range = animal.distanceTo(animalOne);
final boolean isAnimalOne = animalOne.equals(animal);
return animal.getAge() == 0 && range <= DISTANCE_TO_BREED && !isAnimalOne;
}).findAny().orElse(null);
if (animalTwo == null) {
return DECIDE;
}
if (!equipBreedItem(Hand.MAIN_HAND)) {
return START_WORKING;
}
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(TranslationConstants.COM_MINECOLONIES_COREMOD_STATUS_HERDER_BREEDING));
breedTwoAnimals(animalOne, animalTwo);
incrementActionsDoneAndDecSaturation();
return DECIDE;
}
use of net.minecraft.entity.passive.BeeEntity in project minecolonies by Minecolonies.
the class EntityAIWorkBeekeeper method harvestHoney.
/**
* Harvest honey/honeycomb from full beehives.
*
* @return The next {@link IAIState}.
*/
private IAIState harvestHoney() {
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_BEEKEEPER_HARVESTING));
final List<BlockPos> hives = getOwnBuilding().getHives().stream().filter(pos -> BeehiveTileEntity.getHoneyLevel(world.getBlockState(pos)) >= 5).collect(Collectors.toList());
if (hives.isEmpty()) {
return DECIDE;
}
if (getOwnBuilding().getHarvestTypes().equals(BuildingBeekeeper.HONEYCOMB) || (getOwnBuilding().getHarvestTypes().equals(BuildingBeekeeper.BOTH) && lastHarvestedBottle)) {
if (!equipTool(Hand.MAIN_HAND, ToolType.SHEARS)) {
return PREPARING;
}
} else {
if (!equipItem(Hand.MAIN_HAND, new ItemStack(Items.GLASS_BOTTLE))) {
return PREPARING;
}
}
final BlockPos hive = hives.get(0);
if (!world.getBlockState(hive).is(BlockTags.BEEHIVES)) {
getOwnBuilding().removeHive(hive);
return PREPARING;
}
if (walkToBlock(hive)) {
return getState();
}
worker.swing(Hand.MAIN_HAND);
final ItemStack itemStack = worker.getMainHandItem();
if (!getOwnBuilding().getHarvestTypes().equals(BuildingBeekeeper.HONEY) && ItemStackUtils.isTool(itemStack, ToolType.SHEARS)) {
worker.getCitizenItemHandler().damageItemInHand(Hand.MAIN_HAND, 1);
for (ItemStack stackItem : Compatibility.getCombsFromHive(hive, world, getHoneycombsPerHarvest())) {
InventoryUtils.transferItemStackIntoNextBestSlotInItemHandler(stackItem, worker.getItemHandlerCitizen());
}
world.setBlockAndUpdate(hive, world.getBlockState(hive).setValue(BlockStateProperties.LEVEL_HONEY, 0));
worker.getCitizenExperienceHandler().addExperience(EXP_PER_HARVEST);
lastHarvestedBottle = false;
} else if (!getOwnBuilding().getHarvestTypes().equals(BuildingBeekeeper.HONEYCOMB) && itemStack.getItem() == Items.GLASS_BOTTLE) {
int i;
for (i = 0; i < getHoneyBottlesPerHarvest() && !itemStack.isEmpty(); i++) {
itemStack.shrink(1);
}
InventoryUtils.transferItemStackIntoNextBestSlotInItemHandler(new ItemStack(Items.HONEY_BOTTLE, i), worker.getItemHandlerCitizen());
world.setBlockAndUpdate(hive, world.getBlockState(hive).setValue(BlockStateProperties.LEVEL_HONEY, 0));
worker.getCitizenExperienceHandler().addExperience(EXP_PER_HARVEST);
lastHarvestedBottle = true;
}
final int dex = getPrimarySkillLevel();
if ((50 - (dex / 99. * 50.)) / 100 > worker.getRandom().nextDouble()) {
final List<Entity> bees = ((BeehiveTileEntity) world.getBlockEntity(hive)).releaseAllOccupants(world.getBlockState(hive), BeehiveTileEntity.State.EMERGENCY);
bees.stream().filter(entity -> entity instanceof BeeEntity).map(entity -> (BeeEntity) entity).filter(bee -> worker.position().distanceToSqr(bee.position()) <= 16.0D).forEach(bee -> {
bee.setRemainingPersistentAngerTime(400 + worker.getRandom().nextInt(400));
bee.setLastHurtByMob(worker);
});
}
incrementActionsDoneAndDecSaturation();
return START_WORKING;
}
Aggregations