Search in sources :

Example 11 with IColonyEvent

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

the class CommandKillRaider method onExecute.

/**
 * What happens when the command is executed
 *
 * @param context the context of the command execution
 */
@Override
public int onExecute(final CommandContext<CommandSource> context) {
    entitiesKilled = 0;
    context.getSource().getLevel().getEntities().forEach(entity -> {
        if (entity instanceof AbstractEntityMinecoloniesMob) {
            final AbstractEntityMinecoloniesMob mob = (AbstractEntityMinecoloniesMob) entity;
            mob.die(new DamageSource("despawn"));
            mob.remove();
            final IColonyEvent event = mob.getColony().getEventManager().getEventByID(mob.getEventID());
            if (event != null) {
                event.setStatus(EventStatus.DONE);
            }
            entitiesKilled++;
        }
    });
    context.getSource().sendSuccess(new StringTextComponent(entitiesKilled + " entities killed"), true);
    return 1;
}
Also used : IColonyEvent(com.minecolonies.api.colony.colonyEvents.IColonyEvent) DamageSource(net.minecraft.util.DamageSource) StringTextComponent(net.minecraft.util.text.StringTextComponent) AbstractEntityMinecoloniesMob(com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesMob)

Example 12 with IColonyEvent

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

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

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

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

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

the class CommandKillRaider method onExecute.

/**
 * What happens when the command is executed
 *
 * @param context the context of the command execution
 */
@Override
public int onExecute(final CommandContext<CommandSource> context) {
    entitiesKilled = 0;
    context.getSource().getLevel().getEntities().forEach(entity -> {
        if (entity instanceof AbstractEntityMinecoloniesMob) {
            final AbstractEntityMinecoloniesMob mob = (AbstractEntityMinecoloniesMob) entity;
            mob.die(new DamageSource("despawn"));
            mob.remove();
            final IColonyEvent event = mob.getColony().getEventManager().getEventByID(mob.getEventID());
            if (event != null) {
                event.setStatus(EventStatus.DONE);
            }
            entitiesKilled++;
        }
    });
    context.getSource().sendSuccess(new StringTextComponent(entitiesKilled + " entities killed"), true);
    return 1;
}
Also used : IColonyEvent(com.minecolonies.api.colony.colonyEvents.IColonyEvent) DamageSource(net.minecraft.util.DamageSource) StringTextComponent(net.minecraft.util.text.StringTextComponent) AbstractEntityMinecoloniesMob(com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesMob)

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