From efc5fac7ec2a79feeb2f90296bf41be1906df8e8 Mon Sep 17 00:00:00 2001 From: 20kdc Date: Wed, 19 May 2021 18:26:01 +0100 Subject: [PATCH] Fix dropping an item on a translated grid (#4027) --- Content.Server/GameObjects/EntitySystems/HandsSystem.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Content.Server/GameObjects/EntitySystems/HandsSystem.cs b/Content.Server/GameObjects/EntitySystems/HandsSystem.cs index cca7ae53f0..9d666fb05c 100644 --- a/Content.Server/GameObjects/EntitySystems/HandsSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/HandsSystem.cs @@ -122,6 +122,8 @@ namespace Content.Server.GameObjects.EntitySystems if (handsComp.ActiveHand == null || handsComp.GetActiveHand == null) return false; + // It's important to note that the calculations are done in map coordinates (they're absolute). + // They're translated back to EntityCoordinates at the end. var entMap = ent.Transform.MapPosition; var targetPos = coords.ToMapPos(EntityManager); var dropVector = targetPos - entMap.Position; @@ -130,12 +132,14 @@ namespace Content.Server.GameObjects.EntitySystems if (dropVector != Vector2.Zero) { var targetLength = MathF.Min(dropVector.Length, SharedInteractionSystem.InteractionRange - 0.001f); // InteractionRange is reduced due to InRange not dealing with floating point error - var newCoords = coords.WithPosition(dropVector.Normalized * targetLength + entMap.Position).ToMap(EntityManager); + var newCoords = new MapCoordinates(dropVector.Normalized * targetLength + entMap.Position, entMap.MapId); var rayLength = Get().UnobstructedDistance(entMap, newCoords, ignoredEnt: ent); targetVector = dropVector.Normalized * rayLength; } - handsComp.Drop(handsComp.ActiveHand, coords.WithPosition(entMap.Position + targetVector)); + var resultMapCoordinates = new MapCoordinates(entMap.Position + targetVector, entMap.MapId); + var resultEntCoordinates = EntityCoordinates.FromMap(coords.GetParent(EntityManager), resultMapCoordinates); + handsComp.Drop(handsComp.ActiveHand, resultEntCoordinates); return true; }