use of net.minecraft.entity.passive.BeeEntity in project minecolonies by Minecolonies.
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 Arclight by IzzelAliz.
the class BeehiveTileEntityMixin method arclight$beeEnterBlock.
@Inject(method = "tryEnterHive(Lnet/minecraft/entity/Entity;ZI)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;stopRiding()V"))
private void arclight$beeEnterBlock(Entity entity, boolean p_226962_2_, int p_226962_3_, CallbackInfo ci) {
if (this.world != null) {
EntityEnterBlockEvent event = new EntityEnterBlockEvent(((EntityBridge) entity).bridge$getBukkitEntity(), CraftBlock.at(this.world, this.getPos()));
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
if (entity instanceof BeeEntity) {
((BeeEntity) entity).setStayOutOfHiveCountdown(400);
}
ci.cancel();
}
}
}
use of net.minecraft.entity.passive.BeeEntity in project beebuddy by queenofthebees.
the class BeeEntityMixin method tame.
@Override
protected void tame(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cbir) {
ItemStack stack = player.getStackInHand(hand);
boolean friend = beebuddy$getFriend().map(player.getUuid()::equals).orElse(false);
if (!this.world.isClient) {
if (stack.getItem() == Items.HONEY_BOTTLE) {
if (friend && this.getHealth() < this.getMaxHealth()) {
if (!player.abilities.creativeMode) {
stack.decrement(1);
}
this.heal(this.getMaxHealth());
cbir.setReturnValue(ActionResult.SUCCESS);
} else if (!friend && !beebuddy$hasFriend()) {
if (!player.abilities.creativeMode) {
stack.decrement(1);
ItemStack g = new ItemStack(Items.GLASS_BOTTLE);
if (stack.isEmpty()) {
player.setStackInHand(hand, g);
} else if (!player.inventory.insertStack(g)) {
player.dropItem(g, false);
}
}
if (this.random.nextInt(4) == 0) {
beebuddy$setFriend(Optional.of(player.getUuid()));
if (player instanceof ServerPlayerEntity) {
ServerPlayerEntity p = (ServerPlayerEntity) player;
Criteria.TAME_ANIMAL.trigger(p, (BeeEntity) (Object) this);
}
beebuddy$friendify();
this.world.sendEntityStatus(this, (byte) 7);
} else {
this.world.sendEntityStatus(this, (byte) 6);
}
cbir.setReturnValue(ActionResult.SUCCESS);
}
} else if (stack.getItem() instanceof NectarItem) {
NectarItem n = (NectarItem) stack.getItem();
if (friend || !beebuddy$hasFriend()) {
if (!player.abilities.creativeMode) {
stack.decrement(1);
}
beebuddy$setNectarType(n.getType());
cbir.setReturnValue(ActionResult.SUCCESS);
}
} else {
beebuddy$setSitting(!beebuddy$isSitting());
cbir.setReturnValue(ActionResult.SUCCESS);
}
} else if (friend || stack.getItem() == Items.HONEY_BOTTLE) {
cbir.setReturnValue(ActionResult.CONSUME);
} else if (stack.getItem() instanceof NectarItem) {
cbir.setReturnValue(ActionResult.CONSUME);
}
}
use of net.minecraft.entity.passive.BeeEntity in project beebuddy by queenofthebees.
the class BeeEntityMixin method doAceReproduction.
@Override
protected void doAceReproduction(PlayerEntity player, CallbackInfo cbi) {
if (beebuddy$getNectarType().equals("ace")) {
if (this.world instanceof ServerWorld) {
BeeEntity us = (BeeEntity) (Object) this;
us.breed((ServerWorld) this.world, us);
us.setBaby(true);
}
}
}
use of net.minecraft.entity.passive.BeeEntity in project beebuddy by queenofthebees.
the class BeeEntityMixin method beebuddy$initTamedGoals.
@Unique
private void beebuddy$initTamedGoals() {
BeeEntity us = (BeeEntity) (Object) this;
this.goalSelector.add(0, new BeeSitGoal(us));
this.goalSelector.add(1, StingGoalInvoker.beebuddy$make(us, us, 1.399999976158142D, true));
this.goalSelector.add(2, new FollowParentGoal(us, 1.25D));
this.goalSelector.add(3, new FollowFriendGoal(us));
this.goalSelector.add(4, new AnimalMateGoal(us, 1.0D));
if (pollinateGoal == null) {
// we can be called before initGoals's body
pollinateGoal = PollinateGoalInvoker.beebuddy$make(us);
}
this.goalSelector.add(5, pollinateGoal);
if (moveToFlowerGoal == null) {
moveToFlowerGoal = MoveToFlowerGoalInvoker.beebuddy$make(us);
}
this.goalSelector.add(6, moveToFlowerGoal);
this.goalSelector.add(7, new SitOnHeadGoal(us));
this.goalSelector.add(7, BeeWanderAroundGoalInvoker.beebuddy$make(us));
this.goalSelector.add(8, new LookAtEntityGoal(us, PlayerEntity.class, 4.0F));
this.goalSelector.add(8, new SwimGoal(us));
BeeEntityMixin mix = this;
this.targetSelector.add(1, (new RevengeGoal(this) {
@Override
public boolean canStart() {
if (!super.canStart()) {
return false;
}
if (us.getAttacker() != null) {
UUID u = us.getAttacker().getUuid();
return !u.equals(mix.beebuddy$getFriend());
} else {
return true;
}
}
@Override
public boolean shouldContinue() {
return us.hasAngerTime() && super.shouldContinue();
}
}).setGroupRevenge(new Class[0]));
}
Aggregations