public bool DumpInAltChest()
        {
            if (workPoint == null)
            {
                return(false);
            }
            BlockEntityGenericTypedContainer bc = entity.World.BlockAccessor.GetBlockEntity(workPoint) as BlockEntityGenericTypedContainer;

            if (bc == null)
            {
                workChest = null;
                RemoveChest();
                return(false);
            }

            if (bc.Inventory != null)
            {
                foreach (ItemSlot slot in bc.Inventory)
                {
                    workInv[0].TryPutInto(entity.World, slot, workInv[0].StackSize);
                    if (workInv[0].Empty)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public bool TakeAnyFromChest()
        {
            if (workChest == null)
            {
                return(false);
            }
            BlockEntityGenericTypedContainer bc = entity.World.BlockAccessor.GetBlockEntity(workChest) as BlockEntityGenericTypedContainer;

            if (bc == null)
            {
                workChest = null;
                RemoveChest();
                return(false);
            }

            if (bc.Inventory != null)
            {
                foreach (ItemSlot slot in bc.Inventory)
                {
                    if (!slot.Empty)
                    {
                        slot.TryPutInto(entity.World, workInv[0], slot.StackSize);
                    }
                    if (!workInv[0].Empty && workInv[0].StackSize >= workInv[0].Itemstack.Collectible.MaxStackSize)
                    {
                        return(true);
                    }
                }
            }

            return(!workInv[0].Empty);
        }
        public bool TakeFromChest()
        {
            if (!prog.CheckChest())
            {
                return(false);
            }
            BlockEntityGenericTypedContainer bc = entity.World.BlockAccessor.GetBlockEntity(prog.workChest) as BlockEntityGenericTypedContainer;

            if (bc.Inventory != null)
            {
                foreach (ItemSlot slot in bc.Inventory)
                {
                    if (slot.Itemstack == null || !CanPlant(slot.Itemstack.Collectible))
                    {
                        continue;
                    }
                    slot.TryPutInto(entity.World, entity.LeftHandItemSlot, slot.StackSize);
                    if (!entity.LeftHandItemSlot.Empty && entity.LeftHandItemSlot.StackSize >= entity.LeftHandItemSlot.Itemstack.Collectible.MaxStackSize)
                    {
                        return(true);
                    }
                }
            }

            return(!entity.LeftHandItemSlot.Empty);
        }
        public bool DumpInChest()
        {
            if (workChest == null)
            {
                return(false);
            }
            BlockEntityGenericTypedContainer bc = entity.World.BlockAccessor.GetBlockEntity(workChest) as BlockEntityGenericTypedContainer;

            //System.Diagnostics.Debug.WriteLine(workChest.X + "," + workChest.Y + "," + workChest.Z);
            if (bc == null)
            {
                workChest = null;
                RemoveChest();
                return(false);
            }

            if (bc.Inventory != null)
            {
                foreach (ItemSlot slot in bc.Inventory)
                {
                    workInv[0].TryPutInto(entity.World, slot, workInv[0].StackSize);
                    if (workInv[0].Empty)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 5
0
        public void CmdCollectibleExchange(IServerPlayer byPlayer, int id, CmdArgs args)
        {
            BlockPos pos = byPlayer?.CurrentBlockSelection?.Position;
            string   arg = args.PopWord();

            switch (arg)
            {
            case "create":
                if (pos != null)
                {
                    if (!sapi.World.Claims.TryAccess(byPlayer, pos, EnumBlockAccessFlags.Use))
                    {
                        break;
                    }
                    BlockEntityGenericTypedContainer be = (sapi.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityGenericTypedContainer);
                    if (be != null)
                    {
                        List <Exchange> exchanges = GetExchanges(be.Inventory);
                        sapi.World.BlockAccessor.RemoveBlockEntity(pos);
                        sapi.World.BlockAccessor.SpawnBlockEntity("Shop", pos);
                        BlockEntityShop beShop = (sapi.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityShop);
                        beShop.inventory = (InventoryGeneric)be.Inventory;
                        beShop.Exchanges = exchanges;
                        sapi.World.PlaySoundAt(AssetLocation.Create("sounds/effect/latch"), pos.X, pos.Y, pos.Z);
                    }
                }
                break;

            case "update":
                if (!sapi.World.Claims.TryAccess(byPlayer, pos, EnumBlockAccessFlags.Use))
                {
                    break;
                }
                BlockEntityShop shop = (sapi.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityShop);
                if (shop != null)
                {
                    shop.Exchanges = GetExchanges(shop.inventory);
                }
                sapi.World.PlaySoundAt(AssetLocation.Create("sounds/effect/latch"), pos.X, pos.Y, pos.Z);
                break;

            case "list":
                if (sapi.World.BlockAccessor.GetBlockEntity(pos) is BlockEntityShop)
                {
                    StringBuilder builder = new StringBuilder();
                    ((BlockEntityShop)sapi.World.BlockAccessor.GetBlockEntity(pos)).GetBlockInfo(byPlayer, builder);
                    byPlayer.SendMessage(GlobalConstants.GeneralChatGroup, builder.ToString(), EnumChatType.OwnMessage);
                }
                break;

            case "trade":
                ExchangeEvent(byPlayer, byPlayer.CurrentBlockSelection);
                break;

            default:
                byPlayer.SendMessage(GlobalConstants.GeneralChatGroup, syntaxMsg, EnumChatType.OwnMessage);
                break;
            }
        }