Better throwing collisions (#3568)
Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -7,16 +7,13 @@ using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
|
||||
using Content.Shared.GameObjects.Verbs;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Utility;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
@@ -25,7 +22,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
[ComponentReference(typeof(StorableComponent))]
|
||||
[ComponentReference(typeof(SharedStorableComponent))]
|
||||
[ComponentReference(typeof(IItemComponent))]
|
||||
public class ItemComponent : StorableComponent, IInteractHand, IExAct, IEquipped, IUnequipped, IItemComponent, IThrown, ILand
|
||||
public class ItemComponent : StorableComponent, IInteractHand, IExAct, IEquipped, IUnequipped, IItemComponent
|
||||
{
|
||||
public override string Name => "Item";
|
||||
public override uint? NetID => ContentNetIDs.ITEM;
|
||||
@@ -155,26 +152,5 @@ namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
|
||||
Owner.TryThrow(dirVec * throwForce);
|
||||
}
|
||||
|
||||
// TODO: Predicted
|
||||
void IThrown.Thrown(ThrownEventArgs eventArgs)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out PhysicsComponent physicsComponent)) return;
|
||||
|
||||
foreach (var fixture in physicsComponent.Fixtures)
|
||||
{
|
||||
fixture.CollisionLayer |= (int) CollisionGroup.MobImpassable;
|
||||
}
|
||||
}
|
||||
|
||||
void ILand.Land(LandEventArgs eventArgs)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out PhysicsComponent physicsComponent)) return;
|
||||
|
||||
foreach (var fixture in physicsComponent.Fixtures)
|
||||
{
|
||||
fixture.CollisionLayer &= ~(int) CollisionGroup.MobImpassable;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
#nullable enable
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Collision;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Items
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class ThrownItemComponent : Component, IStartCollide, ICollideSpecial
|
||||
public class ThrownItemComponent : Component, IStartCollide, ICollideSpecial, IThrown, ILand
|
||||
{
|
||||
public override string Name => "ThrownItem";
|
||||
|
||||
public IEntity? Thrower { get; set; }
|
||||
|
||||
private Fixture? _fixture;
|
||||
|
||||
void IStartCollide.CollideWith(IPhysBody ourBody, IPhysBody otherBody, in Manifold manifold)
|
||||
{
|
||||
if (otherBody.Entity == Thrower) return;
|
||||
@@ -23,5 +28,22 @@ namespace Content.Shared.GameObjects.Components.Items
|
||||
{
|
||||
return collidedwith.Entity == Thrower;
|
||||
}
|
||||
|
||||
void IThrown.Thrown(ThrownEventArgs eventArgs)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out PhysicsComponent? physicsComponent) ||
|
||||
physicsComponent.Fixtures.Count != 1) return;
|
||||
|
||||
var shape = physicsComponent.Fixtures[0].Shape;
|
||||
_fixture = new Fixture(physicsComponent, shape) {CollisionLayer = (int) CollisionGroup.ThrownItem, Hard = false};
|
||||
physicsComponent.AddFixture(_fixture);
|
||||
}
|
||||
|
||||
void ILand.Land(LandEventArgs eventArgs)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out PhysicsComponent? physicsComponent) || _fixture == null) return;
|
||||
|
||||
physicsComponent.RemoveFixture(_fixture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user