use of net.minecraft.entity.passive.BeeEntity in project beebuddy by queenofthebees.
the class BeeEntityMixin method makePrideChild.
@Inject(method = "createChild", at = @At("HEAD"), cancellable = true)
private void makePrideChild(ServerWorld world, PassiveEntity entity, CallbackInfoReturnable<BeeEntity> cbir) {
if (entity instanceof BeeEntity) {
IFriendlyBee partner = (IFriendlyBee) (Object) entity;
BeeEntity child = (BeeEntity) EntityType.BEE.create(world);
IFriendlyBee fchild = (IFriendlyBee) (Object) child;
String ours = beebuddy$getNectarType();
String theirs = partner.beebuddy$getNectarType();
fchild.beebuddy$setNectarType(this.random.nextBoolean() ? ours : theirs);
if (beebuddy$getFriend().equals(partner.beebuddy$getFriend())) {
beebuddy$getFriend().ifPresent(u -> {
fchild.beebuddy$setFriend(Optional.of(u));
fchild.beebuddy$friendify();
});
}
cbir.setReturnValue(child);
}
}
use of net.minecraft.entity.passive.BeeEntity in project minecolonies by ldtteam.
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