Drop items when you exit a crafting bench

Fixes #26
This commit is contained in:
Drew DeVault 2015-10-07 07:21:12 -04:00
parent c4a65da5a1
commit 42f682ac1c

View File

@ -4,6 +4,7 @@ using TrueCraft.API;
using TrueCraft.API.World;
using TrueCraft.API.Networking;
using TrueCraft.Core.Windows;
using TrueCraft.Core.Entities;
namespace TrueCraft.Core.Logic.Blocks
{
@ -35,6 +36,19 @@ namespace TrueCraft.Core.Logic.Blocks
{
var window = new CraftingBenchWindow(user.Server.CraftingRepository, (InventoryWindow)user.Inventory);
user.OpenWindow(window);
window.Disposed += (sender, e) =>
{
var entityManager = user.Server.GetEntityManagerForWorld(world);
for (int i = 0; i < window.CraftingGrid.StartIndex + window.CraftingGrid.Length; i++)
{
var item = window[i];
if (!item.Empty)
{
var entity = new ItemEntity(descriptor.Coordinates + Coordinates3D.Up, item);
entityManager.SpawnEntity(entity);
}
}
};
return false;
}