First Machine Age's Mods (Combined repo.)
修订版 | e00a7319a14c585230ff0838eb39aa5cf1778199 (tree) |
---|---|
时间 | 2020-05-05 09:04:57 |
作者 | melchior <melchior@user...> |
Commiter | melchior |
Fix for B.E. null on absence in world crash,
boudning box for slot
@@ -14,6 +14,8 @@ namespace FirstMachineAge | ||
14 | 14 | private ICoreServerAPI ServerAPI; |
15 | 15 | private ServerCoreAPI ServerCore { get; set; } |
16 | 16 | |
17 | + public const string BoltableDoorEntityNameKey = @"BoltableDoorEntity"; | |
18 | + | |
17 | 19 | public override bool AllowRuntimeReload { |
18 | 20 | get { return false; } |
19 | 21 | } |
@@ -57,7 +59,7 @@ namespace FirstMachineAge | ||
57 | 59 | private void RegisterBlockClasses( ) |
58 | 60 | { |
59 | 61 | CoreAPI.RegisterBlockClass("BoltableDoor", typeof(BoltableDoor)); |
60 | - CoreAPI.RegisterBlockEntityClass("BoltableDoorEntity", typeof(BoltableDoorBlockEntity)); | |
62 | + CoreAPI.RegisterBlockEntityClass(BoltableDoorEntityNameKey, typeof(BoltableDoorBlockEntity)); | |
61 | 63 | } |
62 | 64 | |
63 | 65 | private void RegisterBehaviorClasses( ) |
@@ -28,7 +28,14 @@ namespace FirstMachineAge | ||
28 | 28 | upperPos = here.UpCopy( ); |
29 | 29 | } |
30 | 30 | |
31 | - return api.World.BlockAccessor.GetBlockEntity(upperPos) as BoltableDoorBlockEntity; | |
31 | + var doorEntity = api.World.BlockAccessor.GetBlockEntity(upperPos) as BoltableDoorBlockEntity; | |
32 | + | |
33 | + if (doorEntity == null) { | |
34 | + api.World.Logger.Warning($"BoltableDoor [{here}]: BlockEntity NULL! (regenerating)" ); | |
35 | + api.World.BlockAccessor.SpawnBlockEntity(AssortedModSystems.BoltableDoorEntityNameKey, here); | |
36 | + } | |
37 | + | |
38 | + return doorEntity; | |
32 | 39 | } |
33 | 40 | |
34 | 41 | public override BlockFacing GetDirection( ) |
@@ -51,9 +58,13 @@ namespace FirstMachineAge | ||
51 | 58 | if (!this.DoesBehaviorAllow(world, byPlayer, selBox)) { |
52 | 59 | return true; |
53 | 60 | } |
61 | + | |
54 | 62 | BlockPos position = selBox.Position; |
55 | 63 | var doorEntity = this.Entity(position); |
56 | 64 | var clientPlayer = byPlayer as IClientPlayer; |
65 | + | |
66 | + if (doorEntity == null) return false;//Corrupted world! | |
67 | + | |
57 | 68 | if (selBox.SelectionBoxIndex == 0) |
58 | 69 | { |
59 | 70 | if (doorEntity.Bolted == false) |
@@ -41,8 +41,7 @@ namespace FirstMachineAge | ||
41 | 41 | public override void GetBlockInfo(IPlayer forPlayer, StringBuilder dsc) |
42 | 42 | { |
43 | 43 | base.GetBlockInfo(forPlayer, dsc); |
44 | - var boltableDoor = this.Block as BoltableDoor; | |
45 | - BoltableDoorBlockEntity realEntity = boltableDoor.Entity(this.Pos.Copy( )); | |
44 | + BoltableDoorBlockEntity realEntity = (this.Block as BoltableDoor).Entity(this.Pos.Copy( )); | |
46 | 45 | if (realEntity != null) dsc.AppendLine($"Bolted: {(realEntity.Bolted?"<font color='red'>Yes</font>":"No")}"); |
47 | 46 | } |
48 | 47 | } |