Skip to content

Commit

Permalink
Fix scheduled block place to work on regionStructure.place
Browse files Browse the repository at this point in the history
  • Loading branch information
leaftail1880 committed Jan 6, 2025
1 parent 1c336ac commit 75f7d3f
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 11 deletions.
13 changes: 11 additions & 2 deletions src/lib/region/structure.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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,
})
}
})
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/rpg/boss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/modules/features/break-place-outside-of-region.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/modules/places/anarchy/quartz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/modules/places/base/actions/rotting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion src/modules/places/dungeons/warden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/modules/places/minearea/minearea-region.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion src/modules/places/mineshaft/mineshaft-region.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
2 changes: 1 addition & 1 deletion src/modules/pvp/raid.ts
Original file line number Diff line number Diff line change
@@ -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<string, { time: number; reason: string }>()
const targetLockTime = ms.from('min', 8)
Expand Down

0 comments on commit 75f7d3f

Please sign in to comment.