Search in sources :

Example 1 with CitizenDiedEvent

use of com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenDiedEvent in project minecolonies by ldtteam.

the class EntityCitizen method die.

/**
 * Called when the mob's health reaches 0.
 *
 * @param damageSource the attacking entity.
 */
@Override
public void die(@NotNull final DamageSource damageSource) {
    currentlyFleeing = false;
    if (citizenColonyHandler.getColony() != null && getCitizenData() != null) {
        citizenColonyHandler.getColony().getRaiderManager().onLostCitizen(getCitizenData());
        citizenExperienceHandler.dropExperience();
        this.remove();
        if (!(citizenJobHandler.getColonyJob() instanceof AbstractJobGuard)) {
            citizenColonyHandler.getColony().getCitizenManager().updateModifier("death");
        }
        triggerDeathAchievement(damageSource, citizenJobHandler.getColonyJob());
        citizenChatHandler.notifyDeath(damageSource);
        if (!(citizenJobHandler.getColonyJob() instanceof AbstractJobGuard)) {
            citizenColonyHandler.getColony().getCitizenManager().updateCitizenMourn(citizenData, true);
        }
        if (!isInvisible()) {
            if (citizenColonyHandler.getColony().isCoordInColony(level, blockPosition())) {
                getCitizenColonyHandler().getColony().getGraveManager().createCitizenGrave(level, blockPosition(), citizenData);
            } else {
                InventoryUtils.dropItemHandler(citizenData.getInventory(), level, (int) getX(), (int) getY(), (int) getZ());
            }
        }
        if (citizenData.getJob() != null) {
            citizenData.getJob().onRemoval();
        }
        citizenColonyHandler.getColony().getCitizenManager().removeCivilian(getCitizenData());
        final String deathCause = new StringTextComponent(damageSource.getLocalizedDeathMessage(this).getString()).getString().replaceFirst(this.getDisplayName().getString(), "Citizen");
        citizenColonyHandler.getColony().getEventDescriptionManager().addEventDescription(new CitizenDiedEvent(blockPosition(), citizenData.getName(), deathCause));
    }
    super.die(damageSource);
}
Also used : StringTextComponent(net.minecraft.util.text.StringTextComponent) CitizenDiedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenDiedEvent)

Example 2 with CitizenDiedEvent

use of com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenDiedEvent in project minecolonies by Minecolonies.

the class EntityCitizen method die.

/**
 * Called when the mob's health reaches 0.
 *
 * @param damageSource the attacking entity.
 */
@Override
public void die(@NotNull final DamageSource damageSource) {
    currentlyFleeing = false;
    if (citizenColonyHandler.getColony() != null && getCitizenData() != null) {
        citizenColonyHandler.getColony().getRaiderManager().onLostCitizen(getCitizenData());
        citizenExperienceHandler.dropExperience();
        this.remove();
        if (!(citizenJobHandler.getColonyJob() instanceof AbstractJobGuard)) {
            citizenColonyHandler.getColony().getCitizenManager().updateModifier("death");
        }
        triggerDeathAchievement(damageSource, citizenJobHandler.getColonyJob());
        citizenChatHandler.notifyDeath(damageSource);
        if (!(citizenJobHandler.getColonyJob() instanceof AbstractJobGuard)) {
            citizenColonyHandler.getColony().getCitizenManager().updateCitizenMourn(citizenData, true);
        }
        if (!isInvisible()) {
            if (citizenColonyHandler.getColony().isCoordInColony(level, blockPosition())) {
                getCitizenColonyHandler().getColony().getGraveManager().createCitizenGrave(level, blockPosition(), citizenData);
            } else {
                InventoryUtils.dropItemHandler(citizenData.getInventory(), level, (int) getX(), (int) getY(), (int) getZ());
            }
        }
        if (citizenData.getJob() != null) {
            citizenData.getJob().onRemoval();
        }
        citizenColonyHandler.getColony().getCitizenManager().removeCivilian(getCitizenData());
        final String deathCause = new StringTextComponent(damageSource.getLocalizedDeathMessage(this).getString()).getString().replaceFirst(this.getDisplayName().getString(), "Citizen");
        citizenColonyHandler.getColony().getEventDescriptionManager().addEventDescription(new CitizenDiedEvent(blockPosition(), citizenData.getName(), deathCause));
    }
    super.die(damageSource);
}
Also used : CitizenDiedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenDiedEvent)

Example 3 with CitizenDiedEvent

use of com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenDiedEvent in project minecolonies by Minecolonies.

the class WindowInfoPage method fillEventsList.

private void fillEventsList() {
    eventList = findPaneOfTypeByID(EVENTS_LIST, ScrollingList.class);
    eventList.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            return permissionEvents ? building.getPermissionEvents().size() : building.getColonyEvents().size();
        }

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final Text nameLabel = rowPane.findPaneOfTypeByID(NAME_LABEL, Text.class);
            final Text actionLabel = rowPane.findPaneOfTypeByID(ACTION_LABEL, Text.class);
            if (permissionEvents) {
                final List<PermissionEvent> permissionEvents = building.getPermissionEvents();
                Collections.reverse(permissionEvents);
                final PermissionEvent event = permissionEvents.get(index);
                nameLabel.setText(event.getName() + (event.getId() == null ? " <fake>" : ""));
                rowPane.findPaneOfTypeByID(POS_LABEL, Text.class).setText(event.getPosition().getX() + " " + event.getPosition().getY() + " " + event.getPosition().getZ());
                if (event.getId() == null) {
                    rowPane.findPaneOfTypeByID(BUTTON_ADD_PLAYER_OR_FAKEPLAYER, Button.class).hide();
                }
                actionLabel.setText(new TranslationTextComponent(KEY_TO_PERMISSIONS + event.getAction().toString().toLowerCase(Locale.US)));
            } else {
                final List<IColonyEventDescription> colonyEvents = building.getColonyEvents();
                Collections.reverse(colonyEvents);
                final IColonyEventDescription event = colonyEvents.get(index);
                if (event instanceof CitizenDiedEvent) {
                    actionLabel.setText(((CitizenDiedEvent) event).getDeathCause());
                } else {
                    actionLabel.setText(event.getName());
                }
                if (event instanceof ICitizenEventDescription) {
                    nameLabel.setText(((ICitizenEventDescription) event).getCitizenName());
                } else if (event instanceof IBuildingEventDescription) {
                    IBuildingEventDescription buildEvent = (IBuildingEventDescription) event;
                    nameLabel.setText(MessageUtils.format(buildEvent.getBuildingName()).append(" " + buildEvent.getLevel()).create());
                }
                rowPane.findPaneOfTypeByID(POS_LABEL, Text.class).setText(event.getEventPos().getX() + " " + event.getEventPos().getY() + " " + event.getEventPos().getZ());
                rowPane.findPaneOfTypeByID(BUTTON_ADD_PLAYER_OR_FAKEPLAYER, Button.class).hide();
            }
        }
    });
}
Also used : IBuildingEventDescription(com.minecolonies.api.colony.colonyEvents.descriptions.IBuildingEventDescription) Text(com.ldtteam.blockout.controls.Text) Pane(com.ldtteam.blockout.Pane) CitizenDiedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenDiedEvent) ICitizenEventDescription(com.minecolonies.api.colony.colonyEvents.descriptions.ICitizenEventDescription) IColonyEventDescription(com.minecolonies.api.colony.colonyEvents.descriptions.IColonyEventDescription) PermissionEvent(com.minecolonies.api.colony.permissions.PermissionEvent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ScrollingList(com.ldtteam.blockout.views.ScrollingList) ScrollingList(com.ldtteam.blockout.views.ScrollingList)

Example 4 with CitizenDiedEvent

use of com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenDiedEvent in project minecolonies by ldtteam.

the class WindowInfoPage method fillEventsList.

private void fillEventsList() {
    eventList = findPaneOfTypeByID(EVENTS_LIST, ScrollingList.class);
    eventList.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            return permissionEvents ? building.getPermissionEvents().size() : building.getColonyEvents().size();
        }

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final Text nameLabel = rowPane.findPaneOfTypeByID(NAME_LABEL, Text.class);
            final Text actionLabel = rowPane.findPaneOfTypeByID(ACTION_LABEL, Text.class);
            if (permissionEvents) {
                final PermissionEvent event = building.getPermissionEvents().get(index);
                nameLabel.setText(event.getName() + (event.getId() == null ? " <fake>" : ""));
                rowPane.findPaneOfTypeByID(POS_LABEL, Text.class).setText(event.getPosition().getX() + " " + event.getPosition().getY() + " " + event.getPosition().getZ());
                if (event.getId() == null) {
                    rowPane.findPaneOfTypeByID(BUTTON_ADD_PLAYER_OR_FAKEPLAYER, Button.class).hide();
                }
                final String name = LanguageHandler.format(KEY_TO_PERMISSIONS + event.getAction().toString().toLowerCase(Locale.US));
                if (name.contains(KEY_TO_PERMISSIONS)) {
                    Log.getLogger().warn("Didn't work for:" + name);
                    return;
                }
                actionLabel.setText(name);
            } else {
                final IColonyEventDescription event = building.getColonyEvents().get(index);
                if (event instanceof CitizenDiedEvent) {
                    actionLabel.setText(((CitizenDiedEvent) event).getDeathCause());
                } else {
                    actionLabel.setText(event.getName());
                }
                if (event instanceof ICitizenEventDescription) {
                    nameLabel.setText(((ICitizenEventDescription) event).getCitizenName());
                } else if (event instanceof IBuildingEventDescription) {
                    IBuildingEventDescription buildEvent = (IBuildingEventDescription) event;
                    nameLabel.setText(buildEvent.getBuildingName() + " " + buildEvent.getLevel());
                }
                rowPane.findPaneOfTypeByID(POS_LABEL, Text.class).setText(event.getEventPos().getX() + " " + event.getEventPos().getY() + " " + event.getEventPos().getZ());
                rowPane.findPaneOfTypeByID(BUTTON_ADD_PLAYER_OR_FAKEPLAYER, Button.class).hide();
            }
        }
    });
}
Also used : ICitizenEventDescription(com.minecolonies.api.colony.colonyEvents.descriptions.ICitizenEventDescription) IColonyEventDescription(com.minecolonies.api.colony.colonyEvents.descriptions.IColonyEventDescription) IBuildingEventDescription(com.minecolonies.api.colony.colonyEvents.descriptions.IBuildingEventDescription) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane) CitizenDiedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenDiedEvent)

Aggregations

CitizenDiedEvent (com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenDiedEvent)4 Pane (com.ldtteam.blockout.Pane)2 ScrollingList (com.ldtteam.blockout.views.ScrollingList)2 IBuildingEventDescription (com.minecolonies.api.colony.colonyEvents.descriptions.IBuildingEventDescription)2 ICitizenEventDescription (com.minecolonies.api.colony.colonyEvents.descriptions.ICitizenEventDescription)2 IColonyEventDescription (com.minecolonies.api.colony.colonyEvents.descriptions.IColonyEventDescription)2 Text (com.ldtteam.blockout.controls.Text)1 PermissionEvent (com.minecolonies.api.colony.permissions.PermissionEvent)1 StringTextComponent (net.minecraft.util.text.StringTextComponent)1 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)1