Skip to content

Commit 92ea998

Browse files
committed
add block and world accessor extensions (wip #9)
1 parent 847afd3 commit 92ea998

14 files changed

Lines changed: 241 additions & 22 deletions

File tree

Common.Mod.Common/Config/IConfigSystem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
using JetBrains.Annotations;
12
using Vintagestory.API.Server;
23

34
namespace Common.Mod.Common.Config;
45

6+
[UsedImplicitly(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Members)]
57
public interface IConfigSystem
68
{
79
#region Event delegates

Common.Mod.Common/Core/LogEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Common.Mod.Common.Core;
44

5-
[UsedImplicitly(ImplicitUseKindFlags.Access, ImplicitUseTargetFlags.Members)]
5+
[UsedImplicitly(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Members)]
66
public record LogEntry
77
{
88
public DateTime Timestamp { get; init; }

Common.Mod.Generator/Specs/ConfigEntrySpec.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Common.Mod.Generator.Specs;
44

5-
[UsedImplicitly(ImplicitUseKindFlags.Assign, ImplicitUseTargetFlags.Members)]
5+
[UsedImplicitly(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Members)]
66
public record ConfigEntrySpec
77
{
88
public string Name { get; set; } = null!;

Common.Mod.Generator/Specs/ConfigEnumSpec.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Common.Mod.Generator.Specs;
55

6-
[UsedImplicitly(ImplicitUseKindFlags.Assign, ImplicitUseTargetFlags.Members)]
6+
[UsedImplicitly(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Members)]
77
public record ConfigEnumSpec
88
{
99
public string EnumName { get; set; } = null!;

Common.Mod.Generator/Specs/ConfigSpec.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Common.Mod.Generator.Specs;
55

6-
[UsedImplicitly(ImplicitUseKindFlags.Assign, ImplicitUseTargetFlags.Members)]
6+
[UsedImplicitly(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Members)]
77
public record ConfigSpec
88
{
99
public string ClassName { get; set; } = null!;

Common.Mod.Generator/Specs/RootConfigSpec.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Common.Mod.Generator.Specs;
44

5-
[UsedImplicitly(ImplicitUseKindFlags.Assign, ImplicitUseTargetFlags.Members)]
5+
[UsedImplicitly(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Members)]
66
public record RootConfigSpec : ConfigSpec
77
{
88
public string Version { get; set; } = null!;

Common.Mod.Generator/Specs/RootConfigTypeSpec.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Common.Mod.Generator.Specs;
44

5-
[UsedImplicitly(ImplicitUseKindFlags.Access, ImplicitUseTargetFlags.Members)]
5+
[UsedImplicitly(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Members)]
66
public enum RootConfigTypeSpec
77
{
88
Common,

Common.Mod/Blocks/MultiblockBlock.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public override Cuboidf[] GetParticleCollisionBoxes(IBlockAccessor blockAccessor
2222
);
2323
}
2424

25-
// This is copy-pasted from the `BlockMultiblock` class where it is private
25+
// This is more or less copy-pasted from the `BlockMultiblock` class where it is private
2626
private static T Handle<T, TK>(
2727
IBlockAccessor blockAccessor,
2828
int x,
@@ -35,24 +35,13 @@ BlockCallDelegateBlock<T> onOtherwise
3535
where TK : class
3636
{
3737
var block = blockAccessor.GetBlock((new Vec3i(x, y, z)).ToBlockPos());
38-
var blockInf = block as TK;
39-
40-
if (blockInf == null)
41-
{
42-
blockInf = block.GetBehavior(typeof(TK), true) as TK;
43-
}
38+
var blockInf = block as TK ?? block.GetBehavior(typeof(TK), true) as TK;
4439

4540
if (blockInf != null)
4641
{
4742
return onImplementsInterface(blockInf);
4843
}
4944

50-
// This is to prevent endless recursion in situations where blocks become incorrectly arranged
51-
if (block is BlockMultiblock)
52-
{
53-
return onIsMultiblock(block);
54-
}
55-
56-
return onOtherwise(block);
45+
return block is BlockMultiblock ? onIsMultiblock(block) : onOtherwise(block);
5746
}
5847
}

Common.Mod/Common.Mod.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
<HintPath>../vendor/VintagestoryAPI.dll</HintPath>
2222
<Private>false</Private>
2323
</Reference>
24+
<Reference Include="VintagestoryLib">
25+
<HintPath>../vendor/VintagestoryLib.dll</HintPath>
26+
<Private>false</Private>
27+
</Reference>
2428
<Reference Include="VSEssentials">
2529
<HintPath>../vendor/VSEssentials.dll</HintPath>
2630
<Private>false</Private>

Common.Mod/Core/FileSystem.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Common.Mod.Common.Core;
22
using Vintagestory.API.Common;
3-
using Vintagestory.API.Config;
43

54
namespace Common.Mod.Core;
65

0 commit comments

Comments
 (0)