1.22 compatibility
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DoorKeybind", "DoorKeybind\DoorKeybind.csproj", "{CB2100BC-F653-402A-9FBA-EA463C2BD4FC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CakeBuild", "ZZCakeBuild\CakeBuild.csproj", "{BC68EDF6-C294-4819-B7F4-9EA99B73E69D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{BC68EDF6-C294-4819-B7F4-9EA99B73E69D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BC68EDF6-C294-4819-B7F4-9EA99B73E69D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BC68EDF6-C294-4819-B7F4-9EA99B73E69D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BC68EDF6-C294-4819-B7F4-9EA99B73E69D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{CB2100BC-F653-402A-9FBA-EA463C2BD4FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CB2100BC-F653-402A-9FBA-EA463C2BD4FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CB2100BC-F653-402A-9FBA-EA463C2BD4FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CB2100BC-F653-402A-9FBA-EA463C2BD4FC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -1,4 +1,4 @@
|
||||
<Solution>
|
||||
<Project Path="InteractDoorsKeybind/DoorKeybind.csproj" />
|
||||
<Project Path="DoorKeybind/DoorKeybind.csproj" />
|
||||
<Project Path="ZZCakeBuild/CakeBuild.csproj" />
|
||||
</Solution>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<OutputPath>bin\$(Configuration)\Mods\mod</OutputPath>
|
||||
<Nullable>enable</Nullable>
|
||||
<VINTAGE_STORY>$(VINTAGE_STORY_21)</VINTAGE_STORY>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using DoorKeybind.Utils;
|
||||
using Vintagestory.API.Client;
|
||||
using Vintagestory.API.Common;
|
||||
using Vintagestory.API.MathTools;
|
||||
@@ -50,7 +51,7 @@ public class DoorKeybindModSystem : ModSystem
|
||||
var closestDistance = max_door_range + 1;
|
||||
|
||||
var range = (int)Math.Ceiling(max_door_range);
|
||||
var centerPos = player.Pos.AsBlockPos;
|
||||
var centerPos = player.GetPos().AsBlockPos;
|
||||
|
||||
var minPos = new BlockPos(-range, -range, -range).Add(centerPos);
|
||||
var maxPos = new BlockPos(range, range, range).Add(centerPos);
|
||||
@@ -75,8 +76,8 @@ public class DoorKeybindModSystem : ModSystem
|
||||
var selectionBoxes = currentBlock.GetSelectionBoxes(capi.World.BlockAccessor, new(x, y, z));
|
||||
var blockCenter = new Vec3d(x + 0.5, y + 0.5, z + 0.5);
|
||||
var distance = selectionBoxes.Length == 0
|
||||
? player.Pos.XYZ.DistanceTo(blockCenter)
|
||||
: selectionBoxes.Min(cuboid => player.Pos.XYZ.DistanceTo(cuboid.Center + new Vec3d(x, y, z)));
|
||||
? player.GetPos().XYZ.DistanceTo(blockCenter)
|
||||
: selectionBoxes.Min(cuboid => player.GetPos().XYZ.DistanceTo(cuboid.Center + new Vec3d(x, y, z)));
|
||||
|
||||
if (distance <= max_door_range && distance <= closestDistance)
|
||||
{
|
||||
@@ -105,7 +106,7 @@ public class DoorKeybindModSystem : ModSystem
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
var distance = player.Pos.XYZ.DistanceTo(new Vec3d(blockPos.X + 0.5, blockPos.Y + 0.5, blockPos.Z + 0.5));
|
||||
var distance = player.GetPos().XYZ.DistanceTo(new Vec3d(blockPos.X + 0.5, blockPos.Y + 0.5, blockPos.Z + 0.5));
|
||||
if (distance > max_door_range)
|
||||
return;
|
||||
|
||||
|
||||
55
DoorKeybind/Utils/CompatibilityUtil.cs
Normal file
55
DoorKeybind/Utils/CompatibilityUtil.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using Vintagestory.API.Common.Entities;
|
||||
|
||||
namespace DoorKeybind.Utils;
|
||||
|
||||
/// <summary>
|
||||
/// When the mod is built for 1.21, and then you run it with 1.22, this happens when referring to Entity.Pos,
|
||||
/// which was changed from a field to a property (and that being the reason this happens):
|
||||
///
|
||||
/// System.MissingFieldException: Field not found: 'Vintagestory.API.Common.Entities.Entity.Pos'.
|
||||
/// at MonoMod.Core.Interop.CoreCLR.V60.InvokeCompileMethod(IntPtr functionPtr, IntPtr thisPtr, IntPtr corJitInfo, CORINFO_METHOD_INFO* methodInfo, UInt32 flags, Byte** nativeEntry, UInt32* nativeSizeOfCode)
|
||||
/// at MonoMod.Core.Platforms.Runtimes.Core60Runtime.JitHookDelegateHolder.CompileMethodHook(IntPtr jit, IntPtr corJitInfo, CORINFO_METHOD_INFO* methodInfo, UInt32 flags, Byte** nativeEntry, UInt32* nativeSizeOfCode)
|
||||
/// at ChestPreview.PreviewTargetProvider.CanAccessContainer(BlockEntity blockEntity) in E:\Code\VintageStory\ChestPreview\ChestPreview\ChestPreview\PreviewTargetProvider.cs:line 237
|
||||
///
|
||||
/// the PreviewTargetProvider.cs: around line 237 looks like this:
|
||||
///
|
||||
/// private bool CanAccessContainer(BlockEntity blockEntity)
|
||||
/// {
|
||||
/// if (blockEntity is not IBlockEntityContainer container || container.Inventory is not InventoryBase inventory)
|
||||
/// return false;
|
||||
///
|
||||
/// IPlayer? player = api.World.Player;
|
||||
/// EntityPlayer? playerEntity = player?.Entity;
|
||||
/// if (player == null || playerEntity == null)
|
||||
/// return false;
|
||||
///
|
||||
/// return inventory.CanPlayerAccess(player, playerEntity.Pos);
|
||||
/// }
|
||||
///
|
||||
/// it happens because of the last line where we refer to "playerEntity.Pos" - this field doesn't exist now, because it's a property.
|
||||
///
|
||||
/// This class uses reflection to refer to either the property, or the field, whichever actually exists.
|
||||
/// </summary>
|
||||
internal static class CompatibilityUtil
|
||||
{
|
||||
#if !VERSION22
|
||||
private static Func<Entity, EntityPos>? _getPos;
|
||||
|
||||
private static Func<Entity, EntityPos> GetPosFunc => _getPos ??= BuildGetPos();
|
||||
|
||||
private static Func<Entity, EntityPos> BuildGetPos()
|
||||
{
|
||||
var prop = typeof(Entity).GetProperty("Pos");
|
||||
if (prop != null)
|
||||
return (Func<Entity, EntityPos>)Delegate.CreateDelegate(typeof(Func<Entity, EntityPos>), prop.GetGetMethod()!);
|
||||
|
||||
var field = typeof(Entity).GetField("Pos")!;
|
||||
return entity => (EntityPos)field.GetValue(entity)!;
|
||||
}
|
||||
|
||||
public static EntityPos GetPos(this Entity entity) => GetPosFunc(entity);
|
||||
#else
|
||||
public static EntityPos GetPos(this Entity entity) => entity.Pos;
|
||||
#endif
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
"OrekiWoof"
|
||||
],
|
||||
"description": "Lets you open and close doors with a keybind, so you don't have to turn around to click them.",
|
||||
"version": "1.0.0-rc.1",
|
||||
"version": "1.0.1",
|
||||
"dependencies": {
|
||||
"game": "1.21.0"
|
||||
},
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
|
||||
<VINTAGE_STORY>$(VINTAGE_STORY_21)</VINTAGE_STORY>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user