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();
}
}
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);
}
}
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);
}
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);
}
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();
}
}
}
Aggregations