Skip to content

Commit 36665f8

Browse files
committed
add common namespace and stuff (wip #3)
1 parent 306aae4 commit 36665f8

9 files changed

Lines changed: 114 additions & 10 deletions

File tree

Common.Mod.Example/Common.Mod.Example.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
</ItemGroup>
3737

3838
<ItemGroup>
39-
<!--<PackageReference Include="Common.Mod" Version="12.34.56"/>-->
39+
<PackageReference Include="Common.Mod" Version="12.34.56"/>
4040
<PackageReference Include="JetBrains.Annotations" Version="2025.2.2">
4141
<ExcludeAssets>runtime</ExcludeAssets>
4242
</PackageReference>
4343
</ItemGroup>
4444

4545
<ItemGroup>
46-
<ProjectReference Include="../Common.Mod/Common.Mod.csproj"/>
46+
<!--<ProjectReference Include="../Common.Mod/Common.Mod.csproj"/>-->
4747
<ProjectReference Include="../Common.Mod.Generator/Common.Mod.Generator.csproj">
4848
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
4949
<OutputItemType>Analyzer</OutputItemType>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using Vintagestory.API.Common;
3+
using Vintagestory.API.MathTools;
4+
5+
namespace Common.Mod.Blocks;
6+
7+
public interface IMultiBlockParticleColBoxes
8+
{
9+
[SuppressMessage("ReSharper", "InconsistentNaming")]
10+
public Cuboidf[] MBGetParticleCollisionBoxes(IBlockAccessor blockAccessor, BlockPos pos, Vec3i offset);
11+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using JetBrains.Annotations;
2+
using Vintagestory.API.Common;
3+
using Vintagestory.API.MathTools;
4+
using Vintagestory.GameContent;
5+
6+
namespace Common.Mod.Blocks;
7+
8+
// TODO: Remove this class if https://github.com/anegostudios/vsessentialsmod/pull/31 gets merged
9+
[UsedImplicitly]
10+
public class MultiblockBlock : BlockMultiblock
11+
{
12+
public const string RegistryId = "MultiblockBlock";
13+
14+
public override Cuboidf[] GetParticleCollisionBoxes(IBlockAccessor blockAccessor, BlockPos pos)
15+
{
16+
return Handle<Cuboidf[], IMultiBlockParticleColBoxes>(
17+
blockAccessor,
18+
pos.X + OffsetInv.X, pos.InternalY + OffsetInv.Y, pos.Z + OffsetInv.Z,
19+
(inf) => inf.MBGetParticleCollisionBoxes(blockAccessor, pos, OffsetInv),
20+
_ => [Cuboidf.Default()],
21+
block => block.GetParticleCollisionBoxes(blockAccessor, pos.AddCopy(OffsetInv))
22+
);
23+
}
24+
25+
// This is copy-pasted from the `BlockMultiblock` class where it is private
26+
private static T Handle<T, TK>(
27+
IBlockAccessor blockAccessor,
28+
int x,
29+
int y,
30+
int z,
31+
BlockCallDelegateInterface<T, TK> onImplementsInterface,
32+
BlockCallDelegateBlock<T> onIsMultiblock,
33+
BlockCallDelegateBlock<T> onOtherwise
34+
)
35+
where TK : class
36+
{
37+
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+
}
44+
45+
if (blockInf != null)
46+
{
47+
return onImplementsInterface(blockInf);
48+
}
49+
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);
57+
}
58+
}

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="VSEssentials">
25+
<HintPath>../vendor/VSEssentials.dll</HintPath>
26+
<Private>false</Private>
27+
</Reference>
2428

2529
<Reference Include="protobuf-net">
2630
<HintPath>../vendor/protobuf-net.dll</HintPath>

Common.Mod/System.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Common.Mod.Blocks;
12
using Common.Mod.Common.Config;
23
using Common.Mod.Common.Core;
34
using Common.Mod.Config;
@@ -216,6 +217,10 @@ protected virtual void ClientStartPre(ICoreClientAPI api)
216217
[UsedImplicitly]
217218
protected virtual void RegisterClasses(ICoreAPI api)
218219
{
220+
if (api.ClassRegistry.GetBlockClass($"common:{MultiblockBlock.RegistryId}") is null)
221+
{
222+
api.RegisterBlockClass($"common:{MultiblockBlock.RegistryId}", typeof(MultiblockBlock));
223+
}
219224
}
220225

221226
#endregion Virtuals

Common.Mod/assets/blocktypes/multiblock.json renamed to Common.Mod/assets/common/blocktypes/multiblock.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
{
22
"code": "multiblock",
3-
"class": "VFBlockMultiblock",
3+
"class": "common:MultiblockBlock",
44
"handbook": {
55
"exclude": true
66
},
7-
"variantgroups": [
7+
"creativeInventory": {
8+
"common": [
9+
"*"
10+
]
11+
},
12+
"variantGroups": [
813
{
914
"code": "type",
1015
"states": [
@@ -46,14 +51,14 @@
4651
"shape": {
4752
"base": "game:block/basic/nothing"
4853
},
49-
"drawtype": "json",
50-
"sidesolid": {
54+
"drawType": "json",
55+
"sideSolid": {
5156
"all": false
5257
},
53-
"sideopaque": {
58+
"sideOpaque": {
5459
"all": false
5560
},
56-
"blockmaterial": "Wood",
61+
"blockMaterial": "Wood",
5762
"replaceable": 160,
5863
"resistance": 4,
5964
"lightAbsorption": 0,
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<Project>
22
<ItemGroup>
3-
<Assets Include="$(MSBuildThisFileDirectory)/../assets/**/*"/>
3+
<LocalAssets Include="$(MSBuildThisFileDirectory)/../assets/common/**/*"/>
4+
<RemoteAssets Include="$(MSBuildThisFileDirectory)/../assets/**/*" Exclude="$(MSBuildThisFileDirectory)/../assets/common/**/*"/>
45
</ItemGroup>
56
<Target Name="CopyAssets" BeforeTargets="Build">
6-
<Copy SourceFiles="@(Assets)" DestinationFolder="$(TargetDir)assets/$(ModId)/%(RecursiveDir)"/>
7+
<Copy SourceFiles="@(LocalAssets)" DestinationFolder="$(TargetDir)assets/common/%(RecursiveDir)"/>
8+
<Copy SourceFiles="@(RemoteAssets)" DestinationFolder="$(TargetDir)assets/$(ModId)/%(RecursiveDir)"/>
79
</Target>
810
</Project>

bootstrap.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ done
2121
# Fetch Vintage Story files
2222
vsFiles=(
2323
"Lib/protobuf-net.dll"
24+
"Mods/VSEssentials.dll"
2425
"VintagestoryAPI.dll"
2526
)
2627
for vsFile in "${vsFiles[@]}"; do

localbuild.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
./build.sh --target Package --general-project Common.Mod --general-skipSubstitution true
6+
./build.sh --target Package --general-project Common.Mod.Common --general-skipSubstitution true
7+
./build.sh --target Package --general-project Common.Mod.Generator --general-skipSubstitution true
8+
9+
mkdir -p out/Common.Mod/12.34.56
10+
mkdir -p out/Common.Mod.Common/12.34.56
11+
mkdir -p out/Common.Mod.Generator/12.34.56
12+
13+
cp out/Common.Mod.12.34.56.nupkg out/Common.Mod/12.34.56/Common.Mod.12.34.56.nupkg
14+
cp out/Common.Mod.Common.12.34.56.nupkg out/Common.Mod.Common/12.34.56/Common.Mod.Common.12.34.56.nupkg
15+
cp out/Common.Mod.Generator.12.34.56.nupkg out/Common.Mod.Generator/12.34.56/Common.Mod.Generator.12.34.56.nupkg
16+
17+
dotnet nuget locals all --clear
18+
dotnet restore

0 commit comments

Comments
 (0)