use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by ldtteam.
the class CitizenManager method registerCivilian.
@Override
public void registerCivilian(final AbstractCivilianEntity entity) {
if (entity.getCivilianID() == 0 || citizens.get(entity.getCivilianID()) == null) {
entity.remove();
return;
}
final ICitizenData data = citizens.get(entity.getCivilianID());
final Optional<AbstractEntityCitizen> existingCitizen = data.getEntity();
if (!existingCitizen.isPresent()) {
data.setEntity(entity);
entity.level.getScoreboard().addPlayerToTeam(entity.getScoreboardName(), colony.getTeam());
return;
}
if (existingCitizen.get() == entity) {
entity.level.getScoreboard().addPlayerToTeam(entity.getScoreboardName(), colony.getTeam());
return;
}
if (entity.isAlive()) {
existingCitizen.get().remove();
data.setEntity(entity);
entity.setCivilianData(data);
entity.level.getScoreboard().addPlayerToTeam(entity.getScoreboardName(), colony.getTeam());
return;
}
entity.remove();
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by ldtteam.
the class VisitorManager method registerCivilian.
@Override
public void registerCivilian(final AbstractCivilianEntity visitor) {
if (visitor.getCivilianID() == 0 || visitorMap.get(visitor.getCivilianID()) == null) {
visitor.remove();
return;
}
final ICitizenData data = visitorMap.get(visitor.getCivilianID());
final Optional<AbstractEntityCitizen> existingCitizen = data.getEntity();
if (!existingCitizen.isPresent()) {
data.setEntity(visitor);
visitor.setCivilianData(data);
return;
}
if (existingCitizen.get() == visitor) {
return;
}
if (visitor.isAlive()) {
existingCitizen.get().remove();
data.setEntity(visitor);
visitor.setCivilianData(data);
return;
}
visitor.remove();
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by ldtteam.
the class MinecoloniesAdvancedPathNavigate method moveToTree.
@Override
public TreePathResult moveToTree(final int range, final double speed, final List<ItemStorage> excludedTrees, final int dyntreesize, final IColony colony) {
@NotNull BlockPos start = AbstractPathJob.prepareStart(ourEntity);
final BlockPos buildingPos = ((AbstractEntityCitizen) mob).getCitizenColonyHandler().getWorkBuilding().getPosition();
if (BlockPosUtil.getDistance2D(buildingPos, ((AbstractEntityCitizen) mob).blockPosition()) > range * 4) {
start = buildingPos;
}
return (TreePathResult) setPathJob(new PathJobFindTree(CompatibilityUtils.getWorldFromEntity(mob), start, buildingPos, range, excludedTrees, dyntreesize, colony, ourEntity), null, speed, true);
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by ldtteam.
the class CitizenSkillHandler method levelUp.
@Override
public void levelUp(final ICitizenData data) {
// Show level-up particles
if (data.getEntity().isPresent()) {
final AbstractEntityCitizen citizen = data.getEntity().get();
Network.getNetwork().sendToTrackingEntity(new VanillaParticleMessage(citizen.getX(), citizen.getY(), citizen.getZ(), ParticleTypes.HAPPY_VILLAGER), data.getEntity().get());
}
if (data.getJob() != null) {
data.getJob().onLevelUp();
}
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by ldtteam.
the class AbstractCraftingBuildingModule method fullFillRecipe.
@Override
public boolean fullFillRecipe(final IRecipeStorage storage) {
final List<IItemHandler> handlers = building.getHandlers();
final ICitizenData data = building.getModuleMatching(WorkerBuildingModule.class, m -> m.getJobEntry() == jobEntry).getFirstCitizen();
if (data == null || !data.getEntity().isPresent()) {
// we shouldn't hit this case, but just in case...
return storage.fullfillRecipe(building.getColony().getWorld(), handlers);
}
final AbstractEntityCitizen worker = data.getEntity().get();
final int primarySkill = worker.getCitizenData().getCitizenSkillHandler().getLevel(building.getModuleMatching(WorkerBuildingModule.class, m -> m.getJobEntry() == jobEntry).getPrimarySkill());
final int luck = (int) (((primarySkill + 1) * 2) - Math.pow((primarySkill + 1) / 10.0, 2));
LootContext.Builder builder = (new LootContext.Builder((ServerWorld) building.getColony().getWorld()).withParameter(LootParameters.ORIGIN, worker.position()).withParameter(LootParameters.THIS_ENTITY, worker).withParameter(LootParameters.TOOL, worker.getMainHandItem()).withRandom(worker.getRandom()).withLuck((float) luck));
return storage.fullfillRecipe(builder.create(RecipeStorage.recipeLootParameters), handlers);
}
Aggregations