diff --git a/src/lib/region/structure.ts b/src/lib/region/structure.ts index 46775ba8..78214af8 100644 --- a/src/lib/region/structure.ts +++ b/src/lib/region/structure.ts @@ -1,4 +1,6 @@ import { BlockPermutation, Dimension, StructureSaveMode, system, world } from '@minecraft/server' +import { MinecraftBlockTypes } from '@minecraft/vanilla-data' +import { getScheduledToPlace, scheduleBlockPlace, unscheduleBlockPlace } from 'lib/scheduled-block-place' import { Vector } from 'lib/vector' import { Region } from './kinds/region' @@ -44,8 +46,15 @@ export class RegionStructure { try { if (block) dimension.setBlockPermutation(vector, block) } catch (e) { - console.warn('Unable to set block for structure:', e) - // TODO Scheduled block place? + const schedule = getScheduledToPlace(vector, dimension.type) + if (schedule) unscheduleBlockPlace(schedule) + scheduleBlockPlace({ + dimension: dimension.type, + location: vector, + typeId: block?.type.id ?? MinecraftBlockTypes.Air, + states: block?.getAllStates() ?? {}, + restoreTime: 0, + }) } }) } diff --git a/src/lib/rpg/boss.ts b/src/lib/rpg/boss.ts index 67067f46..e9963dbd 100644 --- a/src/lib/rpg/boss.ts +++ b/src/lib/rpg/boss.ts @@ -219,6 +219,7 @@ export class Boss { // Boss died or unloaded, respawn after interval this.onDie({ dropLoot: false }) } else { + if (!this.entity.isValid()) return if (this.region && this.location.valid && !this.region.area.isIn(this.entity)) this.entity.teleport(this.location) this.onInterval?.(this) diff --git a/src/modules/survival/scheduled-block-place.ts b/src/lib/scheduled-block-place.ts similarity index 97% rename from src/modules/survival/scheduled-block-place.ts rename to src/lib/scheduled-block-place.ts index 9b6a1b64..778aef3b 100644 --- a/src/modules/survival/scheduled-block-place.ts +++ b/src/lib/scheduled-block-place.ts @@ -1,10 +1,12 @@ import { Block, BlockPermutation, LocationInUnloadedChunkError, system, world } from '@minecraft/server' -import { EventSignal, Vector, util } from 'lib' import { table } from 'lib/database/abstract' import { ProxyDatabase } from 'lib/database/proxy' +import { EventSignal } from 'lib/event-signal' import { form } from 'lib/form/new' import { t } from 'lib/text' +import { util } from 'lib/util' import { createLogger } from 'lib/utils/logger' +import { Vector } from 'lib/vector' interface ScheduledBlockPlace { typeId: string diff --git a/src/modules/features/break-place-outside-of-region.ts b/src/modules/features/break-place-outside-of-region.ts index 756d6aa2..21b53db7 100644 --- a/src/modules/features/break-place-outside-of-region.ts +++ b/src/modules/features/break-place-outside-of-region.ts @@ -2,8 +2,8 @@ import { Player } from '@minecraft/server' import { MinecraftBlockTypes, MinecraftItemTypes } from '@minecraft/vanilla-data' import { Cooldown, ms } from 'lib' import { actionGuard, ActionGuardOrder, BLOCK_CONTAINERS, DOORS, GATES, SWITCHES, TRAPDOORS } from 'lib/region/index' +import { isScheduledToPlace, scheduleBlockPlace } from 'lib/scheduled-block-place' import { BaseRegion } from 'modules/places/base/region' -import { isScheduledToPlace, scheduleBlockPlace } from 'modules/survival/scheduled-block-place' const INTERACTABLE = DOORS.concat(SWITCHES, TRAPDOORS, BLOCK_CONTAINERS, GATES) const INTERACTABLEITEMS = Object.values(MinecraftItemTypes) diff --git a/src/modules/places/anarchy/quartz.ts b/src/modules/places/anarchy/quartz.ts index 75e6ebfe..bb51388d 100644 --- a/src/modules/places/anarchy/quartz.ts +++ b/src/modules/places/anarchy/quartz.ts @@ -3,8 +3,8 @@ import { ItemStack, system } from '@minecraft/server' import { MinecraftBlockTypes, MinecraftEffectTypes, MinecraftItemTypes } from '@minecraft/vanilla-data' import { isKeyof, ms } from 'lib' import { actionGuard, ActionGuardOrder } from 'lib/region/index' +import { scheduleBlockPlace } from 'lib/scheduled-block-place' import { TechCity } from 'modules/places/tech-city/tech-city' -import { scheduleBlockPlace } from 'modules/survival/scheduled-block-place' const quartzTypeId = MinecraftBlockTypes.ChiseledQuartzBlock diff --git a/src/modules/places/base/actions/rotting.ts b/src/modules/places/base/actions/rotting.ts index 399b1989..95fd3cdb 100644 --- a/src/modules/places/base/actions/rotting.ts +++ b/src/modules/places/base/actions/rotting.ts @@ -2,11 +2,11 @@ import { Block, BlockPermutation, ContainerSlot, Player, RawText, system } from import { MinecraftBlockTypes } from '@minecraft/vanilla-data' import { ActionForm, Cooldown, getBlockStatus, isEmpty, isLocationError, Mail, ms, Vector } from 'lib' import { table } from 'lib/database/abstract' -import { anyPlayerNearRegion, playerPositionCache } from 'lib/player-move' +import { anyPlayerNearRegion } from 'lib/player-move' +import { scheduleBlockPlace, SCHEDULED_DB, unscheduleBlockPlace } from 'lib/scheduled-block-place' import { itemDescription } from 'lib/shop/rewards' import { t } from 'lib/text' import { onFullRegionTypeRestore } from 'modules/places/minearea/minearea-region' -import { scheduleBlockPlace, SCHEDULED_DB, unscheduleBlockPlace } from 'modules/survival/scheduled-block-place' import { spawnParticlesInArea } from 'modules/world-edit/config' import { BaseRegion } from '../region' diff --git a/src/modules/places/dungeons/warden.ts b/src/modules/places/dungeons/warden.ts index 8f8aa9f1..2e19b359 100644 --- a/src/modules/places/dungeons/warden.ts +++ b/src/modules/places/dungeons/warden.ts @@ -10,8 +10,8 @@ import { registerSaveableRegion, } from 'lib' import { anyPlayerNearRegion } from 'lib/player-move' +import { getScheduledToPlace, scheduleBlockPlace, unscheduleBlockPlace } from 'lib/scheduled-block-place' import { createLogger } from 'lib/utils/logger' -import { getScheduledToPlace, scheduleBlockPlace, unscheduleBlockPlace } from 'modules/survival/scheduled-block-place' // TODO Add chest generation diff --git a/src/modules/places/minearea/minearea-region.ts b/src/modules/places/minearea/minearea-region.ts index 9b7114d0..2db920db 100644 --- a/src/modules/places/minearea/minearea-region.ts +++ b/src/modules/places/minearea/minearea-region.ts @@ -4,9 +4,9 @@ import { actionGuard, ActionGuardOrder, registerCreateableRegion } from 'lib/reg import { registerSaveableRegion } from 'lib/region/database' import { Region, type RegionPermissions } from 'lib/region/kinds/region' import { RegionWithStructure } from 'lib/region/kinds/with-structure' +import { onScheduledBlockPlace, scheduleBlockPlace } from 'lib/scheduled-block-place' import { createLogger } from 'lib/utils/logger' import { ms } from 'lib/utils/ms' -import { onScheduledBlockPlace, scheduleBlockPlace } from 'modules/survival/scheduled-block-place' const logger = createLogger('Minearea') diff --git a/src/modules/places/mineshaft/mineshaft-region.ts b/src/modules/places/mineshaft/mineshaft-region.ts index 2aea6e72..c73fcf2f 100644 --- a/src/modules/places/mineshaft/mineshaft-region.ts +++ b/src/modules/places/mineshaft/mineshaft-region.ts @@ -1,8 +1,8 @@ import { Player, PlayerBreakBlockBeforeEvent, system } from '@minecraft/server' import { ms, registerCreateableRegion } from 'lib' import { registerSaveableRegion } from 'lib/region/database' +import { scheduleBlockPlace } from 'lib/scheduled-block-place' import { createLogger } from 'lib/utils/logger' -import { scheduleBlockPlace } from 'modules/survival/scheduled-block-place' import { MineareaRegion } from '../minearea/minearea-region' import { ores, placeOre } from './algo' diff --git a/src/modules/pvp/raid.ts b/src/modules/pvp/raid.ts index e2bafed1..06e87e8a 100644 --- a/src/modules/pvp/raid.ts +++ b/src/modules/pvp/raid.ts @@ -1,10 +1,10 @@ import { system, world } from '@minecraft/server' import { LockAction, Region, ms } from 'lib' import { ScoreboardDB } from 'lib/database/scoreboard' +import { isScheduledToPlace } from 'lib/scheduled-block-place' import { t } from 'lib/text' import { BaseRegion } from 'modules/places/base/region' import { MineareaRegion } from 'modules/places/minearea/minearea-region' -import { isScheduledToPlace } from 'modules/survival/scheduled-block-place' const notify = new Map() const targetLockTime = ms.from('min', 8)