Skip to content

Commit

Permalink
+ Minor fixes to vs code settings
Browse files Browse the repository at this point in the history
+ Patch ModSystemOreMap instead of ItemProspectingPick
+ Bump version
  • Loading branch information
Wooza committed Nov 23, 2024
1 parent 37a684e commit 8512e81
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 34 deletions.
34 changes: 20 additions & 14 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
{
"version": "0.2.0",
"configurations": [{
"name": "Launch Client (.NET)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "Build (Debug)",
"program": "${env:VINTAGE_STORY}/Vintagestory.exe",
"args": [
"--playStyle" , "preset-surviveandbuild",
"--openWorld" , "Strip World",
"--addModPath", "${workspaceFolder}/bin/Debug/Mods"
],
"console": "internalConsole",
"internalConsoleOptions": "openOnSessionStart"
}]
"configurations": [
{
"name": "Launch Client (.NET)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "Build (Debug)",
"program": "${env:VINTAGE_STORY}/Vintagestory.exe",
"args": [
"--playStyle",
"preset-surviveandbuild",
"--openWorld",
"Strip World",
"--addModPath",
"${workspaceFolder}/bin/Debug/Mods"
],
"console": "internalConsole",
"internalConsoleOptions": "openOnSessionStart",
"justMyCode": false,
}
]
}
25 changes: 25 additions & 0 deletions ProspectTogether.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProspectTogether", "ProspectTogether.csproj", "{27075B78-F64F-493A-93B8-E171E843AB8B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{27075B78-F64F-493A-93B8-E171E843AB8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27075B78-F64F-493A-93B8-E171E843AB8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27075B78-F64F-493A-93B8-E171E843AB8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27075B78-F64F-493A-93B8-E171E843AB8B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FDF42B19-AAF3-4F35-B030-6C821FCD3264}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion resources/modinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Wooza",
"side": "Universal",
"description": "Stores and displays prospecting data on the map and allows sharing data between players. Based on ProspectoInfo by P3t3rix.",
"version": "1.4.0-rc.2",
"version": "1.4.0",
"dependencies": {
"game": "1.19.8"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
using HarmonyLib;
using HarmonyLib;
using ProspectTogether.Shared;
using System.Collections.Generic;
using System.Reflection;
using Vintagestory.API.Common;
using Vintagestory.API.MathTools;
using Vintagestory.API.Server;
using Vintagestory.API.Util;
using Vintagestory.GameContent;

namespace ProspectTogether.Server
{
[HarmonyPatch(typeof(ItemProspectingPick), "PrintProbeResults")]
class PrintProbeResultsPatch
[HarmonyPatch(typeof(ModSystemOreMap), "DidProbe")]
class ModSystemOreMapPatch
{
static void Postfix(ItemProspectingPick __instance, IWorldAccessor world, IServerPlayer splr, ItemSlot itemslot, BlockPos pos)
static void Postfix(ModSystemOreMap __instance, PropickReading results, IServerPlayer splr)
{
if (world.Side != EnumAppSide.Server)
return;

// Some reflection to get access to some protected stuff
ProPickWorkSpace ppws = (ProPickWorkSpace)typeof(ItemProspectingPick).GetField("ppws", BindingFlags.NonPublic |
ICoreAPI api = (ICoreAPI)typeof(ModSystemOreMap).GetField("api", BindingFlags.NonPublic |
BindingFlags.Instance).GetValue(__instance);
MethodInfo GenProbeResultsMethod = typeof(ItemProspectingPick).GetMethod("GenProbeResults", BindingFlags.NonPublic |
BindingFlags.Instance);

PropickReading results = (PropickReading)GenProbeResultsMethod.Invoke(__instance, new object[] { world, pos });
if (results == null)
// Obtain proPickWorkSpace to get page codes
ProPickWorkSpace proPickWorkSpace = ObjectCacheUtil.TryGet<ProPickWorkSpace>(api, "propickworkspace");

if (proPickWorkSpace is null)
{
// We can't do much without it.
api.World.Logger.Error("propickworkspace is null");
return;
}

// Convert results to ProspectTogether format
var occurences = new List<OreOccurence>();
foreach (var reading in results.OreReadings)
{
string pageCode = ppws.pageCodes[reading.Key];
string pageCode = proPickWorkSpace.pageCodes[reading.Key];
if (reading.Value.TotalFactor > 0.025)
{
// +2 to offset for our Enum
Expand All @@ -45,11 +44,12 @@ static void Postfix(ItemProspectingPick __instance, IWorldAccessor world, IServe
}
}

var pos = results.Position;

// Send information to Player
ProspectTogetherModSystem mod = world.Api.ModLoader.GetModSystem<ProspectTogetherModSystem>();
IBlockAccessor blockAccess = world.BlockAccessor;
int chunksize = blockAccess.ChunkSize;
ProspectInfo info = new(new ChunkCoordinate(pos.X / chunksize, pos.Z / chunksize), occurences);
ProspectTogetherModSystem mod = api.ModLoader.GetModSystem<ProspectTogetherModSystem>();
int chunksize = api.World.BlockAccessor.ChunkSize;
ProspectInfo info = new(new ChunkCoordinate(pos.XInt / chunksize, pos.ZInt / chunksize), occurences);
mod.ServerStorage.UserProspected(info, splr);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Server/ServerStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ServerStorage : CommonStorage<ServerModConfig, ICoreServerAPI>

private IServerNetworkChannel ServerChannel;

// Group id to to chunk to prospecting data
// Group id to chunk to prospecting data
public Dictionary<int, Dictionary<ChunkCoordinate, ProspectInfo>> Data = new();

public ServerStorage(ICoreServerAPI api, ServerModConfig config, string fileName) : base(api, config, fileName)
Expand Down

0 comments on commit 8512e81

Please sign in to comment.