use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class CitizenManager method deserializeCitizen.
/**
* Creates a citizen data from NBT
*
* @param compound NBT
* @return citizen data
*/
private ICitizenData deserializeCitizen(@NotNull final CompoundNBT compound) {
final ICitizenData data = ICitizenDataManager.getInstance().createFromNBT(compound, colony);
topCitizenId = Math.max(topCitizenId, data.getId());
return data;
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class GraveManager method createCitizenGrave.
/**
* Attempt to create a TileEntityGrave at @pos containing the specific @citizenData
* <p>
* On failure: drop all the citizen inventory on the ground.
*
* @param world The world.
* @param pos The position where to spawn a grave
* @param citizenData The citizenData
*/
@Override
public void createCitizenGrave(final World world, final BlockPos pos, final ICitizenData citizenData) {
final BlockState here = world.getBlockState(pos);
if (here.getBlock() == Blocks.LAVA) {
MessageUtils.format(WARNING_GRAVE_LAVA).sendTo(colony).forManagers();
return;
}
BlockPos firstValidPosition = null;
if (here.getBlock() == Blocks.WATER) {
for (int i = 1; i <= 10; i++) {
if (world.getBlockState(pos.above(i)).getBlock() instanceof AirBlock) {
firstValidPosition = searchShore(world, pos.above(i));
break;
}
}
if (firstValidPosition == null) {
MessageUtils.format(WARNING_GRAVE_WATER).sendTo(colony).forManagers();
}
} else {
firstValidPosition = BlockPosUtil.findAround(world, pos, 10, 10, (blockAccess, current) -> blockAccess.getBlockState(current).getMaterial() == Material.AIR && blockAccess.getBlockState(current.below()).getMaterial().isSolid());
}
if (firstValidPosition != null) {
world.setBlockAndUpdate(firstValidPosition, BlockMinecoloniesGrave.getPlacementState(ModBlocks.blockGrave.defaultBlockState(), new TileEntityGrave(), firstValidPosition));
final TileEntityGrave graveEntity = (TileEntityGrave) world.getBlockEntity(firstValidPosition);
if (!InventoryUtils.transferAllItemHandler(citizenData.getInventory(), graveEntity.getInventory())) {
InventoryUtils.dropItemHandler(citizenData.getInventory(), world, pos.getX(), pos.getY(), pos.getZ());
}
graveEntity.delayDecayTimer(colony.getResearchManager().getResearchEffects().getEffectStrength(GRAVE_DECAY_BONUS));
GraveData graveData = new GraveData();
graveData.setCitizenName(citizenData.getName());
if (citizenData.getJob() != null) {
final IFormattableTextComponent jobName = new TranslationTextComponent(citizenData.getJob().getJobRegistryEntry().getTranslationKey().toLowerCase());
graveData.setCitizenJobName(jobName.getString());
}
graveData.setCitizenDataNBT(citizenData.serializeNBT());
graveEntity.setGraveData(graveData);
colony.getGraveManager().addNewGrave(firstValidPosition);
MessageUtils.format(WARNING_GRAVE_SPAWNED).sendTo(colony).forManagers();
} else {
InventoryUtils.dropItemHandler(citizenData.getInventory(), world, pos.getX(), pos.getY(), pos.getZ());
}
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class CombatUtils method notifyGuardsOfTarget.
/**
* Actions on changing to a new target entity
*/
public static void notifyGuardsOfTarget(final AbstractEntityCitizen user, final LivingEntity target, final int callRange) {
for (final ICitizenData citizen : user.getCitizenData().getWorkBuilding().getAllAssignedCitizen()) {
if (citizen.getEntity().isPresent() && citizen.getEntity().get().getLastHurtByMob() == null) {
((EntityCitizen) citizen.getEntity().get()).getThreatTable().addThreat(target, 0);
}
}
if (target instanceof AbstractEntityMinecoloniesMob) {
for (final Map.Entry<BlockPos, IBuilding> entry : user.getCitizenColonyHandler().getColony().getBuildingManager().getBuildings().entrySet()) {
if (entry.getValue() instanceof AbstractBuildingGuards && user.blockPosition().distSqr(entry.getKey()) < callRange) {
final AbstractBuildingGuards building = (AbstractBuildingGuards) entry.getValue();
building.setTempNextPatrolPoint(target.blockPosition());
}
}
}
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class EntityAIEatTask method searchRestaurant.
/**
* Search for a placeToPath within the colony of the citizen.
*
* @return the next state to go to.
*/
private EatingState searchRestaurant() {
final ICitizenData citizenData = citizen.getCitizenData();
final IColony colony = citizenData.getColony();
if (citizenData.getWorkBuilding() != null) {
restaurantPos = colony.getBuildingManager().getBestBuilding(citizenData.getWorkBuilding().getPosition(), BuildingCook.class);
} else if (citizenData.getHomeBuilding() != null) {
restaurantPos = colony.getBuildingManager().getBestBuilding(citizenData.getHomeBuilding().getPosition(), BuildingCook.class);
} else {
restaurantPos = colony.getBuildingManager().getBestBuilding(citizen, BuildingCook.class);
}
final IJob<?> job = citizen.getCitizenJobHandler().getColonyJob();
if (job != null && citizenData.isWorking()) {
citizenData.setWorking(false);
}
if (restaurantPos == null) {
citizenData.triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_RESTAURANT), ChatPriority.BLOCKING));
return CHECK_FOR_FOOD;
}
return GO_TO_RESTAURANT;
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class EntityAIEatTask method eat.
/**
* Actual action of eating.
*
* @return the next state to go to, if successful idle.
*/
private EatingState eat() {
if (!hasFood()) {
return CHECK_FOR_FOOD;
}
final ICitizenData citizenData = citizen.getCitizenData();
final ItemStack stack = citizenData.getInventory().getStackInSlot(foodSlot);
if (!CAN_EAT.test(stack) || !canEat(citizenData, stack)) {
return CHECK_FOR_FOOD;
}
citizen.setItemInHand(Hand.MAIN_HAND, stack);
citizen.swing(Hand.MAIN_HAND);
citizen.playSound(SoundEvents.GENERIC_EAT, (float) BASIC_VOLUME, (float) SoundUtils.getRandomPitch(citizen.getRandom()));
Network.getNetwork().sendToTrackingEntity(new ItemParticleEffectMessage(citizen.getMainHandItem(), citizen.getX(), citizen.getY(), citizen.getZ(), citizen.xRot, citizen.yRot, citizen.getEyeHeight()), citizen);
waitingTicks++;
if (waitingTicks < REQUIRED_TIME_TO_EAT) {
return EAT;
}
final Food itemFood = stack.getItem().getFoodProperties();
Item containerItem = stack.getItem().getCraftingRemainingItem();
if (containerItem == null && stack.getItem() instanceof SoupItem) {
containerItem = Items.BOWL;
}
final double satIncrease = itemFood.getNutrition() * (1.0 + citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SATURATION));
citizenData.increaseSaturation(satIncrease / 2.0);
citizenData.getInventory().extractItem(foodSlot, 1, false);
if (containerItem != null && !(containerItem instanceof AirItem)) {
if (citizenData.getInventory().isFull()) {
InventoryUtils.spawnItemStack(citizen.level, citizen.getX(), citizen.getY(), citizen.getZ(), new ItemStack(containerItem, 1));
} else {
InventoryUtils.addItemStackToItemHandler(citizenData.getInventory(), new ItemStack(containerItem, 1));
}
}
IColony citizenColony = citizen.getCitizenColonyHandler().getColony();
if (citizenColony != null) {
AdvancementUtils.TriggerAdvancementPlayersForColony(citizenColony, playerMP -> AdvancementTriggers.CITIZEN_EAT_FOOD.trigger(playerMP, stack));
}
citizenData.markDirty();
citizen.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
if (citizenData.getSaturation() < CitizenConstants.FULL_SATURATION && !citizenData.getInventory().getStackInSlot(foodSlot).isEmpty()) {
waitingTicks = 0;
return EAT;
}
return IDLE;
}
Aggregations