Skip to content
This repository has been archived by the owner on Oct 22, 2022. It is now read-only.

Commit

Permalink
Fix #14, crash on joining world when carrying
Browse files Browse the repository at this point in the history
  • Loading branch information
copygirl committed Feb 19, 2022
1 parent 7780a0b commit 6775007
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CarryCapacity.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<AssemblyTitle>CarryCapacity</AssemblyTitle>
<Authors>copygirl</Authors>
<Version>0.6.5-rc.1</Version>
<Version>0.6.5-rc.2</Version>

<Description>Vintage Story mod which adds the capability to carry various things</Description>
<RepositoryUrl>https://github.com/copygirl/CarryCapacity</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion resources/modinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "code",
"name": "CarryCapacity",
"modid": "carrycapacity",
"version": "0.6.5-rc.1",
"version": "0.6.5-rc.2",

"description": "Adds the capability to carry various things",
"website": "https://github.com/copygirl/CarryCapacity",
Expand Down
22 changes: 15 additions & 7 deletions src/Common/CarryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public void InitServer()
.SetMessageHandler<PlaceDownMessage>(OnPlaceDownMessage)
.SetMessageHandler<SwapSlotsMessage>(OnSwapSlotsMessage);

System.ServerAPI.Event.OnEntitySpawn += OnServerEntitySpawn;
System.ServerAPI.Event.OnEntitySpawn += OnServerEntitySpawn;
System.ServerAPI.Event.PlayerNowPlaying += OnServerPlayerNowPlaying;

System.ServerAPI.Event.BeforeActiveSlotChanged +=
(player, ev) => OnBeforeActiveSlotChanged(player.Entity, ev);
Expand All @@ -54,12 +55,19 @@ public void InitServer()

public void OnServerEntitySpawn(Entity entity)
{
// We handle player "spawning" in OnServerPlayerJoin.
// If we send a LockSlotsMessage at this point, the client's player is still null.
if (entity is EntityPlayer) return;

// Set this again so walk speed modifiers and animations can be applied.
foreach (var carried in entity.GetCarried())
carried.Set(entity, carried.Slot);

// if (entity is EntityPlayer player)
// player.Controls.OnAction += OnEntityAction;
}

public void OnServerPlayerNowPlaying(IServerPlayer player)
{
foreach (var carried in player.Entity.GetCarried())
carried.Set(player.Entity, carried.Slot);
}


Expand Down Expand Up @@ -268,8 +276,8 @@ public EnumHandling OnBeforeActiveSlotChanged(EntityAgent entity, ActiveSlotChan
? EnumHandling.PreventDefault
: EnumHandling.PassThrough;
}


public void OnLockSlotsMessage(LockSlotsMessage message)
{
var player = System.ClientAPI.World.Player;
Expand All @@ -280,7 +288,7 @@ public void OnLockSlotsMessage(LockSlotsMessage message)
else LockedItemSlot.Restore(hotbar[i]);
}
}

public void SendLockSlotsMessage(IServerPlayer player)
{
var hotbar = player.InventoryManager.GetHotbarInventory();
Expand Down

0 comments on commit 6775007

Please sign in to comment.