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