Search in sources :

Example 1 with IColonyEvent

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

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 2 with IColonyEvent

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

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)

Example 3 with IColonyEvent

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

the class RaiderWalkAI method walk.

/**
 * Walk raider towards the colony or campfires
 *
 * @return
 */
private boolean walk() {
    if (raider.getColony() != null) {
        final IColonyEvent event = raider.getColony().getEventManager().getEventByID(raider.getEventID());
        if (event == null) {
            return false;
        }
        if (event.getStatus() == EventStatus.PREPARING && event instanceof HordeRaidEvent) {
            walkToCampFire();
            return false;
        }
        if (targetBlock == null || raider.getNavigation().isDone() || (targetBlock != null && raider.blockPosition().distSqr(targetBlock) < 25)) {
            targetBlock = raider.getColony().getRaiderManager().getRandomBuilding();
            final BlockPos moveToPos = ShipBasedRaiderUtils.chooseWaypointFor(((IColonyRaidEvent) event).getWayPoints(), raider.blockPosition(), targetBlock);
            raider.getNavigation().moveToXYZ(moveToPos.getX(), moveToPos.getY(), moveToPos.getZ(), 1.1);
        }
    }
    return false;
}
Also used : IColonyEvent(com.minecolonies.api.colony.colonyEvents.IColonyEvent) BlockPos(net.minecraft.util.math.BlockPos) HordeRaidEvent(com.minecolonies.coremod.colony.colonyEvents.raidEvents.HordeRaidEvent)

Example 4 with IColonyEvent

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

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) {
        LanguageHandler.sendPlayersMessage(colony.getImportantMessageEntityPlayers(), LanguageHandler.translateKey(ALL_BARBARIANS_KILLED_MESSAGE), colony.getName());
        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) {
        LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), ONLY_X_BARBARIANS_LEFT_MESSAGE, total);
    }
}
Also used : IColonyEvent(com.minecolonies.api.colony.colonyEvents.IColonyEvent) PlayAudioMessage(com.minecolonies.coremod.network.messages.client.PlayAudioMessage)

Example 5 with IColonyEvent

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

the class RaiderWalkAI method walk.

/**
 * Walk raider towards the colony or campfires
 *
 * @return
 */
private boolean walk() {
    if (raider.getColony() != null) {
        final IColonyEvent event = raider.getColony().getEventManager().getEventByID(raider.getEventID());
        if (event == null) {
            return false;
        }
        if (event.getStatus() == EventStatus.PREPARING && event instanceof HordeRaidEvent) {
            walkToCampFire();
            return false;
        }
        if (targetBlock == null || raider.blockPosition().distSqr(targetBlock) < 25 || raider.level.getGameTime() > walkTimer) {
            targetBlock = raider.getColony().getRaiderManager().getRandomBuilding();
            walkTimer = raider.level.getGameTime() + TICKS_SECOND * 240;
            final BlockPos moveToPos = ShipBasedRaiderUtils.chooseWaypointFor(((IColonyRaidEvent) event).getWayPoints(), raider.blockPosition(), targetBlock);
            raider.getNavigation().moveToXYZ(moveToPos.getX(), moveToPos.getY(), moveToPos.getZ(), 1.1);
        } else if (raider.getNavigation().isDone() || raider.getNavigation().getDesiredPos() == null) {
            final BlockPos moveToPos = ShipBasedRaiderUtils.chooseWaypointFor(((IColonyRaidEvent) event).getWayPoints(), raider.blockPosition(), targetBlock);
            raider.getNavigation().moveToXYZ(moveToPos.getX(), moveToPos.getY(), moveToPos.getZ(), 1.1);
        }
    }
    return false;
}
Also used : IColonyEvent(com.minecolonies.api.colony.colonyEvents.IColonyEvent) IColonyRaidEvent(com.minecolonies.api.colony.colonyEvents.IColonyRaidEvent) BlockPos(net.minecraft.util.math.BlockPos) HordeRaidEvent(com.minecolonies.coremod.colony.colonyEvents.raidEvents.HordeRaidEvent)

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