Skip to content

Commit 9480c0d

Browse files
committed
made search areas a sphere / cylinder (closes #11)
1 parent cee411a commit 9480c0d

7 files changed

Lines changed: 77 additions & 65 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 21.2.0
22
**:sparkles: Features**
33
- Made each mode variant toggleable ([#10](https://git.omni.ms/vintage-story-mods/durable-better-prospecting/issues/10))
4+
- Made the modes use spherical / cylindrical walk blocks functions instead of the vanilla cuboid ones ([#11](https://git.omni.ms/vintage-story-mods/durable-better-prospecting/issues/11))
45

56
**:bug: Bug Fixes**
67
- Re-added mod icon ([#12](https://git.omni.ms/vintage-story-mods/durable-better-prospecting/issues/12))

DurableBetterProspecting/Core/PickaxeMode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal record PickaxeMode
77
public required Icon Icon { get; init; }
88
public required SampleShape SampleShape { get; init; }
99
public required SampleType SampleType { get; init; }
10-
public required int SampleSize { get; init; }
10+
public required int SampleRadius { get; init; }
1111
public required int DurabilityCost { get; init; }
1212
public required bool Enabled { get; init; }
1313
}

DurableBetterProspecting/Core/SampleShape.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ namespace DurableBetterProspecting.Core;
33
internal enum SampleShape
44
{
55
Vanilla,
6-
Cube,
7-
Cuboid
6+
Sphere,
7+
Cylinder
88
}

DurableBetterProspecting/Items/ItemProspectingPick.cs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Common.Mod.Common.Config;
2+
using Common.Mod.Extensions;
23
using DryIoc;
34
using DurableBetterProspecting.Core;
45
using DurableBetterProspecting.Managers;
@@ -146,24 +147,18 @@ PickaxeMode mode
146147
}
147148

148149
if (_channel is not IServerNetworkChannel serverChannel
149-
|| world is not ServerMain serverWorld
150150
|| player.Player is not IServerPlayer serverPlayer)
151151
{
152152
return;
153153
}
154154

155155
var sampleShape = mode.SampleShape;
156156
var sampleType = mode.SampleType;
157-
var sampleSize = mode.SampleSize;
158-
159-
var halfSize = (int)MathF.Round(sampleSize / 2.0f);
160-
var bottomPosition = sampleShape is SampleShape.Cube ? position.Y - halfSize : 0;
161-
var topPosition = sampleShape is SampleShape.Cube ? position.Y + halfSize : serverWorld.MapSize.Y;
162-
var minPosition = new Vec3i(position.X - halfSize, bottomPosition, position.Z - halfSize).ToBlockPos();
163-
var maxPosition = new Vec3i(position.X + halfSize, topPosition, position.Z + halfSize).ToBlockPos();
157+
var sampleRadius = mode.SampleRadius;
164158

159+
// Handler
165160
Dictionary<string, Reading> readings = [];
166-
serverWorld.BlockAccessor.WalkBlocks(minPosition, maxPosition, (block, x, y, z) =>
161+
void OnBlockHandler(Block block, int x, int y, int z)
167162
{
168163
switch (sampleType)
169164
{
@@ -224,13 +219,29 @@ PickaxeMode mode
224219
default:
225220
throw new ArgumentOutOfRangeException(nameof(sampleType), sampleType, null);
226221
}
227-
});
222+
}
223+
224+
switch (sampleShape)
225+
{
226+
case SampleShape.Sphere:
227+
world.WalkBlocksSphere(position, sampleRadius, OnBlockHandler);
228+
break;
229+
230+
case SampleShape.Cylinder:
231+
var worldHeight = world.BlockAccessor.MapSizeY;
232+
world.WalkBlocksCylinder(position, sampleRadius, 0, worldHeight, OnBlockHandler);
233+
break;
234+
235+
case SampleShape.Vanilla:
236+
default:
237+
throw new ArgumentOutOfRangeException(nameof(sampleShape), sampleShape, null);
238+
}
228239

229240
var markerEligible = mode.Id is Constants.ColumnModeId or Constants.DistanceLongModeId or Constants.QuantityLongModeId;
230241
var readingPacket = new ReadingPacket
231242
{
232243
Mode = mode.Id,
233-
Size = mode.SampleSize,
244+
Size = mode.SampleRadius,
234245
Position = markerEligible ? position.ToVec3i() : null,
235246
Readings = readings.Values.ToArray(),
236247
};

DurableBetterProspecting/Managers/ModeManager.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private void CreateModes()
106106
Icon = Icon.Create("game", "heatmap"),
107107
SampleShape = SampleShape.Vanilla,
108108
SampleType = SampleType.Vanilla,
109-
SampleSize = int.MaxValue,
109+
SampleRadius = int.MaxValue,
110110
DurabilityCost = _commonConfig.DensityMode.DurabilityCost,
111111
Enabled = _commonConfig.DensityMode.Enabled
112112
};
@@ -118,7 +118,7 @@ private void CreateModes()
118118
Icon = Icon.Create("game", "rocks"),
119119
SampleShape = SampleShape.Vanilla,
120120
SampleType = SampleType.Vanilla,
121-
SampleSize = int.MaxValue,
121+
SampleRadius = int.MaxValue,
122122
DurabilityCost = _commonConfig.NodeMode.DurabilityCost,
123123
Enabled = _commonConfig.NodeMode.Enabled && _api.World.Config.GetString(Constants.NodeSearchRadiusConfigKey).ToInt() > 0
124124
};
@@ -128,9 +128,9 @@ private void CreateModes()
128128
Id = Constants.RockModeId,
129129
Name = _translations.Get("mode--rock"),
130130
Icon = Icon.Create("mode_rock"),
131-
SampleShape = SampleShape.Cube,
131+
SampleShape = SampleShape.Sphere,
132132
SampleType = SampleType.Rock,
133-
SampleSize = _commonConfig.RockMode.SampleSize,
133+
SampleRadius = _commonConfig.RockMode.SampleSize,
134134
DurabilityCost = _commonConfig.RockMode.DurabilityCost,
135135
Enabled = _commonConfig.RockMode.Enabled
136136
};
@@ -140,9 +140,9 @@ private void CreateModes()
140140
Id = Constants.ColumnModeId,
141141
Name = _translations.Get("mode--column"),
142142
Icon = Icon.Create("mode_column"),
143-
SampleShape = SampleShape.Cuboid,
143+
SampleShape = SampleShape.Cylinder,
144144
SampleType = SampleType.Ore,
145-
SampleSize = _commonConfig.ColumnMode.SampleSize,
145+
SampleRadius = _commonConfig.ColumnMode.SampleSize,
146146
DurabilityCost = _commonConfig.ColumnMode.DurabilityCost,
147147
Enabled = _commonConfig.ColumnMode.Enabled
148148
};
@@ -152,9 +152,9 @@ private void CreateModes()
152152
Id = Constants.DistanceShortModeId,
153153
Name = _translations.Get("mode--distance-short"),
154154
Icon = Icon.Create("mode_distance_short"),
155-
SampleShape = SampleShape.Cube,
155+
SampleShape = SampleShape.Sphere,
156156
SampleType = SampleType.Ore,
157-
SampleSize = _commonConfig.DistanceMode.SampleSizeShort,
157+
SampleRadius = _commonConfig.DistanceMode.SampleSizeShort,
158158
DurabilityCost = _commonConfig.DistanceMode.DurabilityCostShort,
159159
Enabled = _commonConfig.DistanceMode.EnabledShort
160160
};
@@ -164,9 +164,9 @@ private void CreateModes()
164164
Id = Constants.DistanceMediumModeId,
165165
Name = _translations.Get("mode--distance-medium"),
166166
Icon = Icon.Create("mode_distance_medium"),
167-
SampleShape = SampleShape.Cube,
167+
SampleShape = SampleShape.Sphere,
168168
SampleType = SampleType.Ore,
169-
SampleSize = _commonConfig.DistanceMode.SampleSizeMedium,
169+
SampleRadius = _commonConfig.DistanceMode.SampleSizeMedium,
170170
DurabilityCost = _commonConfig.DistanceMode.DurabilityCostMedium,
171171
Enabled = _commonConfig.DistanceMode.EnabledMedium
172172
};
@@ -176,9 +176,9 @@ private void CreateModes()
176176
Id = Constants.DistanceLongModeId,
177177
Name = _translations.Get("mode--distance-long"),
178178
Icon = Icon.Create("mode_distance_long"),
179-
SampleShape = SampleShape.Cube,
179+
SampleShape = SampleShape.Sphere,
180180
SampleType = SampleType.Ore,
181-
SampleSize = _commonConfig.DistanceMode.SampleSizeLong,
181+
SampleRadius = _commonConfig.DistanceMode.SampleSizeLong,
182182
DurabilityCost = _commonConfig.DistanceMode.DurabilityCostLong,
183183
Enabled = _commonConfig.DistanceMode.EnabledLong
184184
};
@@ -188,9 +188,9 @@ private void CreateModes()
188188
Id = Constants.QuantityShortModeId,
189189
Name = _translations.Get("mode--quantity-short"),
190190
Icon = Icon.Create("mode_quantity_short"),
191-
SampleShape = SampleShape.Cube,
191+
SampleShape = SampleShape.Sphere,
192192
SampleType = SampleType.Ore,
193-
SampleSize = _commonConfig.QuantityMode.SampleSizeShort,
193+
SampleRadius = _commonConfig.QuantityMode.SampleSizeShort,
194194
DurabilityCost = _commonConfig.QuantityMode.DurabilityCostShort,
195195
Enabled = _commonConfig.QuantityMode.EnabledShort
196196
};
@@ -200,9 +200,9 @@ private void CreateModes()
200200
Id = Constants.QuantityMediumModeId,
201201
Name = _translations.Get("mode--quantity-medium"),
202202
Icon = Icon.Create("mode_quantity_medium"),
203-
SampleShape = SampleShape.Cube,
203+
SampleShape = SampleShape.Sphere,
204204
SampleType = SampleType.Ore,
205-
SampleSize = _commonConfig.QuantityMode.SampleSizeMedium,
205+
SampleRadius = _commonConfig.QuantityMode.SampleSizeMedium,
206206
DurabilityCost = _commonConfig.QuantityMode.DurabilityCostMedium,
207207
Enabled = _commonConfig.QuantityMode.EnabledMedium
208208
};
@@ -212,9 +212,9 @@ private void CreateModes()
212212
Id = Constants.QuantityLongModeId,
213213
Name = _translations.Get("mode--quantity-long"),
214214
Icon = Icon.Create("mode_quantity_long"),
215-
SampleShape = SampleShape.Cube,
215+
SampleShape = SampleShape.Sphere,
216216
SampleType = SampleType.Ore,
217-
SampleSize = _commonConfig.QuantityMode.SampleSizeLong,
217+
SampleRadius = _commonConfig.QuantityMode.SampleSizeLong,
218218
DurabilityCost = _commonConfig.QuantityMode.DurabilityCostLong,
219219
Enabled = _commonConfig.QuantityMode.EnabledLong
220220
};

DurableBetterProspecting/assets/durablebetterprospecting/lang/en.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
{
2-
"Durable Better Prospecting Common Configuration": "Durable Better Prospecting Common Configuration",
3-
"Durable Better Prospecting Client Configuration": "Durable Better Prospecting Client Configuration",
42
"You don't have permission to edit the common configuration": "You don't have permission to edit the common configuration",
53
"Ascending": "Ascending",
64
"Descending": "Descending",
@@ -23,7 +21,7 @@
2321
"reading--mode-column": "Column",
2422
"reading--mode-distance": "Distance",
2523
"reading--mode-quantity": "Quantity",
26-
"reading--sample-taken": "{0} sample taken within an area of {1} block(s)",
24+
"reading--sample-taken": "{0} sample taken within a radius of {1} block(s)",
2725
"reading--sample-empty": "No {0} found",
2826
"reading--sample-not-empty": "Found the following {0}:",
2927
"reading--amount-trace": "Trace amounts",
@@ -39,6 +37,8 @@
3937
"reading--east": "E",
4038
"reading--west": "W",
4139

40+
"config--header--common": "Durable Better Prospecting Common Configuration",
41+
"config--header--client": "Durable Better Prospecting Client Configuration",
4242
"config--button--reset": "Reset to default: {0}",
4343
"config--label--enabled": "Enabled",
4444
"config--label--enabled-short": "Enabled (Short Range)",
@@ -50,13 +50,13 @@
5050
"config--label--durability-cost-short": "Durability Cost (Short Range)",
5151
"config--label--durability-cost-medium": "Durability Cost (Medium Range)",
5252
"config--label--durability-cost-long": "Durability Cost (Long Range)",
53-
"config--label--sample-size": "Sample Size",
54-
"config--label--sample-size-short": "Sample Size (Short Range)",
55-
"config--label--sample-size-medium": "Sample Size (Medium Range)",
56-
"config--label--sample-size-long": "Sample Size (Long Range)",
53+
"config--label--sample-radius": "Sample Radius",
54+
"config--label--sample-radius-short": "Sample Radius (Short Range)",
55+
"config--label--sample-radius-medium": "Sample Radius (Medium Range)",
56+
"config--label--sample-radius-long": "Sample Radius (Long Range)",
5757
"config--description--durability-cost": "The amount of durability damage to take for each sample",
58-
"config--description--sample-size-cube": "The size of the sampled area. This area is a cube, centered on the sampled block",
59-
"config--description--sample-size-cuboid": "The size of the sampled area. This area is a cuboid, centered on the sampled block and stretching from the mantle to the world height",
58+
"config--description--sample-radius-sphere": "The radius of the sampled area. This area is a sphere, centered on the sampled block",
59+
"config--description--sample-radius-cylinder": "The radius of the sampled area. This area is a cylinder, centered on the sampled block and stretching from the mantle to the world height",
6060

6161
"config--label--common--direction": "Reading Direction",
6262
"config--label--common--marker": "Automatic Marker",

DurableBetterProspecting/config.json

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@
201201
{
202202
"name": "SampleSize",
203203
"type": "Int32",
204-
"defaultValue": 32,
205-
"label": "config--label--sample-size",
206-
"description": "config--description--sample-size-cube"
204+
"defaultValue": 16,
205+
"label": "config--label--sample-radius",
206+
"description": "config--description--sample-radius-sphere"
207207
}
208208
]
209209
},
@@ -229,9 +229,9 @@
229229
{
230230
"name": "SampleSize",
231231
"type": "Int32",
232-
"defaultValue": 32,
233-
"label": "config--label--sample-size",
234-
"description": "config--description--sample-size-cuboid"
232+
"defaultValue": 16,
233+
"label": "config--label--sample-radius",
234+
"description": "config--description--sample-radius-cylinder"
235235
}
236236
]
237237
},
@@ -257,9 +257,9 @@
257257
{
258258
"name": "SampleSizeShort",
259259
"type": "Int32",
260-
"defaultValue": 16,
261-
"label": "config--label--sample-size-short",
262-
"description": "config--description--sample-size-cube"
260+
"defaultValue": 8,
261+
"label": "config--label--sample-radius-short",
262+
"description": "config--description--sample-radius-sphere"
263263
},
264264
{
265265
"name": "EnabledMedium",
@@ -278,9 +278,9 @@
278278
{
279279
"name": "SampleSizeMedium",
280280
"type": "Int32",
281-
"defaultValue": 32,
282-
"label": "config--label--sample-size-medium",
283-
"description": "config--description--sample-size-cube"
281+
"defaultValue": 16,
282+
"label": "config--label--sample-radius-medium",
283+
"description": "config--description--sample-radius-sphere"
284284
},
285285
{
286286
"name": "EnabledLong",
@@ -299,9 +299,9 @@
299299
{
300300
"name": "SampleSizeLong",
301301
"type": "Int32",
302-
"defaultValue": 64,
303-
"label": "config--label--sample-size-long",
304-
"description": "config--description--sample-size-cube"
302+
"defaultValue": 32,
303+
"label": "config--label--sample-radius-long",
304+
"description": "config--description--sample-radius-sphere"
305305
}
306306
]
307307
},
@@ -327,9 +327,9 @@
327327
{
328328
"name": "SampleSizeShort",
329329
"type": "Int32",
330-
"defaultValue": 16,
331-
"label": "config--label--sample-size-short",
332-
"description": "config--description--sample-size-cube"
330+
"defaultValue": 8,
331+
"label": "config--label--sample-radius-short",
332+
"description": "config--description--sample-radius-sphere"
333333
},
334334
{
335335
"name": "EnabledMedium",
@@ -348,9 +348,9 @@
348348
{
349349
"name": "SampleSizeMedium",
350350
"type": "Int32",
351-
"defaultValue": 32,
352-
"label": "config--label--sample-size-medium",
353-
"description": "config--description--sample-size-cube"
351+
"defaultValue": 16,
352+
"label": "config--label--sample-radius-medium",
353+
"description": "config--description--sample-radius-sphere"
354354
},
355355
{
356356
"name": "EnabledLong",
@@ -369,9 +369,9 @@
369369
{
370370
"name": "SampleSizeLong",
371371
"type": "Int32",
372-
"defaultValue": 64,
373-
"label": "config--label--sample-size-long",
374-
"description": "config--description--sample-size-cube"
372+
"defaultValue": 32,
373+
"label": "config--label--sample-radius-long",
374+
"description": "config--description--sample-radius-sphere"
375375
}
376376
]
377377
},

0 commit comments

Comments
 (0)