use of com.minecolonies.coremod.colony.jobs.AbstractJobGuard in project minecolonies by Minecolonies.
the class EventListener method onUpdateEntityRadar.
@SubscribeEvent
public void onUpdateEntityRadar(@NotNull final EntityRadarUpdateEvent event) {
final WrappedEntity wrapper = event.getWrappedEntity();
final LivingEntity entity = wrapper.getEntityLivingRef().get();
if (entity instanceof AbstractEntityCitizen) {
final boolean isVisitor = entity instanceof VisitorCitizen;
TextComponent jobName;
if (isVisitor) {
if (!JourneymapOptions.getShowVisitors(this.jmap.getOptions())) {
wrapper.setDisable(true);
return;
}
jobName = new TranslationTextComponent(COM_MINECOLONIES_JMAP_PREFIX + "visitor");
} else {
final String jobId = entity.getEntityData().get(DATA_JOB);
final JobEntry jobEntry = IJobRegistry.getInstance().getValue(new ResourceLocation(jobId));
final IJob<?> job = jobEntry == null ? null : jobEntry.produceJob(null);
if (job instanceof AbstractJobGuard ? !JourneymapOptions.getShowGuards(this.jmap.getOptions()) : !JourneymapOptions.getShowCitizens(this.jmap.getOptions())) {
wrapper.setDisable(true);
return;
}
jobName = new TranslationTextComponent(jobEntry == null ? COM_MINECOLONIES_JMAP_PREFIX + "unemployed" : jobEntry.getTranslationKey());
}
if (JourneymapOptions.getShowColonistTooltip(this.jmap.getOptions())) {
ITextComponent name = entity.getCustomName();
if (name != null) {
wrapper.setEntityToolTips(Arrays.asList(name, jobName.setStyle(JOB_TOOLTIP)));
}
}
final boolean showName = event.getActiveUiState().ui.equals(Context.UI.Minimap) ? JourneymapOptions.getShowColonistNameMinimap(this.jmap.getOptions()) : JourneymapOptions.getShowColonistNameFullscreen(this.jmap.getOptions());
if (!showName) {
wrapper.setCustomName("");
}
if (!isVisitor && JourneymapOptions.getShowColonistTeamColour(this.jmap.getOptions())) {
wrapper.setColor(entity.getTeamColor());
}
}
}
use of com.minecolonies.coremod.colony.jobs.AbstractJobGuard in project minecolonies by Minecolonies.
the class ItemScrollGuardHelp method onItemUseSuccess.
@Override
protected ItemStack onItemUseSuccess(final ItemStack itemStack, final World world, final ServerPlayerEntity player) {
final IColony colony = getColony(itemStack);
final BlockPos buildingPos = BlockPosUtil.read(itemStack.getTag(), TAG_BUILDING_POS);
final IBuilding building = colony.getBuildingManager().getBuilding(buildingPos);
if (!(building instanceof AbstractBuildingGuards)) {
LanguageHandler.sendPlayerMessage(player, "minecolonies.scroll.noguardbuilding");
return itemStack;
}
itemStack.shrink(1);
final List<ICitizenData> guards = new ArrayList<>(building.getAllAssignedCitizen());
if (world.random.nextInt(10) == 0 || colony.getWorld() != world) {
// Fail
final LlamaEntity entity = EntityType.LLAMA.create(world);
entity.setPos(player.getX(), player.getY(), player.getZ());
world.addFreshEntity(entity);
player.displayClientMessage(new TranslationTextComponent("minecolonies.scroll.failed" + (world.random.nextInt(FAIL_RESPONSES_TOTAL) + 1)).setStyle(Style.EMPTY.withColor(TextFormatting.GOLD)), true);
SoundUtils.playSoundForPlayer(player, SoundEvents.EVOKER_CAST_SPELL, 0.5f, 1.0f);
return itemStack;
} else {
for (final ICitizenData citizenData : guards) {
final AbstractJobGuard job = citizenData.getJob(AbstractJobGuard.class);
if (job != null && job.getWorkerAI() != null && !((AbstractEntityAIGuard) job.getWorkerAI()).hasTool()) {
continue;
}
if (citizenData.getEntity().isPresent()) {
if (citizenData.getEntity().get().getCitizenDiseaseHandler().isSick()) {
continue;
}
citizenData.getEntity().get().remove();
}
colony.getCitizenManager().spawnOrCreateCivilian(citizenData, world, player.blockPosition(), true);
citizenData.setNextRespawnPosition(buildingPos);
((AbstractBuildingGuards) building).getSetting(AbstractBuildingGuards.GUARD_TASK).set(GuardTaskSetting.FOLLOW);
((AbstractBuildingGuards) building).setPlayerToFollow(player);
final FollowModeSetting grouping = ((AbstractBuildingGuards) building).getSetting(AbstractBuildingGuards.FOLLOW_MODE);
if (grouping.getValue().equals(FollowModeSetting.LOOSE)) {
grouping.trigger();
}
citizenData.setSaturation(100);
colony.getPackageManager().addCloseSubscriber(player);
if (job != null && job.getWorkerAI() != null) {
final long spawnTime = world.getGameTime() + TICKS_SECOND * 900;
// Timed despawn
job.getWorkerAI().registerTarget(new AIOneTimeEventTarget(() -> {
if (world.getGameTime() - spawnTime > 0) {
((AbstractBuildingGuards) building).getSetting(AbstractBuildingGuards.GUARD_TASK).set(GuardTaskSetting.PATROL);
citizenData.getEntity().ifPresent(Entity::remove);
colony.getPackageManager().removeCloseSubscriber(player);
return true;
}
return false;
}, AIWorkerState.DECIDE));
}
}
SoundUtils.playSoundForPlayer(player, SoundEvents.UI_TOAST_CHALLENGE_COMPLETE, 0.3f, 1.0f);
}
return itemStack;
}
use of com.minecolonies.coremod.colony.jobs.AbstractJobGuard in project minecolonies by Minecolonies.
the class CitizenHappinessHandler method getGuardFactor.
/**
* Get the guard security happiness modifier from the colony.
*
* @param colony the colony.
* @return true if so.
*/
private double getGuardFactor(final IColony colony) {
double guards = 1;
double workers = 1;
for (final ICitizenData citizen : colony.getCitizenManager().getCitizens()) {
if (citizen.getJob() instanceof AbstractJobGuard) {
guards++;
} else {
workers++;
}
}
return Math.min(guards / (workers * 2 / 3), 2);
}
use of com.minecolonies.coremod.colony.jobs.AbstractJobGuard in project minecolonies by Minecolonies.
the class ColonyPermissionEventHandler method on.
/**
* AttackEntityEvent handler.
* <p>
* Check, if a player tries to attack an entity.. Deny if: - If the attacking happens in the colony - Player is less than officer to the colony.
*
* @param event ItemEntityPickupEvent
*/
@SubscribeEvent
public void on(final AttackEntityEvent event) {
if (event.getTarget() instanceof MonsterEntity) {
return;
}
@NotNull final PlayerEntity player = EntityUtils.getPlayerOfFakePlayer(event.getPlayer(), event.getPlayer().getCommandSenderWorld());
if (MineColonies.getConfig().getServer().enableColonyProtection.get() && colony.isCoordInColony(player.getCommandSenderWorld(), new BlockPos(player.position()))) {
final Permissions perms = colony.getPermissions();
if (event.getTarget() instanceof EntityCitizen) {
final AbstractEntityCitizen citizen = (AbstractEntityCitizen) event.getTarget();
if (citizen.getCitizenJobHandler().getColonyJob() instanceof AbstractJobGuard && perms.hasPermission(event.getPlayer(), Action.GUARDS_ATTACK)) {
return;
}
if (perms.hasPermission(event.getPlayer(), Action.ATTACK_CITIZEN)) {
return;
}
cancelEvent(event, event.getPlayer(), colony, Action.ATTACK_CITIZEN, new BlockPos(event.getTarget().position()));
return;
}
if (!(event.getTarget() instanceof MobEntity) && !perms.hasPermission(event.getPlayer(), Action.ATTACK_ENTITY)) {
cancelEvent(event, event.getPlayer(), colony, Action.ATTACK_ENTITY, new BlockPos(event.getTarget().position()));
}
}
}
use of com.minecolonies.coremod.colony.jobs.AbstractJobGuard in project minecolonies by ldtteam.
the class AbstractBuildingGuards method startPatrolNext.
/**
* Starts the patrol to the next point
*/
private void startPatrolNext() {
getNextPatrolTarget(true);
patrolTimer = 5;
for (final ICitizenData curguard : getAllAssignedCitizen()) {
if (curguard.getEntity().isPresent()) {
if (curguard.getEntity().get().getCitizenJobHandler().getColonyJob() instanceof AbstractJobGuard) {
((AbstractEntityAIGuard<?, ?>) curguard.getEntity().get().getCitizenJobHandler().getColonyJob().getWorkerAI()).setNextPatrolTarget(lastPatrolPoint);
}
}
}
arrivedAtPatrol.clear();
}
Aggregations