Search in sources :

Example 6 with IColonyEvent

use of com.minecolonies.api.colony.colonyEvents.IColonyEvent in project minecolonies by Minecolonies.

the class HordeRaidEvent method sendHordeMessage.

/**
 * Sends the right horde message.
 */
protected void sendHordeMessage() {
    int total = 0;
    for (IColonyEvent event : colony.getEventManager().getEvents().values()) {
        if (event instanceof HordeRaidEvent) {
            total += ((HordeRaidEvent) event).horde.hordeSize;
        }
    }
    raidBar.setPercent((float) horde.hordeSize / horde.initialSize);
    if (total == 0) {
        MessageUtils.format(ALL_BARBARIANS_KILLED_MESSAGE, colony.getName()).sendTo(colony).forManagers();
        PlayAudioMessage audio = new PlayAudioMessage(horde.initialSize <= SMALL_HORDE_SIZE ? RaidSounds.VICTORY_EARLY : RaidSounds.VICTORY, SoundCategory.RECORDS);
        PlayAudioMessage.sendToAll(getColony(), false, true, audio);
        if (colony.getRaiderManager().getLostCitizen() == 0) {
            colony.getCitizenManager().updateModifier("raidwithoutdeath");
        }
    } else if (total > 0 && total <= SMALL_HORDE_SIZE) {
        MessageUtils.format(ONLY_X_BARBARIANS_LEFT_MESSAGE, total).sendTo(colony).forManagers();
    }
}
Also used : IColonyEvent(com.minecolonies.api.colony.colonyEvents.IColonyEvent) PlayAudioMessage(com.minecolonies.coremod.network.messages.client.PlayAudioMessage)

Example 7 with IColonyEvent

use of com.minecolonies.api.colony.colonyEvents.IColonyEvent in project minecolonies by Minecolonies.

the class EventManager method readFromNBT.

@Override
public void readFromNBT(@NotNull final CompoundNBT compound) {
    if (compound.contains(TAG_EVENT_MANAGER)) {
        final CompoundNBT eventManagerNBT = compound.getCompound(TAG_EVENT_MANAGER);
        final ListNBT eventListNBT = eventManagerNBT.getList(TAG_EVENT_LIST, Constants.NBT.TAG_COMPOUND);
        for (final INBT base : eventListNBT) {
            final CompoundNBT tagCompound = (CompoundNBT) base;
            final ResourceLocation eventTypeID = new ResourceLocation(MOD_ID, tagCompound.getString(TAG_NAME));
            final ColonyEventTypeRegistryEntry registryEntry = MinecoloniesAPIProxy.getInstance().getColonyEventRegistry().getValue(eventTypeID);
            if (registryEntry == null) {
                Log.getLogger().warn("Event is missing registryEntry!:" + eventTypeID.getPath());
                continue;
            }
            final IColonyEvent colonyEvent = registryEntry.deserializeEvent(colony, tagCompound);
            events.put(colonyEvent.getID(), colonyEvent);
        }
        currentEventID = eventManagerNBT.getInt(TAG_EVENT_ID);
        structureManager.readFromNBT(compound);
    }
}
Also used : IColonyEvent(com.minecolonies.api.colony.colonyEvents.IColonyEvent) ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) INBT(net.minecraft.nbt.INBT) ResourceLocation(net.minecraft.util.ResourceLocation) ColonyEventTypeRegistryEntry(com.minecolonies.api.colony.colonyEvents.registry.ColonyEventTypeRegistryEntry)

Example 8 with IColonyEvent

use of com.minecolonies.api.colony.colonyEvents.IColonyEvent in project minecolonies by Minecolonies.

the class EventManager method registerEntity.

/**
 * Registers an entity with the given event.
 *
 * @param entity  the entity to register.
 * @param eventID the event id to register it to.
 */
@Override
public void registerEntity(@NotNull final Entity entity, final int eventID) {
    final IColonyEvent event = events.get(eventID);
    if (!(event instanceof IColonyEntitySpawnEvent)) {
        entity.remove();
        return;
    }
    ((IColonyEntitySpawnEvent) event).registerEntity(entity);
}
Also used : IColonyEvent(com.minecolonies.api.colony.colonyEvents.IColonyEvent) IColonyEntitySpawnEvent(com.minecolonies.api.colony.colonyEvents.IColonyEntitySpawnEvent)

Example 9 with IColonyEvent

use of com.minecolonies.api.colony.colonyEvents.IColonyEvent in project minecolonies by Minecolonies.

the class EventManager method writeToNBT.

@Override
public void writeToNBT(@NotNull final CompoundNBT compound) {
    final CompoundNBT eventManagerNBT = new CompoundNBT();
    final ListNBT eventListNBT = new ListNBT();
    for (final IColonyEvent event : events.values()) {
        final CompoundNBT eventNBT = event.serializeNBT();
        eventNBT.putString(TAG_NAME, event.getEventTypeID().getPath());
        eventListNBT.add(eventNBT);
    }
    eventManagerNBT.putInt(TAG_EVENT_ID, currentEventID);
    eventManagerNBT.put(TAG_EVENT_LIST, eventListNBT);
    compound.put(TAG_EVENT_MANAGER, eventManagerNBT);
    structureManager.writeToNBT(compound);
}
Also used : IColonyEvent(com.minecolonies.api.colony.colonyEvents.IColonyEvent) ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT)

Example 10 with IColonyEvent

use of com.minecolonies.api.colony.colonyEvents.IColonyEvent in project minecolonies by Minecolonies.

the class EventManager method onColonyTick.

/**
 * Updates the current events.
 *
 * @param colony the colony being ticked.
 */
@Override
public void onColonyTick(@NotNull final IColony colony) {
    final Iterator<IColonyEvent> iterator = events.values().iterator();
    while (iterator.hasNext()) {
        final IColonyEvent event = iterator.next();
        if (event.getStatus() == DONE) {
            event.onFinish();
            structureManager.loadBackupForEvent(event.getID());
            colony.markDirty();
            iterator.remove();
        } else if (event.getStatus() == STARTING) {
            event.onStart();
        } else if (event.getStatus() == CANCELED) {
            colony.markDirty();
            iterator.remove();
        } else {
            event.onUpdate();
        }
    }
}
Also used : IColonyEvent(com.minecolonies.api.colony.colonyEvents.IColonyEvent)

Aggregations

IColonyEvent (com.minecolonies.api.colony.colonyEvents.IColonyEvent)14 CompoundNBT (net.minecraft.nbt.CompoundNBT)4 ListNBT (net.minecraft.nbt.ListNBT)4 IColonyEntitySpawnEvent (com.minecolonies.api.colony.colonyEvents.IColonyEntitySpawnEvent)2 ColonyEventTypeRegistryEntry (com.minecolonies.api.colony.colonyEvents.registry.ColonyEventTypeRegistryEntry)2 AbstractEntityMinecoloniesMob (com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesMob)2 HordeRaidEvent (com.minecolonies.coremod.colony.colonyEvents.raidEvents.HordeRaidEvent)2 PlayAudioMessage (com.minecolonies.coremod.network.messages.client.PlayAudioMessage)2 INBT (net.minecraft.nbt.INBT)2 DamageSource (net.minecraft.util.DamageSource)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 BlockPos (net.minecraft.util.math.BlockPos)2 StringTextComponent (net.minecraft.util.text.StringTextComponent)2 IColonyRaidEvent (com.minecolonies.api.colony.colonyEvents.IColonyRaidEvent)1