Search in sources :

Example 76 with ICitizenData

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;
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 77 with ICitizenData

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());
    }
}
Also used : AirBlock(net.minecraft.block.AirBlock) Constants(net.minecraftforge.common.util.Constants) CompoundNBT(net.minecraft.nbt.CompoundNBT) ICitizenData(com.minecolonies.api.colony.ICitizenData) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent) HashMap(java.util.HashMap) Direction(net.minecraft.util.Direction) ModBlocks(com.minecolonies.api.blocks.ModBlocks) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockMinecoloniesGrave(com.minecolonies.coremod.blocks.BlockMinecoloniesGrave) Map(java.util.Map) BlockState(net.minecraft.block.BlockState) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) ListNBT(net.minecraft.nbt.ListNBT) MAX_TICKRATE(com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickRateConstants.MAX_TICKRATE) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) MessageUtils(com.minecolonies.api.util.MessageUtils) Iterator(java.util.Iterator) Colony(com.minecolonies.coremod.colony.Colony) World(net.minecraft.world.World) GraveData(com.minecolonies.api.colony.GraveData) BlockPos(net.minecraft.util.math.BlockPos) BlockPosUtil(com.minecolonies.api.util.BlockPosUtil) Blocks(net.minecraft.block.Blocks) IGraveManager(com.minecolonies.api.colony.managers.interfaces.IGraveManager) Material(net.minecraft.block.material.Material) InventoryUtils(com.minecolonies.api.util.InventoryUtils) NbtTagConstants(com.minecolonies.api.util.constant.NbtTagConstants) IColony(com.minecolonies.api.colony.IColony) TileEntity(net.minecraft.tileentity.TileEntity) WorldUtil(com.minecolonies.api.util.WorldUtil) NotNull(org.jetbrains.annotations.NotNull) GRAVE_DECAY_BONUS(com.minecolonies.api.research.util.ResearchConstants.GRAVE_DECAY_BONUS) BlockState(net.minecraft.block.BlockState) AirBlock(net.minecraft.block.AirBlock) GraveData(com.minecolonies.api.colony.GraveData) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent)

Example 78 with ICitizenData

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());
            }
        }
    }
}
Also used : AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) Map(java.util.Map) AbstractEntityMinecoloniesMob(com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesMob)

Example 79 with ICitizenData

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;
}
Also used : StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) ICitizenData(com.minecolonies.api.colony.ICitizenData) IColony(com.minecolonies.api.colony.IColony) BuildingCook(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingCook) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent)

Example 80 with ICitizenData

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;
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData) IColony(com.minecolonies.api.colony.IColony) ItemParticleEffectMessage(com.minecolonies.coremod.network.messages.client.ItemParticleEffectMessage)

Aggregations

ICitizenData (com.minecolonies.api.colony.ICitizenData)180 NotNull (org.jetbrains.annotations.NotNull)49 BlockPos (net.minecraft.util.math.BlockPos)47 IColony (com.minecolonies.api.colony.IColony)46 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)40 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)33 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)31 ItemStack (net.minecraft.item.ItemStack)28 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)23 PlayerEntity (net.minecraft.entity.player.PlayerEntity)23 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)22 Nullable (org.jetbrains.annotations.Nullable)22 CompoundNBT (net.minecraft.nbt.CompoundNBT)18 Colony (com.minecolonies.coremod.colony.Colony)16 ArrayList (java.util.ArrayList)16 AbstractJobCrafter (com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)14 EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)14 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)13 AbstractAssignedCitizenModule (com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule)12 java.util (java.util)12