Send resources and existing buildings when re-sending chunks
'/kafkatorio chunks' only re-sent chunk terrain: resources were only sent when Factorio first generated a chunk, and buildings only when built or mined. A save that predates the mod therefore showed no resources or buildings at all. Re-sent chunks now also go through the entity chunk handler, which now also includes the chunk's existing player-force buildings (excluding characters). Newly generated chunks contain no buildings, so that path is unaffected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
424e12309d
commit
d680608deb
2 changed files with 25 additions and 0 deletions
|
|
@ -105,6 +105,13 @@ export class EntityUpdatesHandler {
|
|||
Converters.chunkPosition(event.position),
|
||||
entities,
|
||||
)
|
||||
|
||||
// Buildings that already exist are otherwise only sent when they're built or mined, so
|
||||
// include them, so that re-sending chunks (`/kafkatorio chunks`) also sends existing bases.
|
||||
// (Newly generated chunks won't contain any.)
|
||||
for (const building of EntityUpdatesHandler.getAreaPlayerBuildings(event.surface, event.area)) {
|
||||
EntityUpdatesHandler.throttleEntityUpdate(event, building)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -216,6 +223,21 @@ export class EntityUpdatesHandler {
|
|||
}
|
||||
|
||||
|
||||
/** Get all player-force buildings within a map-area (excluding player characters) */
|
||||
private static getAreaPlayerBuildings(
|
||||
surface: LuaSurface,
|
||||
area: BoundingBox,
|
||||
): LuaEntity[] {
|
||||
const buildings: LuaEntity[] = []
|
||||
for (const entity of surface.find_entities_filtered({area: area, force: "player"})) {
|
||||
if (entity.type != "character") {
|
||||
buildings[buildings.length] = entity
|
||||
}
|
||||
}
|
||||
return buildings
|
||||
}
|
||||
|
||||
|
||||
/** Get all resources within a map-area */
|
||||
private static getAreaResourceEntities(
|
||||
surface: LuaSurface,
|
||||
|
|
@ -236,6 +258,7 @@ export default EntityUpdates
|
|||
|
||||
type EntityUpdateEvent =
|
||||
| OnBuiltEntityEvent
|
||||
| OnChunkGeneratedEvent
|
||||
|
||||
| OnEntityClonedEvent
|
||||
| OnEntityDamagedEvent
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import {Converters} from "./converters";
|
|||
import {handleSurfaceUpdate} from "./surfaceUpdates";
|
||||
import EventCacheService from "../emitting/EventDataCache";
|
||||
import MapChunkUpdate from "./handlers/MapChunkUpdateHandler";
|
||||
import EntityUpdates from "./handlers/EntityUpdateHandler";
|
||||
import KafkatorioPacketQueue from "../emitting/KafkatorioPacketQueue";
|
||||
import PacketEmitter from "../emitting/PacketEmitter";
|
||||
import {KafkatorioPacketData} from "../../generated/kafkatorio-schema";
|
||||
|
|
@ -43,6 +44,7 @@ script.on_event(defines.events.on_tick, (event: OnTickEvent) => {
|
|||
|
||||
log(`[on_tick:${event.tick}] dequeued event ${eName}, delay ${i}`)
|
||||
MapChunkUpdate.handleChunkGeneratedEvent(event, i)
|
||||
EntityUpdates.handleChunkGeneratedEvent(event)
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue