Ejemplo n.º 1
0
        public override bool BlockRightClicked(BlockDescriptor descriptor, BlockFace face, IWorld world,
                                               IRemoteClient user)
        {
            var window = new FurnaceWindow(user.Server.Scheduler, descriptor.Coordinates,
                                           user.Server.ItemRepository, (InventoryWindow)user.Inventory);

            var state = GetState(world, descriptor.Coordinates);

            for (var i = 0; i < state.Items.Length; i++)
            {
                window[i] = state.Items[i];
            }

            user.OpenWindow(window);
            if (!TrackedFurnaceWindows.ContainsKey(descriptor.Coordinates))
            {
                TrackedFurnaceWindows[descriptor.Coordinates] = new List <IWindow>();
            }
            TrackedFurnaceWindows[descriptor.Coordinates].Add(window);
            window.Disposed += (sender, e) => TrackedFurnaceWindows.Remove(descriptor.Coordinates);
            UpdateWindows(descriptor.Coordinates, state);

            // TODO: Set window progress appropriately

            window.WindowChange += (sender, e) => FurnaceWindowChanged(sender, e, world);
            return(false);
        }
Ejemplo n.º 2
0
        public override bool BlockRightClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
        {
            var window = new CraftingBenchWindow(user.Server.CraftingRepository, (InventoryWindow)user.Inventory);

            user.OpenWindow(window);
            return(false);
        }
Ejemplo n.º 3
0
 public override bool BlockRightClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
 {
     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;
 }
Ejemplo n.º 4
0
        public override bool BlockRightClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
        {
            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);
        }
Ejemplo n.º 5
0
        public override bool BlockRightClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
        {
            var adjacent = -Coordinates3D.One; // -1, no adjacent chest
            var self     = descriptor.Coordinates;

            for (int i = 0; i < AdjacentBlocks.Length; i++)
            {
                var test = self + AdjacentBlocks[i];
                if (world.GetBlockID(test) == ChestBlock.BlockID)
                {
                    adjacent = test;
                    var up = world.BlockRepository.GetBlockProvider(world.GetBlockID(test + Coordinates3D.Up));
                    if (up.Opaque)
                    {
                        return(false); // Obstructed
                    }
                    break;
                }
            }
            var upSelf = world.BlockRepository.GetBlockProvider(world.GetBlockID(self + Coordinates3D.Up));

            if (upSelf.Opaque)
            {
                return(false); // Obstructed
            }
            if (adjacent != -Coordinates3D.One)
            {
                // Ensure that chests are always opened in the same arrangement
                if (adjacent.X < self.X ||
                    adjacent.Z < self.Z)
                {
                    var _ = adjacent;
                    adjacent = self;
                    self     = _; // Swap
                }
            }

            var window = new ChestWindow((InventoryWindow)user.Inventory, adjacent != -Coordinates3D.One);
            // Add items
            var entity = world.GetTileEntity(self);

            if (entity != null)
            {
                foreach (var item in (NbtList)entity["Items"])
                {
                    var slot = ItemStack.FromNbt((NbtCompound)item);
                    window.ChestInventory[slot.Index] = slot;
                }
            }
            // Add adjacent items
            if (adjacent != -Coordinates3D.One)
            {
                entity = world.GetTileEntity(adjacent);
                if (entity != null)
                {
                    foreach (var item in (NbtList)entity["Items"])
                    {
                        var slot = ItemStack.FromNbt((NbtCompound)item);
                        window.ChestInventory[slot.Index + ChestWindow.DoubleChestSecondaryIndex] = slot;
                    }
                }
            }
            window.WindowChange += (sender, e) =>
            {
                var entitySelf     = new NbtList("Items", NbtTagType.Compound);
                var entityAdjacent = new NbtList("Items", NbtTagType.Compound);
                for (int i = 0; i < window.ChestInventory.Items.Length; i++)
                {
                    var item = window.ChestInventory.Items[i];
                    if (!item.Empty)
                    {
                        if (i < ChestWindow.DoubleChestSecondaryIndex)
                        {
                            item.Index = i;
                            entitySelf.Add(item.ToNbt());
                        }
                        else
                        {
                            item.Index = i - ChestWindow.DoubleChestSecondaryIndex;
                            entityAdjacent.Add(item.ToNbt());
                        }
                    }
                }
                var newEntity = world.GetTileEntity(self);
                if (newEntity == null)
                {
                    newEntity = new NbtCompound(new[] { entitySelf });
                }
                else
                {
                    newEntity["Items"] = entitySelf;
                }
                world.SetTileEntity(self, newEntity);
                if (adjacent != -Coordinates3D.One)
                {
                    newEntity = world.GetTileEntity(adjacent);
                    if (newEntity == null)
                    {
                        newEntity = new NbtCompound(new[] { entityAdjacent });
                    }
                    else
                    {
                        newEntity["Items"] = entityAdjacent;
                    }
                    world.SetTileEntity(adjacent, newEntity);
                }
            };
            user.OpenWindow(window);
            return(false);
        }
Ejemplo n.º 6
0
        public override bool BlockRightClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
        {
            var window = new FurnaceWindow(user.Server.Scheduler, descriptor.Coordinates,
                             user.Server.ItemRepository, (InventoryWindow)user.Inventory);

            var state = GetState(world, descriptor.Coordinates);
            for (int i = 0; i < state.Items.Length; i++)
                window[i] = state.Items[i];

            user.OpenWindow(window);
            if (!TrackedFurnaceWindows.ContainsKey(descriptor.Coordinates))
                TrackedFurnaceWindows[descriptor.Coordinates] = new List<IWindow>();
            TrackedFurnaceWindows[descriptor.Coordinates].Add(window);
            window.Disposed += (sender, e) => TrackedFurnaceWindows.Remove(descriptor.Coordinates);
            UpdateWindows(descriptor.Coordinates, state);

            // TODO: Set window progress appropriately

            window.WindowChange += (sender, e) => FurnaceWindowChanged(sender, e, world);
            return false;
        }
Ejemplo n.º 7
0
        public override bool BlockRightClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
        {
            var adjacent = -Coordinates3D.One; // -1, no adjacent chest
            var self = descriptor.Coordinates;
            for (int i = 0; i < AdjacentBlocks.Length; i++)
            {
                var test = self + AdjacentBlocks[i];
                if (world.GetBlockID(test) == ChestBlock.BlockID)
                {
                    adjacent = test;
                    var up = world.BlockRepository.GetBlockProvider(world.GetBlockID(test + Coordinates3D.Up));
                    if (up.Opaque && !(up is WallSignBlock)) // Wall sign blocks are an exception
                        return false; // Obstructed
                    break;
                }
            }
            var upSelf = world.BlockRepository.GetBlockProvider(world.GetBlockID(self + Coordinates3D.Up));
            if (upSelf.Opaque && !(upSelf is WallSignBlock))
                return false; // Obstructed

            if (adjacent != -Coordinates3D.One)
            {
                // Ensure that chests are always opened in the same arrangement
                if (adjacent.X < self.X ||
                    adjacent.Z < self.Z)
                {
                    var _ = adjacent;
                    adjacent = self;
                    self = _; // Swap
                }
            }

            var window = new ChestWindow((InventoryWindow)user.Inventory, adjacent != -Coordinates3D.One);
            // Add items
            var entity = world.GetTileEntity(self);
            if (entity != null)
            {
                foreach (var item in (NbtList)entity["Items"])
                {
                    var slot = ItemStack.FromNbt((NbtCompound)item);
                    window.ChestInventory[slot.Index] = slot;
                }
            }
            // Add adjacent items
            if (adjacent != -Coordinates3D.One)
            {
                entity = world.GetTileEntity(adjacent);
                if (entity != null)
                {
                    foreach (var item in (NbtList)entity["Items"])
                    {
                        var slot = ItemStack.FromNbt((NbtCompound)item);
                        window.ChestInventory[slot.Index + ChestWindow.DoubleChestSecondaryIndex] = slot;
                    }
                }
            }
            window.WindowChange += (sender, e) =>
                {
                    var entitySelf = new NbtList("Items", NbtTagType.Compound);
                    var entityAdjacent = new NbtList("Items", NbtTagType.Compound);
                    for (int i = 0; i < window.ChestInventory.Items.Length; i++)
                    {
                        var item = window.ChestInventory.Items[i];
                        if (!item.Empty)
                        {
                            if (i < ChestWindow.DoubleChestSecondaryIndex)
                            {
                                item.Index = i;
                                entitySelf.Add(item.ToNbt());
                            }
                            else
                            {
                                item.Index = i - ChestWindow.DoubleChestSecondaryIndex;
                                entityAdjacent.Add(item.ToNbt());
                            }
                        }
                    }
                    var newEntity = world.GetTileEntity(self);
                    if (newEntity == null)
                        newEntity = new NbtCompound(new[] { entitySelf });
                    else
                        newEntity["Items"] = entitySelf;
                    world.SetTileEntity(self, newEntity);
                    if (adjacent != -Coordinates3D.One)
                    {
                        newEntity = world.GetTileEntity(adjacent);
                        if (newEntity == null)
                            newEntity = new NbtCompound(new[] { entityAdjacent });
                        else
                            newEntity["Items"] = entityAdjacent;
                        world.SetTileEntity(adjacent, newEntity);
                    }
                };
            user.OpenWindow(window);
            return false;
        }
Ejemplo n.º 8
0
 public override bool BlockRightClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user)
 {
     var window = new CraftingBenchWindow(user.Server.CraftingRepository, (InventoryWindow)user.Inventory);
     user.OpenWindow(window);
     return false;
 }