@@ -13,12 +13,13 @@ import {
1313 registerSaveableRegion ,
1414 Vec ,
1515} from 'lib'
16+ import { form } from 'lib/form/new'
1617import { i18n , noI18n } from 'lib/i18n/text'
1718import { anyPlayerNearRegion } from 'lib/player-move'
1819import { rollChance } from 'lib/rpg/random'
1920import { createLogger } from 'lib/utils/logger'
21+ import { BaseItem } from '../base/base'
2022
21- // TODO Add chest generation
2223const logger = createLogger ( 'warden' )
2324
2425class WardenDungeonRegion extends Region {
@@ -132,8 +133,11 @@ system.runInterval(
132133
133134 if ( ! region . ldb . cleaned ) {
134135 region . ldb . cleaned = true
135- for ( const block of region . ldb . blocks ) {
136- region . dimension . setBlockType ( block , MinecraftBlockTypes . Air )
136+ for ( const location of region . ldb . blocks ) {
137+ const block = region . dimension . getBlock ( location )
138+ const container = block ?. getComponent ( 'inventory' ) ?. container
139+ if ( container ) container . clearAll ( )
140+ block ?. setType ( MinecraftBlockTypes . Air )
137141 }
138142 region . ldb . blocks = [ ]
139143 region . save ( )
@@ -145,15 +149,22 @@ system.runInterval(
145149 region . area . forEachVector ( ( location , isIn ) => {
146150 if ( ! isIn ) return
147151 if ( Vec . distance ( location , region . area . center ) > region . area . radius ) return
148- if ( ! rollChance ( 90 ) ) return
149152
150153 const below = region . dimension . getBlock ( Vec . add ( location , Vec . down ) )
151154 if ( ! below || below . isAir ) return
152155
156+ let chance = 50
157+ if ( below . typeId === MinecraftBlockTypes . AncientDebris ) chance -= 20
158+ else if ( below . typeId === MinecraftBlockTypes . Chest ) chance = 100
159+
153160 if ( ! chest && rollChance ( 10 ) ) {
154161 chest = true
155- region . dimension . setBlockType ( location , MinecraftBlockTypes . Chest )
162+ const block = region . dimension . getBlock ( location )
163+ block ?. setType ( MinecraftBlockTypes . Chest )
164+ const container = block ?. getComponent ( 'inventory' ) ?. container
165+ if ( container ) container . setItem ( 15 , BaseItem . blueprint )
156166 } else {
167+ if ( chance !== 100 && ! rollChance ( chance ) ) return
157168 region . dimension . setBlockType ( location , MinecraftBlockTypes . AncientDebris )
158169 }
159170 region . ldb . blocks . push ( location )
@@ -164,3 +175,21 @@ system.runInterval(
164175 'wardenDungeonUpdateLoot' ,
165176 fromMsToTicks ( ms . from ( 'sec' , 3 ) ) ,
166177)
178+
179+ const cmd = new Command ( 'warden' ) . setPermissions ( 'techAdmin' ) . executes ( ctx => {
180+ ctx . player . teleport ( WardenDungeonRegion . getAll ( ) [ 0 ] ?. area . center ?? ctx . player . location )
181+ ctx . reply ( 'Tp to location' )
182+ } )
183+
184+ const lootForm = form ( ( f , { player } ) => {
185+ f . title ( 'loot' )
186+ for ( const region of WardenDungeonLootRegion . getAll ( ) . sort ( ( a , b ) =>
187+ a . ldb . selected && b . ldb . selected ? 0 : a . ldb . selected && ! b . ldb . selected ? 1 : - 1 ,
188+ ) ) {
189+ f . button ( ( region . ldb . selected ? '§aA!§r ' : '' ) + region . area . toString ( ) , ( ) => {
190+ player . teleport ( region . area . center )
191+ } )
192+ }
193+ } )
194+
195+ cmd . overload ( 'loot' ) . executes ( lootForm . command )
0 commit comments