1mod magic;
40pub use self::magic::{Attribute, AttributeError};
42use crate::{
43 attributes,
44 comp::{BuffData, BuffKind, item::ItemDefinitionIdOwned, tool::ToolKind},
45 effect::BuffEffect,
46 lottery::LootSpec,
47 make_case_elim,
48 resources::Secs,
49 sprites,
50 terrain::Block,
51};
52use common_i18n::Content;
53use hashbrown::HashMap;
54use lazy_static::lazy_static;
55use num_derive::FromPrimitive;
56use serde::{Deserialize, Serialize};
57use std::{
58 convert::{Infallible, TryFrom},
59 fmt,
60};
61use strum::EnumIter;
62use vek::*;
63
64#[derive(Copy, Clone, Debug, Eq, PartialEq, Deserialize)]
89#[serde(transparent)]
90pub struct StructureSprite(StructureSpriteKind);
91
92impl StructureSprite {
93 pub fn get_block(self, with_sprite: impl FnMut(SpriteKind) -> Block) -> Block {
94 self.0.get_block(with_sprite)
95 }
96}
97
98sprites! {
99 Void = 0 {
100 Empty = 0,
101 },
102 Misc = 1 {
104 Ember = 0x00,
105 SmokeDummy = 0x01,
106 Bomb = 0x02,
107 FireBlock = 0x03, HotSurface = 0x04,
109 Stones2 = 0x05, },
111 Furniture = 2 has Ori, MirrorX {
114 BookshelfArabic = 0x0D,
116 WallTableArabic = 0x0E,
117 TableArabicLarge = 0x0F,
118 TableArabicSmall = 0x10,
119 CupboardArabic = 0x11,
120 OvenArabic = 0x12,
121 CushionArabic = 0x13,
122 CanapeArabic = 0x14,
123 Shelf = 0x15,
124 Planter = 0x16,
125 BedMesa = 0x18,
126 WallTableMesa = 0x19,
127 MirrorMesa = 0x1A,
128 WardrobeSingleMesa = 0x1B,
129 WardrobeDoubleMesa = 0x1C,
130 CupboardMesa = 0x1D,
131 TableCoastalLarge = 0x1E,
132 BenchCoastal = 0x1F,
133 CraftingBench = 0x20,
135 Forge = 0x21,
136 Cauldron = 0x22,
137 Anvil = 0x23,
138 CookingPot = 0x24,
139 SpinningWheel = 0x25,
140 TanningRack = 0x26,
141 Loom = 0x27,
142 DismantlingBench = 0x28,
143 RepairBench = 0x29,
144 HangingBasket = 0x50,
146 HangingSign = 0x51,
147 ChristmasOrnament = 0x52,
148 ChristmasWreath = 0x53,
149 WallLampWizard = 0x54,
150 WallLamp = 0x55,
151 WallLampSmall = 0x56,
152 WallSconce = 0x57,
153 DungeonWallDecor = 0x58,
154 WallLampMesa = 0x59,
155 Tent = 0x60,
157 Bedroll = 0x61,
158 BedrollSnow = 0x62,
159 BedrollPirate = 0x63,
160 Sign = 0x64,
161 Helm = 0x65,
162 Scarecrow = 0x70,
164 FountainArabic = 0x71,
165 Hearth = 0x72,
166 ChestWoodDouble= 0x73,
167 LanternpostWoodUpper = 0x74,
168 LanternpostWoodBase = 0x75,
169 LampMetalBase = 0x76,
170 BlacksmithBellows = 0x77,
171 CarpenterTable = 0x78,
172 CarpenterCrateWoodS = 0x79,
173 CarpenterCrateWoodL = 0x7A,
174 CarpenterToolsWall = 0x7B,
175 CarpenterLogCutter = 0x7C,
176 BarrelWoodCoal = 0x7D,
177 BarrelWoodWater = 0x7E,
178 BasketWovenL = 0x7F,
179 BasketWovenM = 0x80,
180 BasketWovenS = 0x81,
181 BonfireMLit = 0x82,
182 BonfireMUnlit = 0x83,
183 BucketWoodM = 0x84,
184 MirrorWoodM = 0x85,
185 SackLeatherM = 0x86,
186 TrophyframeWoodBear = 0x87,
187 TrophyframeWoodDeer = 0x88,
188 JugClayM = 0x89,
189 LogsWoodBranchS = 0x8A,
190 DiningtableWoodCorner = 0x8B,
191 DiningtableWoodBody = 0x8C,
192 BenchWoodEnd = 0x8D,
193 BenchWoodMiddle = 0x8E,
194 LogsWoodCoreEnd = 0x8F,
195 LogsWoodCoreMiddle = 0x90,
196 LogsWoodBarkEnd = 0x91,
197 LogsWoodBarkMiddle = 0x92,
198 LogsWoodBranchEnd = 0x93,
199 LogsWoodBranchMiddle = 0x94,
200 SeatWoodBlueMiddle = 0x95,
201 SeatWoodBlueSide = 0x96,
202 RopeCoilM = 0x97,
203 BedWoodWoodlandHead = 0x99,
204 BedWoodWoodlandMiddle = 0x9A,
205 BedWoodWoodlandTail = 0x9B,
206 BenchWoodWoodlandGreen1 = 0x9C,
207 BenchWoodWoodlandGreen2 = 0x9D,
208 BenchWoodWoodlandGreen3 = 0x9E,
209 BenchWoodWoodland = 0xA0,
210 ChairWoodWoodland = 0xA1,
211 ChairWoodWoodland2 = 0xA2,
212 CoatrackMetalWoodland = 0xA3,
213 CoatrackWoodWoodland = 0xA4,
214 DrawerWoodWoodlandL1 = 0xA5,
215 DrawerWoodWoodlandL2 = 0xA6,
216 DrawerWoodWoodlandM1 = 0xA7,
217 DrawerWoodWoodlandM2 = 0xA8,
218 DrawerWoodWoodlandS = 0xA9,
219 HandCartWoodHead = 0xAA,
220 HandCartWoodMiddle = 0xAB,
221 HandCartWoodTail = 0xAC,
222 FlowerpotWoodWoodlandS = 0xAD,
223 DiningtableWoodWoodlandRound = 0xAE,
224 DiningtableWoodWoodlandSquare = 0xAF,
225 TableWoodFancyWoodlandCorner = 0xB0,
226 TableWoodFancyWoodlandBody = 0xB1,
227 WardrobedoubleWoodWoodland = 0xB2,
228 WardrobedoubleWoodWoodland2 = 0xB3,
229 WardrobesingleWoodWoodland = 0xB4,
230 WardrobesingleWoodWoodland2 = 0xB5,
231 BedCliffHead = 0xB6,
232 BedCliffMiddle = 0xB7,
233 BedCliffTail = 0xB8,
234 BedCoastalHead = 0xB9,
235 BedCoastalMiddle = 0xBA,
236 BedCoastalTail = 0xBB,
237 BedDesertHead = 0xBC,
238 BedDesertMiddle = 0xBD,
239 BedDesertTail = 0xBE,
240 BedSavannahHead = 0xBF,
241 BedSavannahMiddle = 0xC0,
242 BedSavannahTail = 0xC1,
243 Ladder = 0xC2,
244 BookshelfEnd = 0xC3,
245 BookshelfMiddle = 0xC4,
246 HandrailWoodWoodlandBase = 0xC5,
247 HandrailWoodWoodlandMiddle = 0xC6,
248 HandrailWoodWoodlandTop = 0xC7,
249 BroomWoodWoodlandBlue = 0xC8,
250 ShovelWoodWoodlandGreen = 0xC9,
251 PitchforkWoodWoodlandGreen = 0xCA,
252 RakeWoodWoodland = 0xCB,
253 FenceWoodGateWoodland = 0xCC,
254 },
255 Plant = 3 has Growth, Owned, SnowCovered, Collectable {
257 BarrelCactus = 0x00,
259 RoundCactus = 0x01,
260 ShortCactus = 0x02,
261 MedFlatCactus = 0x03,
262 ShortFlatCactus = 0x04,
263 LargeCactus = 0x05,
264 TallCactus = 0x06,
265 BlueFlower = 0x10,
267 PinkFlower = 0x11,
268 PurpleFlower = 0x12,
269 RedFlower = 0x13,
270 WhiteFlower = 0x14,
271 YellowFlower = 0x15,
272 Sunflower = 0x16,
273 Moonbell = 0x17,
274 Pyrebloom = 0x18,
275 LushFlower = 0x19,
276 LanternFlower = 0x1A,
277 LongGrass = 0x20,
280 MediumGrass = 0x21,
281 ShortGrass = 0x22,
282 Fern = 0x23,
283 LargeGrass = 0x24,
284 Reed = 0x25,
285 TaigaGrass = 0x26,
286 GrassBlue = 0x27,
287 SavannaGrass = 0x28,
288 TallSavannaGrass = 0x29,
289 RedSavannaGrass = 0x2A,
290 SavannaBush = 0x2B,
291 Welwitch = 0x2C,
292 LeafyPlant = 0x2D,
293 DeadBush = 0x2E,
294 JungleFern = 0x2F,
295 GrassBlueShort = 0x30,
296 GrassBlueMedium = 0x31,
297 GrassBlueLong = 0x32,
298 CavernLillypadBlue = 0x33,
299 EnsnaringVines = 0x34,
300 LillyPads = 0x35,
301 JungleLeafyPlant = 0x36,
302 JungleRedGrass = 0x37,
303 LanternPlant = 0x38,
304 SporeReed = 0x39,
305 DeadPlant = 0x3A,
306 Corn = 0x41,
308 WheatYellow = 0x42,
309 WheatGreen = 0x43, LingonBerry = 0x44,
311 Blueberry = 0x45,
312 Lettuce = 0x46,
313 Pumpkin = 0x47,
314 Carrot = 0x48,
315 Tomato = 0x49,
316 Radish = 0x4A,
317 Turnip = 0x4B,
318 Flax = 0x4C,
319 Mushroom = 0x4D,
320 CaveMushroom = 0x4E,
321 Cotton = 0x4F,
322 WildFlax = 0x50,
323 SewerMushroom = 0x51,
324 LushMushroom = 0x52,
325 RockyMushroom = 0x53,
326 GlowMushroom = 0x54,
327 StonyCoral = 0x61,
329 SoftCoral = 0x62,
330 SeaweedTemperate = 0x63,
331 SeaweedTropical = 0x64,
332 GiantKelp = 0x65,
333 BullKelp = 0x66,
334 WavyAlgae = 0x67,
335 SeaGrapes = 0x68,
336 MermaidsFan = 0x69,
337 SeaAnemone = 0x6A,
338 Seagrass = 0x6B,
339 RedAlgae = 0x6C,
340 Liana = 0x71,
342 MycelBlue = 0x72,
343 CeilingMushroom = 0x73,
344 Mold = 0x74,
345 Root = 0x75,
346 CeilingLanternPlant = 0x76,
347 CeilingLanternFlower = 0x77,
348 CeilingJungleLeafyPlant = 0x78,
349 },
350 Resource = 4 has Owned, SnowCovered {
353 Twigs = 0x00,
356 Wood = 0x01,
357 Bamboo = 0x02,
358 Hardwood = 0x03,
359 Ironwood = 0x04,
360 Frostwood = 0x05,
361 Eldwood = 0x06,
362 Apple = 0x20,
364 Coconut = 0x21,
365 Stones = 0x22,
366 Seashells = 0x23,
367 Beehive = 0x24,
368 Bowl = 0x25,
369 PotionMinor = 0x26,
370 PotionDummy = 0x27,
371 VialEmpty = 0x28,
372 },
373 MineableResource = 5 has Damage {
374 Amethyst = 0x00,
375 Ruby = 0x01,
376 Sapphire = 0x02,
377 Emerald = 0x03,
378 Topaz = 0x04,
379 Diamond = 0x05,
380 Bloodstone = 0x06,
381 Coal = 0x07,
382 Cobalt = 0x08,
383 Copper = 0x09,
384 Iron = 0x0A,
385 Tin = 0x0B,
386 Silver = 0x0C,
387 Gold = 0x0D,
388 Velorite = 0x0E,
389 VeloriteFrag = 0x0F,
390 Mud = 0x10,
391 Grave = 0x11,
392 },
393 Structural = 6 has Ori {
395 Door = 0x00,
397 DoorDark = 0x01,
398 DoorWide = 0x02,
399 BoneKeyhole = 0x03,
400 BoneKeyDoor = 0x04,
401 Keyhole = 0x05,
402 KeyDoor = 0x06,
403 GlassKeyhole = 0x07,
404 KeyholeBars = 0x08,
405 HaniwaKeyDoor = 0x09,
406 HaniwaKeyhole = 0x0A,
407 TerracottaKeyDoor = 0x0B,
408 TerracottaKeyhole = 0x0C,
409 SahaginKeyhole = 0x0D,
410 SahaginKeyDoor = 0x0E,
411 VampireKeyDoor = 0x0F,
412 VampireKeyhole = 0x10,
413 MyrmidonKeyDoor = 0x11,
414 MyrmidonKeyhole = 0x12,
415 MinotaurKeyhole = 0x13,
416
417 Window1 = 0x14,
419 Window2 = 0x15,
420 Window3 = 0x16,
421 Window4 = 0x17,
422 WitchWindow = 0x18,
423 WindowArabic = 0x19,
424 GlassBarrier = 0x20,
426 SeaDecorBlock = 0x21,
427 CliffDecorBlock = 0x22,
428 MagicalBarrier = 0x23,
429 OneWayWall = 0x24,
430 SeaDecorWindowHor = 0x30,
432 SeaDecorWindowVer = 0x31,
433 DropGate = 0x32,
434 DropGateBottom = 0x33,
435 WoodBarricades = 0x34,
436 Rope = 0x40,
438 SeaDecorChain = 0x41,
439 IronSpike = 0x42,
440 DoorBars = 0x43,
441 HaniwaTrap = 0x44,
442 HaniwaTrapTriggered = 0x45,
443 TerracottaStatue = 0x46,
444 TerracottaBlock = 0x47,
445 MetalChain = 0x48,
446 },
447 Decor = 7 has Ori {
449 Bones = 0x00,
451 IceCrystal = 0x01,
452 GlowIceCrystal = 0x02,
453 CrystalHigh = 0x03,
454 CrystalLow = 0x04,
455 UnderwaterVent = 0x05,
456 SeaUrchin = 0x06,
457 IceSpike = 0x07,
458 Orb = 0x08,
459 EnsnaringWeb = 0x09,
460 DiamondLight = 0x0A,
461
462 Gravestone = 0x10,
464 Melon = 0x11,
465 ForgeTools = 0x12,
466 JugAndBowlArabic = 0x13,
467 JugArabic = 0x14,
468 DecorSetArabic = 0x15,
469 SepareArabic = 0x16,
470 Candle = 0x17,
471 SmithingTable = 0x18,
472 Forge0 = 0x19,
473 GearWheel0 = 0x1A,
474 Quench0 = 0x1B,
475 SeaDecorEmblem = 0x1C,
476 SeaDecorPillar = 0x1D,
477 MagicalSeal = 0x1E,
478 JugAndCupsCoastal = 0x1F,
479 },
480 Lamp = 8 has Ori, LightEnabled {
481 Lantern = 0x00,
483 StreetLamp = 0x01,
484 StreetLampTall = 0x02,
485 SeashellLantern = 0x03,
486 FireBowlGround = 0x04,
487 MesaLantern = 0x05,
488 LanternpostWoodLantern = 0x06,
489 LampMetalShinglesRed = 0x07,
490 LampTerracotta = 0x08,
491 LampMetalShinglesCyan = 0x09,
492 LanternAirshipWallBlackS = 0x0A,
493 LanternAirshipWallBrownS = 0x0B,
494 LanternAirshipWallChestnutS = 0x0C,
495 LanternAirshipWallRedS = 0x0D,
496 LanternAirshipGroundBlackS = 0x0E,
497 LanternAirshipGroundBrownS = 0x0F,
498 LanternAirshipGroundChestnutS = 0x10,
499 LanternAirshipGroundRedS = 0x11,
500 },
501 Container = 9 has Ori, Owned, Collectable {
502 Chest = 0x00,
503 DungeonChest0 = 0x01,
504 DungeonChest1 = 0x02,
505 DungeonChest2 = 0x03,
506 DungeonChest3 = 0x04,
507 DungeonChest4 = 0x05,
508 DungeonChest5 = 0x06,
509 CoralChest = 0x07,
510 HaniwaUrn = 0x08,
511 TerracottaChest = 0x09,
512 SahaginChest = 0x0A,
513 CommonLockedChest = 0x0B,
514 ChestBuried = 0x0C,
515 Crate = 0x0D,
516 Barrel = 0x0E,
517 CrateBlock = 0x0F,
518 },
519 Modular = 10 has Ori, AdjacentType {
520 FenceWoodWoodland = 0x00,
521 }
522}
523
524attributes! {
525 Ori { bits: 3, err: Infallible, from: |bits| Ok(Self(bits as u8)), into: |Ori(x)| x as u16 },
526 MirrorX { bits: 1, err: Infallible, from: |bits| Ok(Self(bits == 1)), into: |MirrorX(x)| x as u16 },
527 MirrorY { bits: 1, err: Infallible, from: |bits| Ok(Self(bits == 1)), into: |MirrorY(x)| x as u16 },
528 MirrorZ { bits: 1, err: Infallible, from: |bits| Ok(Self(bits == 1)), into: |MirrorZ(x)| x as u16 },
529 Growth { bits: 4, err: Infallible, from: |bits| Ok(Self(bits as u8)), into: |Growth(x)| x as u16 },
530 LightEnabled { bits: 1, err: Infallible, from: |bits| Ok(Self(bits == 1)), into: |LightEnabled(x)| x as u16 },
531 Collectable { bits: 1, err: Infallible, from: |bits| Ok(Self(bits == 1)), into: |Collectable(x)| x as u16 },
532 Damage { bits: 3, err: Infallible, from: |bits| Ok(Self(bits as u8)), into: |Damage(x)| x as u16 },
533 Owned { bits: 1, err: Infallible, from: |bits| Ok(Self(bits == 1)), into: |Owned(x)| x as u16 },
534 AdjacentType { bits: 3, err: Infallible, from: |bits| Ok(Self(bits as u8)), into: |AdjacentType(x)| x as u16 },
535 SnowCovered { bits: 1, err: Infallible, from: |bits| Ok(Self(bits == 1)), into: |SnowCovered(x)| x as u16 },
536}
537
538#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, Deserialize)]
540pub struct Ori(pub u8);
541
542#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, Deserialize)]
543pub struct MirrorX(pub bool);
544
545#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, Deserialize)]
546pub struct MirrorY(pub bool);
547
548#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, Deserialize)]
549pub struct MirrorZ(pub bool);
550
551#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)]
553pub struct Growth(pub u8);
554
555impl Default for Growth {
556 fn default() -> Self { Self(15) }
557}
558
559#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)]
561pub struct LightEnabled(pub bool);
562
563impl Default for LightEnabled {
564 fn default() -> Self { Self(true) }
565}
566
567#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)]
568pub struct Collectable(pub bool);
569
570impl Default for Collectable {
571 fn default() -> Self { Self(true) }
572}
573
574#[derive(Default, Copy, Clone, Debug, PartialEq, Eq, Deserialize)]
575pub struct Owned(pub bool);
576
577#[derive(Default, Copy, Clone, Debug, PartialEq, Eq, Deserialize, FromPrimitive, Hash)]
587#[repr(u8)]
588pub enum RelativeNeighborPosition {
589 #[default]
590 I,
591 L,
592 T,
593 X,
594 End,
595}
596
597#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)]
598#[serde(from = "RelativeNeighborPosition")]
599pub struct AdjacentType(pub u8);
600
601impl From<RelativeNeighborPosition> for AdjacentType {
602 fn from(value: RelativeNeighborPosition) -> Self { Self(value as u8) }
603}
604
605impl Default for AdjacentType {
606 fn default() -> Self { Self::from(RelativeNeighborPosition::I) }
607}
608
609#[derive(Copy, Clone, Debug, PartialEq, Eq, Default, Deserialize)]
611pub struct Damage(pub u8);
612
613#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, Deserialize)]
615pub struct SnowCovered(pub bool);
616
617impl SpriteKind {
618 #[inline]
619 pub fn solid_height(&self) -> Option<f32> {
621 Some(match self {
624 SpriteKind::Bedroll => 0.3,
625 SpriteKind::BedrollSnow => 0.4,
626 SpriteKind::BedrollPirate => 0.3,
627 SpriteKind::Tomato => 1.65,
628 SpriteKind::BarrelCactus => 0.909,
629 SpriteKind::LargeCactus => 3.0,
630 SpriteKind::TallCactus => 2.63,
631 SpriteKind::Scarecrow => 3.0,
632 SpriteKind::Turnip => 0.36,
633 SpriteKind::Pumpkin => 0.81,
634 SpriteKind::Chest => 1.09,
635 SpriteKind::CommonLockedChest => 1.09,
636 SpriteKind::DungeonChest0 => 1.09,
637 SpriteKind::DungeonChest1 => 1.09,
638 SpriteKind::DungeonChest2 => 1.09,
639 SpriteKind::DungeonChest3 => 1.09,
640 SpriteKind::DungeonChest4 => 1.09,
641 SpriteKind::DungeonChest5 => 1.09,
642 SpriteKind::CoralChest => 1.09,
643 SpriteKind::HaniwaUrn => 1.09,
644 SpriteKind::SahaginChest => 1.09,
645 SpriteKind::TerracottaChest => 1.09,
646 SpriteKind::TerracottaStatue => 5.29,
647 SpriteKind::TerracottaBlock => 1.00,
648 SpriteKind::FenceWoodWoodland => 1.09,
649 SpriteKind::SeaDecorChain => 1.09,
650 SpriteKind::SeaDecorBlock => 1.00,
651 SpriteKind::SeaDecorWindowHor => 0.55,
652 SpriteKind::SeaDecorWindowVer => 1.09,
653 SpriteKind::SeaDecorPillar => 2.55,
654 SpriteKind::SeashellLantern => 2.09,
655 SpriteKind::MesaLantern => 1.3,
656 SpriteKind::Rope => 1.09,
657 SpriteKind::MetalChain => 1.09,
658 SpriteKind::StreetLamp => 2.65,
659 SpriteKind::Carrot => 0.18,
660 SpriteKind::Radish => 0.18,
661 SpriteKind::FireBowlGround => 0.55,
662 SpriteKind::BedMesa => 0.82,
663 SpriteKind::DungeonWallDecor => 1.0,
664 SpriteKind::Planter => 1.09,
665 SpriteKind::WardrobeSingleMesa => 2.0,
666 SpriteKind::WardrobeDoubleMesa => 2.0,
667 SpriteKind::MirrorMesa => 2.0,
668 SpriteKind::Mud => 0.36,
669 SpriteKind::ChestBuried => 0.91,
670 SpriteKind::StonyCoral => 1.4,
671 SpriteKind::CraftingBench => 1.18,
672 SpriteKind::Forge => 1.818,
673 SpriteKind::Cauldron => 1.27,
674 SpriteKind::SpinningWheel => 1.454,
675 SpriteKind::TanningRack => 1.454,
676 SpriteKind::Loom => 1.636,
677 SpriteKind::Anvil => 1.18,
678 SpriteKind::CookingPot => 1.090,
679 SpriteKind::DismantlingBench => 1.18,
680 SpriteKind::IceSpike => 1.0,
681 SpriteKind::RepairBench => 1.2,
682 SpriteKind::RoundCactus => 0.72,
683 SpriteKind::ShortCactus => 1.36,
684 SpriteKind::MedFlatCactus => 1.36,
685 SpriteKind::ShortFlatCactus => 0.91,
686 SpriteKind::Apple
688 | SpriteKind::Beehive
689 | SpriteKind::Velorite
690 | SpriteKind::VeloriteFrag
691 | SpriteKind::Coconut
692 | SpriteKind::StreetLampTall
693 | SpriteKind::Window1
694 | SpriteKind::Window2
695 | SpriteKind::Window3
696 | SpriteKind::Window4
697 | SpriteKind::DropGate
698 | SpriteKind::WitchWindow
699 | SpriteKind::SeaUrchin
700 | SpriteKind::IronSpike
701 | SpriteKind::GlassBarrier
702 | SpriteKind::GlassKeyhole
703 | SpriteKind::Keyhole
704 | SpriteKind::KeyDoor
705 | SpriteKind::BoneKeyhole
706 | SpriteKind::BoneKeyDoor
707 | SpriteKind::HaniwaKeyhole
708 | SpriteKind::HaniwaKeyDoor
709 | SpriteKind::SahaginKeyhole
710 | SpriteKind::SahaginKeyDoor
711 | SpriteKind::VampireKeyhole
712 | SpriteKind::VampireKeyDoor
713 | SpriteKind::HaniwaTrap
714 | SpriteKind::HaniwaTrapTriggered
715 | SpriteKind::TerracottaKeyDoor
716 | SpriteKind::TerracottaKeyhole
717 | SpriteKind::MyrmidonKeyDoor
718 | SpriteKind::MyrmidonKeyhole
719 | SpriteKind::MinotaurKeyhole
720 | SpriteKind::Bomb
721 | SpriteKind::OneWayWall
722 | SpriteKind::DoorBars
723 | SpriteKind::KeyholeBars
724 | SpriteKind::WoodBarricades
725 | SpriteKind::DiamondLight => 1.0,
726 SpriteKind::Shelf => 1.0,
728 SpriteKind::Lantern => 0.9,
729 SpriteKind::CrystalHigh | SpriteKind::CrystalLow => 1.5,
730 SpriteKind::Bloodstone
731 | SpriteKind::Coal
732 | SpriteKind::Cobalt
733 | SpriteKind::Copper
734 | SpriteKind::Iron
735 | SpriteKind::Tin
736 | SpriteKind::Silver
737 | SpriteKind::Gold => 0.6,
738 SpriteKind::EnsnaringVines
739 | SpriteKind::CavernLillypadBlue
740 | SpriteKind::EnsnaringWeb => 0.15,
741 SpriteKind::LillyPads => 0.1,
742 SpriteKind::WindowArabic | SpriteKind::BookshelfArabic => 1.9,
743 SpriteKind::DecorSetArabic => 2.6,
744 SpriteKind::SepareArabic => 2.2,
745 SpriteKind::CushionArabic => 0.4,
746 SpriteKind::JugArabic => 1.4,
747 SpriteKind::TableArabicSmall => 0.9,
748 SpriteKind::TableArabicLarge => 1.0,
749 SpriteKind::TableCoastalLarge => 1.0,
750 SpriteKind::BenchCoastal => 1.0,
751 SpriteKind::CanapeArabic => 1.2,
752 SpriteKind::CupboardArabic => 4.5,
753 SpriteKind::WallTableArabic => 2.3,
754 SpriteKind::JugAndBowlArabic => 1.4,
755 SpriteKind::JugAndCupsCoastal => 1.4,
756 SpriteKind::Melon => 0.7,
757 SpriteKind::OvenArabic => 3.2,
758 SpriteKind::FountainArabic => 2.4,
759 SpriteKind::Hearth => 2.3,
760 SpriteKind::ForgeTools => 2.8,
761 SpriteKind::CliffDecorBlock | SpriteKind::FireBlock => 1.0,
762 SpriteKind::Wood
763 | SpriteKind::Hardwood
764 | SpriteKind::Ironwood
765 | SpriteKind::Frostwood
766 | SpriteKind::Eldwood => 7.0 / 11.0,
767 SpriteKind::Bamboo => 9.0 / 11.0,
768 SpriteKind::MagicalBarrier => 3.0,
769 SpriteKind::MagicalSeal => 1.0,
770 SpriteKind::Helm => 1.909,
771 SpriteKind::Sign => 16.0 / 11.0,
772 SpriteKind::SmithingTable => 13.0 / 11.0,
773 SpriteKind::Forge0 => 17.0 / 11.0,
774 SpriteKind::GearWheel0 => 3.0 / 11.0,
775 SpriteKind::Quench0 => 8.0 / 11.0,
776 SpriteKind::HotSurface => 0.01,
777 SpriteKind::Barrel => 1.0,
778 SpriteKind::CrateBlock => 1.0,
779 SpriteKind::BarrelWoodWater | SpriteKind::BarrelWoodCoal => 1.545,
780 SpriteKind::LanternpostWoodLantern | SpriteKind::LanternpostWoodUpper => 2.000,
781 SpriteKind::LanternpostWoodBase => 3.000,
782 SpriteKind::LampMetalShinglesRed => 1.000,
783 SpriteKind::LampMetalShinglesCyan => 1.000,
784 SpriteKind::LampMetalBase => 2.818,
785 SpriteKind::LampTerracotta => 1.727,
786 SpriteKind::BlacksmithBellows => 0.545,
787 SpriteKind::CarpenterTable => 2.000,
788 SpriteKind::CarpenterCrateWoodS => 0.727,
789 SpriteKind::CarpenterCrateWoodL => 1.273,
790 SpriteKind::CarpenterLogCutter => 1.545,
791 SpriteKind::BasketWovenL | SpriteKind::JugClayM => 1.000,
792 SpriteKind::BasketWovenM => 0.909,
793 SpriteKind::BasketWovenS => 0.818,
794 SpriteKind::BonfireMLit | SpriteKind::BonfireMUnlit => 2.273,
795 SpriteKind::BucketWoodM | SpriteKind::SackLeatherM => 1.091,
796 SpriteKind::MirrorWoodM => 1.364,
797 SpriteKind::TrophyframeWoodBear => 1.455,
798 SpriteKind::TrophyframeWoodDeer => 1.727,
799 SpriteKind::ChestWoodDouble => 1.182,
800 SpriteKind::DiningtableWoodCorner => 1.273,
801 SpriteKind::DiningtableWoodBody => 1.273,
802 SpriteKind::BenchWoodEnd => 0.636,
803 SpriteKind::BenchWoodMiddle => 0.636,
804 SpriteKind::LogsWoodCoreEnd => 0.818,
805 SpriteKind::LogsWoodCoreMiddle => 0.818,
806 SpriteKind::LogsWoodBarkEnd => 1.091,
807 SpriteKind::LogsWoodBarkMiddle => 1.091,
808 SpriteKind::LogsWoodBranchEnd => 1.091,
809 SpriteKind::LogsWoodBranchMiddle => 1.091,
810 SpriteKind::LogsWoodBranchS => 1.091,
811 SpriteKind::SeatWoodBlueMiddle => 1.818,
812 SpriteKind::SeatWoodBlueSide => 1.818,
813 SpriteKind::LanternAirshipWallBlackS
814 | SpriteKind::LanternAirshipWallBrownS
815 | SpriteKind::LanternAirshipWallChestnutS
816 | SpriteKind::LanternAirshipWallRedS => 1.182,
817 SpriteKind::LanternAirshipGroundBlackS
818 | SpriteKind::LanternAirshipGroundBrownS
819 | SpriteKind::LanternAirshipGroundChestnutS
820 | SpriteKind::LanternAirshipGroundRedS => 0.909,
821 SpriteKind::RopeCoilM => 0.363,
822 SpriteKind::BedCliffHead => 0.636,
823 SpriteKind::BedCliffMiddle => 0.636,
824 SpriteKind::BedCliffTail => 0.636,
825 SpriteKind::BedCoastalHead => 0.636,
826 SpriteKind::BedCoastalMiddle => 0.636,
827 SpriteKind::BedCoastalTail => 0.636,
828 SpriteKind::BedDesertHead => 0.545,
829 SpriteKind::BedDesertMiddle => 0.545,
830 SpriteKind::BedDesertTail => 0.545,
831 SpriteKind::BedSavannahHead => 0.545,
832 SpriteKind::BedSavannahMiddle => 0.545,
833 SpriteKind::BedSavannahTail => 0.545,
834 SpriteKind::BedWoodWoodlandHead => 0.727,
835 SpriteKind::BedWoodWoodlandMiddle => 0.727,
836 SpriteKind::BedWoodWoodlandTail => 0.727,
837 SpriteKind::BookshelfEnd => 3.0,
838 SpriteKind::BookshelfMiddle => 3.0,
839 SpriteKind::BenchWoodWoodlandGreen1 => 1.545,
840 SpriteKind::BenchWoodWoodlandGreen2 => 1.545,
841 SpriteKind::BenchWoodWoodlandGreen3 => 1.545,
842 SpriteKind::BenchWoodWoodland => 1.545,
843 SpriteKind::ChairWoodWoodland => 1.636,
844 SpriteKind::ChairWoodWoodland2 => 1.727,
845 SpriteKind::CoatrackMetalWoodland => 2.364,
846 SpriteKind::CoatrackWoodWoodland => 2.364,
847 SpriteKind::Crate => 0.909,
848 SpriteKind::DrawerWoodWoodlandS => 1.000,
849 SpriteKind::DrawerWoodWoodlandM1 => 0.909,
850 SpriteKind::DrawerWoodWoodlandM2 => 0.909,
851 SpriteKind::DrawerWoodWoodlandL1 => 1.273,
852 SpriteKind::DrawerWoodWoodlandL2 => 1.273,
853 SpriteKind::DiningtableWoodWoodlandRound => 1.273,
854 SpriteKind::DiningtableWoodWoodlandSquare => 1.273,
855 SpriteKind::TableWoodFancyWoodlandCorner => 1.273,
856 SpriteKind::TableWoodFancyWoodlandBody => 1.273,
857 SpriteKind::WardrobesingleWoodWoodland => 2.364,
858 SpriteKind::WardrobesingleWoodWoodland2 => 2.364,
859 SpriteKind::WardrobedoubleWoodWoodland => 2.364,
860 SpriteKind::WardrobedoubleWoodWoodland2 => 2.364,
861 SpriteKind::FlowerpotWoodWoodlandS => 0.455,
862 SpriteKind::HandCartWoodHead => 1.091,
863 SpriteKind::HandCartWoodMiddle => 1.091,
864 SpriteKind::HandCartWoodTail => 1.091,
865 SpriteKind::HandrailWoodWoodlandBase | SpriteKind::HandrailWoodWoodlandMiddle => 1.727,
866 SpriteKind::HandrailWoodWoodlandTop => 1.181,
867 _ => return None,
868 })
869 }
870
871 pub fn valid_collision_dir(
872 &self,
873 entity_aabb: Aabb<f32>,
874 block_aabb: Aabb<f32>,
875 move_dir: Vec3<f32>,
876 parent: &Block,
877 ) -> bool {
878 match self {
879 SpriteKind::OneWayWall => {
880 let dir = entity_aabb.collision_vector_with_aabb(block_aabb);
882
883 let max_axis = dir.map(|e| e.abs()).reduce_partial_min();
886 let resolve_dir = -dir.map(|e| {
887 if e.abs().to_bits() == max_axis.to_bits() {
888 e.signum()
889 } else {
890 0.0
891 }
892 });
893
894 let is_moving_into = move_dir.dot(resolve_dir) <= 0.0;
895
896 is_moving_into
897 && parent.get_attr().is_ok_and(|Ori(ori)| {
898 Vec2::new(
899 0.0,
900 parent.get_attr::<MirrorY>().map_or(1.0, |m| match m.0 {
901 true => -1.0,
902 false => 1.0,
903 }),
904 )
905 .rotated_z(std::f32::consts::PI * 0.25 * ori as f32)
906 .with_z(0.0)
907 .map2(resolve_dir, |e, r| (e - r).abs() < 0.1)
908 .reduce_and()
909 })
910 },
911 _ => true,
912 }
913 }
914
915 #[inline]
924 pub fn default_loot_spec(&self) -> Option<Option<LootSpec<&'static str>>> {
925 let item = LootSpec::Item;
926 let table = LootSpec::LootTable;
927 Some(Some(match self {
928 SpriteKind::Apple => item("common.items.food.apple"),
929 SpriteKind::Mushroom => item("common.items.food.mushroom"),
930 SpriteKind::Velorite => item("common.items.mineral.ore.velorite"),
931 SpriteKind::VeloriteFrag => item("common.items.mineral.ore.veloritefrag"),
932 SpriteKind::RedFlower => item("common.items.flowers.red"),
936 SpriteKind::Sunflower => item("common.items.flowers.sunflower"),
939 SpriteKind::Lettuce => item("common.items.food.lettuce"),
943 SpriteKind::Coconut => item("common.items.food.coconut"),
944 SpriteKind::Beehive => item("common.items.crafting_ing.honey"),
945 SpriteKind::Stones => item("common.items.crafting_ing.stones"),
946 SpriteKind::Twigs => item("common.items.crafting_ing.twigs"),
947 SpriteKind::VialEmpty => item("common.items.crafting_ing.empty_vial"),
948 SpriteKind::Bowl => item("common.items.crafting_ing.bowl"),
949 SpriteKind::PotionMinor => item("common.items.consumable.potion_minor"),
950 SpriteKind::Amethyst => item("common.items.mineral.gem.amethyst"),
951 SpriteKind::Ruby => item("common.items.mineral.gem.ruby"),
952 SpriteKind::Diamond => item("common.items.mineral.gem.diamond"),
953 SpriteKind::Sapphire => item("common.items.mineral.gem.sapphire"),
954 SpriteKind::Topaz => item("common.items.mineral.gem.topaz"),
955 SpriteKind::Emerald => item("common.items.mineral.gem.emerald"),
956 SpriteKind::Bloodstone => item("common.items.mineral.ore.bloodstone"),
957 SpriteKind::Coal => item("common.items.mineral.ore.coal"),
958 SpriteKind::Cobalt => item("common.items.mineral.ore.cobalt"),
959 SpriteKind::Copper => item("common.items.mineral.ore.copper"),
960 SpriteKind::Iron => item("common.items.mineral.ore.iron"),
961 SpriteKind::Tin => item("common.items.mineral.ore.tin"),
962 SpriteKind::Silver => item("common.items.mineral.ore.silver"),
963 SpriteKind::Gold => item("common.items.mineral.ore.gold"),
964 SpriteKind::Cotton => item("common.items.crafting_ing.cotton_boll"),
965 SpriteKind::Moonbell => item("common.items.flowers.moonbell"),
966 SpriteKind::Pyrebloom => item("common.items.flowers.pyrebloom"),
967 SpriteKind::WildFlax => item("common.items.flowers.wild_flax"),
968 SpriteKind::Seashells => item("common.items.crafting_ing.seashells"),
969 SpriteKind::RoundCactus => item("common.items.crafting_ing.cactus"),
970 SpriteKind::ShortFlatCactus => item("common.items.crafting_ing.cactus"),
971 SpriteKind::MedFlatCactus => item("common.items.crafting_ing.cactus"),
972 SpriteKind::Bomb => item("common.items.utility.bomb"),
973 SpriteKind::DungeonChest0 => table("common.loot_tables.dungeon.gnarling.chest"),
974 SpriteKind::DungeonChest1 => table("common.loot_tables.dungeon.adlet.chest"),
975 SpriteKind::DungeonChest2 => table("common.loot_tables.dungeon.sahagin.chest"),
976 SpriteKind::DungeonChest3 => table("common.loot_tables.dungeon.haniwa.chest"),
977 SpriteKind::DungeonChest4 => table("common.loot_tables.dungeon.myrmidon.chest"),
978 SpriteKind::DungeonChest5 => table("common.loot_tables.dungeon.cultist.chest"),
979 SpriteKind::Chest => table("common.loot_tables.sprite.chest"),
980 SpriteKind::CommonLockedChest => table("common.loot_tables.dungeon.sahagin.chest"),
981 SpriteKind::ChestBuried => table("common.loot_tables.sprite.chest-buried"),
982 SpriteKind::CoralChest => table("common.loot_tables.dungeon.sea_chapel.chest_coral"),
983 SpriteKind::HaniwaUrn => table("common.loot_tables.dungeon.haniwa.key"),
984 SpriteKind::TerracottaChest => {
985 table("common.loot_tables.dungeon.terracotta.chest_terracotta")
986 },
987 SpriteKind::SahaginChest => table("common.loot_tables.dungeon.sahagin.key_chest"),
988 SpriteKind::Mud => table("common.loot_tables.sprite.mud"),
989 SpriteKind::Grave => table("common.loot_tables.sprite.mud"),
990 SpriteKind::Crate => table("common.loot_tables.sprite.crate"),
991 SpriteKind::Wood => item("common.items.log.wood"),
992 SpriteKind::Bamboo => item("common.items.log.bamboo"),
993 SpriteKind::Hardwood => item("common.items.log.hardwood"),
994 SpriteKind::Ironwood => item("common.items.log.ironwood"),
995 SpriteKind::Frostwood => item("common.items.log.frostwood"),
996 SpriteKind::Eldwood => item("common.items.log.eldwood"),
997 SpriteKind::MagicalBarrier => table("common.loot_tables.sprite.chest"),
998 SpriteKind::Keyhole
999 | SpriteKind::BoneKeyhole
1000 | SpriteKind::HaniwaKeyhole
1001 | SpriteKind::VampireKeyhole
1002 | SpriteKind::GlassKeyhole
1003 | SpriteKind::KeyholeBars
1004 | SpriteKind::SahaginKeyhole
1005 | SpriteKind::TerracottaKeyhole
1006 | SpriteKind::MyrmidonKeyhole
1007 | SpriteKind::MinotaurKeyhole => {
1008 return Some(None);
1009 },
1010 _ => return None,
1011 }))
1012 }
1013
1014 #[inline]
1020 pub fn default_tool(&self) -> Option<Option<ToolKind>> {
1021 self.default_loot_spec().map(|_| self.mine_tool())
1022 }
1023
1024 #[inline]
1035 pub fn is_defined_as_container(&self) -> bool { self.category() == Category::Container }
1036
1037 #[inline]
1038 pub fn should_drop_mystery(&self) -> bool {
1040 self.is_defined_as_container()
1041 || matches!(
1042 self.default_loot_spec(),
1043 Some(Some(LootSpec::LootTable { .. } | LootSpec::Lottery { .. }))
1044 )
1045 }
1046
1047 #[inline]
1049 pub fn mount_offset(&self) -> Option<(Vec3<f32>, Vec3<f32>)> {
1051 match self {
1052 SpriteKind::ChairWoodWoodland
1053 | SpriteKind::ChairWoodWoodland2
1054 | SpriteKind::BenchWoodWoodlandGreen1
1055 | SpriteKind::BenchWoodWoodlandGreen2
1056 | SpriteKind::BenchWoodWoodlandGreen3
1057 | SpriteKind::BenchWoodWoodland
1058 | SpriteKind::BenchWoodEnd
1059 | SpriteKind::BenchWoodMiddle
1060 | SpriteKind::BenchCoastal => Some((Vec3::new(0.0, 0.0, 0.5), Vec3::unit_x())),
1061 SpriteKind::SeatWoodBlueMiddle | SpriteKind::SeatWoodBlueSide => {
1062 Some((Vec3::new(0.4, 0.0, 0.5), Vec3::unit_x()))
1063 },
1064 SpriteKind::Helm => Some((Vec3::new(0.0, -1.1, 0.0), Vec3::unit_y())),
1065 SpriteKind::BedWoodWoodlandHead
1066 | SpriteKind::BedCliffHead
1067 | SpriteKind::BedDesertHead
1068 | SpriteKind::BedCoastalHead
1069 | SpriteKind::BedSavannahHead => Some((Vec3::new(1.4, 0.0, 0.5), Vec3::unit_x())),
1070 SpriteKind::BedMesa => Some((Vec3::new(0.0, 0.0, 0.6), -Vec3::unit_y())),
1071 SpriteKind::BedrollSnow | SpriteKind::BedrollPirate => {
1072 Some((Vec3::new(0.0, 0.0, 0.1), -Vec3::unit_x()))
1073 },
1074 SpriteKind::Bedroll => Some((Vec3::new(0.0, 0.0, 0.1), Vec3::unit_y())),
1075 _ => None,
1076 }
1077 }
1078
1079 pub fn is_bed(&self) -> bool {
1080 matches!(
1081 self,
1082 SpriteKind::BedWoodWoodlandHead
1083 | SpriteKind::BedMesa
1084 | SpriteKind::BedCliffHead
1085 | SpriteKind::BedCoastalHead
1086 | SpriteKind::BedDesertHead
1087 | SpriteKind::BedSavannahHead
1088 | SpriteKind::Bedroll
1089 | SpriteKind::BedrollSnow
1090 | SpriteKind::BedrollPirate
1091 )
1092 }
1093
1094 #[inline]
1095 pub fn is_mountable(&self) -> bool { self.mount_offset().is_some() }
1096
1097 #[inline]
1099 pub fn mount_buffs(&self) -> Option<Vec<BuffEffect>> {
1100 match self {
1101 SpriteKind::BedWoodWoodlandHead
1102 | SpriteKind::BedMesa
1103 | SpriteKind::BedrollSnow
1104 | SpriteKind::BedrollPirate
1105 | SpriteKind::Bedroll => Some(vec![BuffEffect {
1106 kind: BuffKind::RestingHeal,
1107 data: BuffData::new(0.02, Some(Secs(1.0))),
1108 cat_ids: Vec::new(),
1109 }]),
1110 _ => None,
1111 }
1112 }
1113
1114 #[inline]
1115 pub fn is_controller(&self) -> bool { matches!(self, SpriteKind::Helm) }
1116
1117 #[inline]
1118 pub fn is_door(&self) -> bool {
1119 matches!(
1120 self,
1121 SpriteKind::Door | SpriteKind::DoorWide | SpriteKind::DoorDark
1122 )
1123 }
1124
1125 #[inline]
1127 pub fn mine_tool(&self) -> Option<ToolKind> {
1128 match self {
1129 SpriteKind::Velorite
1130 | SpriteKind::VeloriteFrag
1131 | SpriteKind::Amethyst
1133 | SpriteKind::Ruby
1134 | SpriteKind::Diamond
1135 | SpriteKind::Sapphire
1136 | SpriteKind::Emerald
1137 | SpriteKind::Topaz
1138 | SpriteKind::Bloodstone
1139 | SpriteKind::Coal
1140 | SpriteKind::Cobalt
1141 | SpriteKind::Copper
1142 | SpriteKind::Iron
1143 | SpriteKind::Tin
1144 | SpriteKind::Silver
1145 | SpriteKind::Gold => Some(ToolKind::Pick),
1146 SpriteKind::Grave | SpriteKind::Mud => Some(ToolKind::Shovel),
1147 _ => None,
1148 }
1149 }
1150
1151 pub fn required_mine_damage(&self) -> Option<u8> {
1152 Some(match self {
1153 SpriteKind::Gold => 6,
1154 SpriteKind::Silver => 6,
1155 SpriteKind::Bloodstone => 6,
1156 SpriteKind::Cobalt => 6,
1157 SpriteKind::Coal => 6,
1158 SpriteKind::Iron => 6,
1159 SpriteKind::Copper => 3,
1160 SpriteKind::Tin => 3,
1161 SpriteKind::Amethyst => 3,
1162 SpriteKind::Ruby => 6,
1163 SpriteKind::Sapphire => 3,
1164 SpriteKind::Emerald => 3,
1165 SpriteKind::Topaz => 3,
1166 SpriteKind::Diamond => 6,
1167 SpriteKind::Velorite => 3,
1168 SpriteKind::VeloriteFrag => 2,
1169 _ => return None,
1170 })
1171 }
1172
1173 pub fn mine_drop_interval(&self) -> u8 {
1176 match self {
1177 SpriteKind::Gold => 2,
1178 SpriteKind::Silver => 2,
1179 SpriteKind::Bloodstone => 2,
1180 SpriteKind::Cobalt => 2,
1181 SpriteKind::Coal => 2,
1182 SpriteKind::Iron => 2,
1183 SpriteKind::Copper => 1,
1184 SpriteKind::Tin => 1,
1185 SpriteKind::Emerald => 1,
1186 SpriteKind::Sapphire => 1,
1187 SpriteKind::Amethyst => 1,
1188 SpriteKind::Topaz => 1,
1189 SpriteKind::Diamond => 2,
1190 SpriteKind::Ruby => 2,
1191 SpriteKind::Velorite => 1,
1192 SpriteKind::VeloriteFrag => 1,
1193 _ => 1,
1194 }
1195 }
1196
1197 pub fn unlock_condition(&self, cfg: Option<SpriteCfg>) -> UnlockKind {
1203 cfg.and_then(|cfg| cfg.unlock)
1204 .unwrap_or_else(|| match self {
1205 SpriteKind::CommonLockedChest => UnlockKind::Consumes(
1206 ItemDefinitionIdOwned::Simple(String::from("common.items.utility.lockpick_0")),
1207 ),
1208 SpriteKind::SahaginKeyhole => UnlockKind::Consumes(ItemDefinitionIdOwned::Simple(
1209 String::from("common.items.keys.sahagin_key"),
1210 )),
1211 SpriteKind::BoneKeyhole => UnlockKind::Consumes(ItemDefinitionIdOwned::Simple(
1212 String::from("common.items.keys.bone_key"),
1213 )),
1214 SpriteKind::HaniwaKeyhole => UnlockKind::Consumes(ItemDefinitionIdOwned::Simple(
1215 String::from("common.items.keys.haniwa_key"),
1216 )),
1217 SpriteKind::VampireKeyhole => UnlockKind::Consumes(ItemDefinitionIdOwned::Simple(
1218 String::from("common.items.keys.vampire_key"),
1219 )),
1220 SpriteKind::GlassKeyhole => UnlockKind::Consumes(ItemDefinitionIdOwned::Simple(
1221 String::from("common.items.keys.glass_key"),
1222 )),
1223 SpriteKind::TerracottaChest => UnlockKind::Consumes(
1224 ItemDefinitionIdOwned::Simple(String::from(
1225 "common.items.keys.terracotta_key_chest",
1226 ))
1227 .to_owned(),
1228 ),
1229 SpriteKind::TerracottaKeyhole => UnlockKind::Consumes(
1230 ItemDefinitionIdOwned::Simple(String::from(
1231 "common.items.keys.terracotta_key_door",
1232 ))
1233 .to_owned(),
1234 ),
1235 SpriteKind::MyrmidonKeyhole => UnlockKind::Consumes(
1236 ItemDefinitionIdOwned::Simple(String::from("common.items.keys.myrmidon_key"))
1237 .to_owned(),
1238 ),
1239 SpriteKind::MinotaurKeyhole => UnlockKind::Consumes(
1240 ItemDefinitionIdOwned::Simple(String::from("common.items.keys.minotaur_key"))
1241 .to_owned(),
1242 ),
1243 _ => UnlockKind::Free,
1244 })
1245 }
1246
1247 pub fn content(&self, cfg: Option<SpriteCfg>) -> Option<Content> {
1249 cfg.and_then(|cfg| cfg.content)
1250 }
1251
1252 #[inline]
1254 pub fn has_ori(&self) -> bool { self.category().has_attr::<Ori>() }
1255}
1256
1257impl fmt::Display for SpriteKind {
1258 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:?}", self) }
1259}
1260
1261use strum::IntoEnumIterator;
1262
1263lazy_static! {
1264 pub static ref SPRITE_KINDS: HashMap<String, SpriteKind> =
1265 SpriteKind::iter().map(|sk| (sk.to_string(), sk)).collect();
1266}
1267
1268impl<'a> TryFrom<&'a str> for SpriteKind {
1269 type Error = ();
1270
1271 #[inline]
1272 fn try_from(s: &'a str) -> Result<Self, Self::Error> { SPRITE_KINDS.get(s).copied().ok_or(()) }
1273}
1274
1275#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
1276pub enum UnlockKind {
1277 Free,
1279 Requires(ItemDefinitionIdOwned),
1282 Consumes(ItemDefinitionIdOwned),
1285}
1286
1287#[derive(Default, PartialEq, Clone, Debug, Serialize, Deserialize)]
1288pub struct SpriteCfg {
1289 pub unlock: Option<UnlockKind>,
1291 pub content: Option<Content>,
1296 pub loot_table: Option<String>,
1309}
1310
1311#[cfg(test)]
1312pub mod tests {
1313 use super::*;
1314
1315 #[test]
1316 fn sprite_conv_kind() {
1317 for sprite in SpriteKind::all() {
1318 let block = Block::air(*sprite);
1319 assert_eq!(block.sprite_category(), Some(sprite.category()));
1320 assert_eq!(block.get_sprite(), Some(*sprite));
1321 }
1322 }
1323
1324 #[test]
1325 fn sprite_attr() {
1326 for category in Category::all() {
1327 if category.has_attr::<Ori>() {
1328 for sprite in category.all_sprites() {
1329 for i in 0..4 {
1330 let block = Block::air(*sprite).with_attr(Ori(i)).unwrap();
1331 assert_eq!(block.get_attr::<Ori>().unwrap(), Ori(i));
1332 assert_eq!(block.get_sprite(), Some(*sprite));
1333 }
1334 }
1335 }
1336 if category.has_attr::<Growth>() {
1337 for sprite in category.all_sprites() {
1338 for i in 0..16 {
1339 let block = Block::air(*sprite).with_attr(Growth(i)).unwrap();
1340 assert_eq!(block.get_attr::<Growth>().unwrap(), Growth(i));
1341 assert_eq!(block.get_sprite(), Some(*sprite));
1342 }
1343 }
1344 }
1345 }
1346 }
1347}